Skip to content

Commit c2eb0df

Browse files
committed
added deployment config
1 parent 2df57ea commit c2eb0df

File tree

9 files changed

+141
-67
lines changed

9 files changed

+141
-67
lines changed

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22.1.0

docker-compose.yaml

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "3.8"
1+
version: '3.8'
22
services:
33
postgres:
44
image: postgres:latest
@@ -7,37 +7,15 @@ services:
77
POSTGRES_PASSWORD: postgres
88
POSTGRES_DB: postgres
99
ports:
10-
- "5432:5432"
10+
- '5432:5432'
1111
volumes:
1212
- postgres_data:/var/lib/postgresql/data
13-
1413
redis:
1514
image: redis:latest
1615
ports:
17-
- "6379:6379"
16+
- '6379:6379'
1817
volumes:
1918
- redis_data:/data
20-
21-
minio:
22-
image: docker.io/bitnami/minio
23-
ports:
24-
- '9000:9000'
25-
- '9001:9001'
26-
networks:
27-
- minionetwork
28-
volumes:
29-
- 'minio_data:/data'
30-
environment:
31-
- MINIO_ROOT_USER=user
32-
- MINIO_ROOT_PASSWORD=password
33-
- MINIO_DEFAULT_BUCKETS=dev
34-
3519
volumes:
3620
postgres_data:
3721
redis_data:
38-
minio_data:
39-
driver: local
40-
41-
networks:
42-
minionetwork:
43-
driver: bridge

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"test": "npm run test:integration && npm run test:unit",
1414
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
1515
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
16+
"initialize": "pnpm install && docker-compose up --no-recreate -d && pnpm db:migrate",
1617
"lint": "prettier --check . && eslint .",
1718
"format": "prettier --write .",
1819
"test:integration": "playwright test",

render.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
services:
2+
- type: web
3+
name: web
4+
runtime: node
5+
region: oregon # optional (defaults to oregon)
6+
plan: starter # optional (defaults to starter instance type)
7+
branch: main # optional (defaults to master)
8+
buildCommand: npm install --force && npm run build
9+
startCommand: npm run db:migrate && node build/index.js
10+
healthCheckPath: /
11+
envVars:
12+
- key: DATABASE_URL
13+
fromDatabase:
14+
name: db
15+
property: connectionString
16+
- key: PUBLIC_ORIGIN
17+
fromDatabase:
18+
name: web
19+
property: host
20+
- type: redis
21+
name: private redis
22+
ipAllowList: [] # Only allow internal connections
23+
24+
databases:
25+
- name: db
26+
databaseName: postgres
27+
ipAllowList: []
Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
CREATE TABLE IF NOT EXISTS "sessions" (
1+
CREATE EXTENSION IF NOT EXISTS "citext";
2+
3+
CREATE TABLE IF NOT EXISTS "email_verifications" (
24
"id" text PRIMARY KEY NOT NULL,
5+
"hashed_token" text NOT NULL,
36
"user_id" text NOT NULL,
4-
"expires_at" timestamp with time zone NOT NULL
7+
"requested_email" text NOT NULL,
8+
"expires_at" timestamp with time zone NOT NULL,
9+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
10+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
11+
CONSTRAINT "email_verifications_user_id_unique" UNIQUE("user_id")
512
);
613

7-
CREATE TABLE IF NOT EXISTS "tokens" (
14+
CREATE TABLE IF NOT EXISTS "login_requests" (
815
"id" text PRIMARY KEY NOT NULL,
9-
"token" text NOT NULL,
10-
"user_id" text NOT NULL,
16+
"hashed_token" text NOT NULL,
1117
"email" text NOT NULL,
1218
"expires_at" timestamp with time zone NOT NULL,
1319
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
1420
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
15-
CONSTRAINT "tokens_token_unique" UNIQUE("token")
21+
CONSTRAINT "login_requests_email_unique" UNIQUE("email")
22+
);
23+
24+
CREATE TABLE IF NOT EXISTS "sessions" (
25+
"id" text PRIMARY KEY NOT NULL,
26+
"user_id" text NOT NULL,
27+
"expires_at" timestamp with time zone NOT NULL
1628
);
1729

1830
CREATE TABLE IF NOT EXISTS "users" (
@@ -26,13 +38,13 @@ CREATE TABLE IF NOT EXISTS "users" (
2638
);
2739

2840
DO $$ BEGIN
29-
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;
41+
ALTER TABLE "email_verifications" ADD CONSTRAINT "email_verifications_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;
3042
EXCEPTION
3143
WHEN duplicate_object THEN null;
3244
END $$;
3345

3446
DO $$ BEGIN
35-
ALTER TABLE "tokens" ADD CONSTRAINT "tokens_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;
47+
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;
3648
EXCEPTION
3749
WHEN duplicate_object THEN null;
3850
END $$;

src/lib/server/api/infrastructure/database/migrations/meta/0000_snapshot.json

Lines changed: 85 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"id": "8bb6c6c1-e68f-4b94-a390-b51666d00dbb",
2+
"id": "2e0c1e11-ed33-45bf-8084-c3200d8f65a8",
33
"prevId": "00000000-0000-0000-0000-000000000000",
44
"version": "6",
55
"dialect": "postgresql",
66
"tables": {
7-
"public.sessions": {
8-
"name": "sessions",
7+
"public.email_verifications": {
8+
"name": "email_verifications",
99
"schema": "",
1010
"columns": {
1111
"id": {
@@ -14,24 +14,50 @@
1414
"primaryKey": true,
1515
"notNull": true
1616
},
17+
"hashed_token": {
18+
"name": "hashed_token",
19+
"type": "text",
20+
"primaryKey": false,
21+
"notNull": true
22+
},
1723
"user_id": {
1824
"name": "user_id",
1925
"type": "text",
2026
"primaryKey": false,
2127
"notNull": true
2228
},
29+
"requested_email": {
30+
"name": "requested_email",
31+
"type": "text",
32+
"primaryKey": false,
33+
"notNull": true
34+
},
2335
"expires_at": {
2436
"name": "expires_at",
2537
"type": "timestamp with time zone",
2638
"primaryKey": false,
2739
"notNull": true
40+
},
41+
"created_at": {
42+
"name": "created_at",
43+
"type": "timestamp with time zone",
44+
"primaryKey": false,
45+
"notNull": true,
46+
"default": "now()"
47+
},
48+
"updated_at": {
49+
"name": "updated_at",
50+
"type": "timestamp with time zone",
51+
"primaryKey": false,
52+
"notNull": true,
53+
"default": "now()"
2854
}
2955
},
3056
"indexes": {},
3157
"foreignKeys": {
32-
"sessions_user_id_users_id_fk": {
33-
"name": "sessions_user_id_users_id_fk",
34-
"tableFrom": "sessions",
58+
"email_verifications_user_id_users_id_fk": {
59+
"name": "email_verifications_user_id_users_id_fk",
60+
"tableFrom": "email_verifications",
3561
"tableTo": "users",
3662
"columnsFrom": [
3763
"user_id"
@@ -44,10 +70,18 @@
4470
}
4571
},
4672
"compositePrimaryKeys": {},
47-
"uniqueConstraints": {}
73+
"uniqueConstraints": {
74+
"email_verifications_user_id_unique": {
75+
"name": "email_verifications_user_id_unique",
76+
"nullsNotDistinct": false,
77+
"columns": [
78+
"user_id"
79+
]
80+
}
81+
}
4882
},
49-
"public.tokens": {
50-
"name": "tokens",
83+
"public.login_requests": {
84+
"name": "login_requests",
5185
"schema": "",
5286
"columns": {
5387
"id": {
@@ -56,14 +90,8 @@
5690
"primaryKey": true,
5791
"notNull": true
5892
},
59-
"token": {
60-
"name": "token",
61-
"type": "text",
62-
"primaryKey": false,
63-
"notNull": true
64-
},
65-
"user_id": {
66-
"name": "user_id",
93+
"hashed_token": {
94+
"name": "hashed_token",
6795
"type": "text",
6896
"primaryKey": false,
6997
"notNull": true
@@ -96,10 +124,46 @@
96124
}
97125
},
98126
"indexes": {},
127+
"foreignKeys": {},
128+
"compositePrimaryKeys": {},
129+
"uniqueConstraints": {
130+
"login_requests_email_unique": {
131+
"name": "login_requests_email_unique",
132+
"nullsNotDistinct": false,
133+
"columns": [
134+
"email"
135+
]
136+
}
137+
}
138+
},
139+
"public.sessions": {
140+
"name": "sessions",
141+
"schema": "",
142+
"columns": {
143+
"id": {
144+
"name": "id",
145+
"type": "text",
146+
"primaryKey": true,
147+
"notNull": true
148+
},
149+
"user_id": {
150+
"name": "user_id",
151+
"type": "text",
152+
"primaryKey": false,
153+
"notNull": true
154+
},
155+
"expires_at": {
156+
"name": "expires_at",
157+
"type": "timestamp with time zone",
158+
"primaryKey": false,
159+
"notNull": true
160+
}
161+
},
162+
"indexes": {},
99163
"foreignKeys": {
100-
"tokens_user_id_users_id_fk": {
101-
"name": "tokens_user_id_users_id_fk",
102-
"tableFrom": "tokens",
164+
"sessions_user_id_users_id_fk": {
165+
"name": "sessions_user_id_users_id_fk",
166+
"tableFrom": "sessions",
103167
"tableTo": "users",
104168
"columnsFrom": [
105169
"user_id"
@@ -112,15 +176,7 @@
112176
}
113177
},
114178
"compositePrimaryKeys": {},
115-
"uniqueConstraints": {
116-
"tokens_token_unique": {
117-
"name": "tokens_token_unique",
118-
"nullsNotDistinct": false,
119-
"columns": [
120-
"token"
121-
]
122-
}
123-
}
179+
"uniqueConstraints": {}
124180
},
125181
"public.users": {
126182
"name": "users",

src/lib/server/api/infrastructure/database/migrations/meta/_journal.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
{
66
"idx": 0,
77
"version": "6",
8-
"when": 1716599372513,
9-
"tag": "0000_first_crystal",
8+
"when": 1719436322147,
9+
"tag": "0000_sudden_human_fly",
1010
"breakpoints": false
1111
}
1212
]

src/lib/server/api/repositories/email-verifications.repository.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ export class EmailVerificationsRepository implements Repository {
2020
}
2121

2222
// finds a valid record by token and userId
23-
async findValidRecord(userId: string, hashedToken: string) {
23+
async findValidRecord(userId: string) {
2424
return this.db.select().from(emailVerificationsTable).where(
2525
and(
2626
eq(emailVerificationsTable.userId, userId),
27-
eq(emailVerificationsTable.hashedToken, hashedToken),
2827
lte(emailVerificationsTable.expiresAt, new Date())
2928
)).then(takeFirst)
3029
}

src/lib/server/api/services/email-verifications.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class EmailVerificationsService {
6363
private async findAndBurnEmailVerificationToken(userId: string, token: string) {
6464
return this.db.transaction(async (trx) => {
6565
// find a valid record
66-
const emailVerificationRecord = await this.emailVerificationsRepository.trxHost(trx).findValidRecord(userId, token);
66+
const emailVerificationRecord = await this.emailVerificationsRepository.trxHost(trx).findValidRecord(userId);
6767
if (!emailVerificationRecord) return null;
6868

6969
// check if the token is valid

0 commit comments

Comments
 (0)