From c30ec12ea8e85101350d1391107c9a8f34f5f7b2 Mon Sep 17 00:00:00 2001 From: Mariusz Wachowski Date: Thu, 17 Oct 2024 22:29:31 +0200 Subject: [PATCH 1/4] updated drizzle-kit and drizzle-orm packages --- package.json | 4 ++-- pnpm-lock.yaml | 34 ++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index ae49caf..9c8dcd9 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,8 @@ "bullmq": "^5.13.0", "chalk": "^5.3.0", "dotenv-cli": "^7.4.2", - "drizzle-kit": "^0.24.2", - "drizzle-orm": "^0.33.0", + "drizzle-kit": "^0.26.2", + "drizzle-orm": "^0.35.1", "eslint": "^9.10.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-svelte": "^2.43.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 11ebf94..11a749a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -65,7 +65,7 @@ importers: version: 0.2.2(hono@4.6.1)(zod@3.23.8) '@lucia-auth/adapter-drizzle': specifier: ^1.1.0 - version: 1.1.0(drizzle-orm@0.33.0(pg@8.12.0)(postgres@3.4.4)(react@18.3.1))(lucia@3.2.0) + version: 1.1.0(drizzle-orm@0.35.1(pg@8.12.0)(postgres@3.4.4)(react@18.3.1))(lucia@3.2.0) '@paralleldrive/cuid2': specifier: ^2.2.2 version: 2.2.2 @@ -112,11 +112,11 @@ importers: specifier: ^7.4.2 version: 7.4.2 drizzle-kit: - specifier: ^0.24.2 - version: 0.24.2 + specifier: ^0.26.2 + version: 0.26.2 drizzle-orm: - specifier: ^0.33.0 - version: 0.33.0(pg@8.12.0)(postgres@3.4.4)(react@18.3.1) + specifier: ^0.35.1 + version: 0.35.1(pg@8.12.0)(postgres@3.4.4)(react@18.3.1) eslint: specifier: ^9.10.0 version: 9.10.0(jiti@1.21.6) @@ -393,9 +393,11 @@ packages: '@esbuild-kit/core-utils@3.3.2': resolution: {integrity: sha512-sPRAnw9CdSsRmEtnsl2WXWdyquogVpB3yZ3dgwJfe8zrOzTsV7cJvmwrKVa+0ma5BoiGJ+BoqkMvawbayKUsqQ==} + deprecated: 'Merged into tsx: https://tsx.is' '@esbuild-kit/esm-loader@2.6.5': resolution: {integrity: sha512-FxEMIkJKnodyA1OaCUoEvbYRkoZlLZ4d/eXFu9Fh8CbBBgP5EmZxrfTRyN0qpXZ4vOvqnE5YdRdcrmUUXuU+dA==} + deprecated: 'Merged into tsx: https://tsx.is' '@esbuild/aix-ppc64@0.19.12': resolution: {integrity: sha512-bmoCYyWdEL3wDQIVbcyzRyeKLgk2WtWLTWz1ZIAZF/EGbNOwSA6ew3PftJ1PqMiOOGu0OyFMzG53L0zqIpPeNA==} @@ -2131,17 +2133,17 @@ packages: resolution: {integrity: sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==} engines: {node: '>=12'} - drizzle-kit@0.24.2: - resolution: {integrity: sha512-nXOaTSFiuIaTMhS8WJC2d4EBeIcN9OSt2A2cyFbQYBAZbi7lRsVGJNqDpEwPqYfJz38yxbY/UtbvBBahBfnExQ==} + drizzle-kit@0.26.2: + resolution: {integrity: sha512-cMq8omEKywjIy5KcqUo6LvEFxkl8/zYHsgYjFVXjmPWWtuW4blcz+YW9+oIhoaALgs2ebRjzXwsJgN9i6P49Dw==} hasBin: true - drizzle-orm@0.33.0: - resolution: {integrity: sha512-SHy72R2Rdkz0LEq0PSG/IdvnT3nGiWuRk+2tXZQ90GVq/XQhpCzu/EFT3V2rox+w8MlkBQxifF8pCStNYnERfA==} + drizzle-orm@0.35.1: + resolution: {integrity: sha512-HQxDdYuXlZFuvDPztlUIzrX8TqWa/Ej6uN6L0hkbuGL4slexOUMc3u4nXVU15RQ5QYbk+uLQnR6v1+OIrdCTXQ==} peerDependencies: '@aws-sdk/client-rds-data': '>=3' '@cloudflare/workers-types': '>=3' '@electric-sql/pglite': '>=0.1.1' - '@libsql/client': '*' + '@libsql/client': '>=0.10.0' '@neondatabase/serverless': '>=0.1' '@op-engineering/op-sqlite': '>=2' '@opentelemetry/api': ^1.4.1 @@ -2228,7 +2230,7 @@ packages: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} ee-first@1.1.1: - resolution: {integrity: sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=} + resolution: {integrity: sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==} electron-to-chromium@1.5.21: resolution: {integrity: sha512-+rBAerCpQvFSPyAO677i5gJuWGO2WFsoujENdcMzsrpP7Ebcc3pmpERgU8CV4fFF10a5haP4ivnFQ/AmLICBVg==} @@ -2757,7 +2759,7 @@ packages: resolution: {integrity: sha512-+Wri9p0QHMy+545hKww7YAu5NyzF8iomPL/RQazugQ9+Ez4Ic3mERMd8ZTX5rfK944j+560ZJi8iAwgak1Ac7A==} media-typer@0.3.0: - resolution: {integrity: sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=} + resolution: {integrity: sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==} engines: {node: '>= 0.6'} memfs-browser@3.5.10302: @@ -4650,9 +4652,9 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.0 - '@lucia-auth/adapter-drizzle@1.1.0(drizzle-orm@0.33.0(pg@8.12.0)(postgres@3.4.4)(react@18.3.1))(lucia@3.2.0)': + '@lucia-auth/adapter-drizzle@1.1.0(drizzle-orm@0.35.1(pg@8.12.0)(postgres@3.4.4)(react@18.3.1))(lucia@3.2.0)': dependencies: - drizzle-orm: 0.33.0(pg@8.12.0)(postgres@3.4.4)(react@18.3.1) + drizzle-orm: 0.35.1(pg@8.12.0)(postgres@3.4.4)(react@18.3.1) lucia: 3.2.0 '@melt-ui/svelte@0.76.2(svelte@5.0.0-next.164)': @@ -5825,7 +5827,7 @@ snapshots: dotenv@16.4.5: {} - drizzle-kit@0.24.2: + drizzle-kit@0.26.2: dependencies: '@drizzle-team/brocli': 0.10.1 '@esbuild-kit/esm-loader': 2.6.5 @@ -5834,7 +5836,7 @@ snapshots: transitivePeerDependencies: - supports-color - drizzle-orm@0.33.0(pg@8.12.0)(postgres@3.4.4)(react@18.3.1): + drizzle-orm@0.35.1(pg@8.12.0)(postgres@3.4.4)(react@18.3.1): optionalDependencies: pg: 8.12.0 postgres: 3.4.4 From 3eef0bab38b078cbf0b96d219f3ffcbb79067814 Mon Sep 17 00:00:00 2001 From: Mariusz Wachowski Date: Thu, 17 Oct 2024 22:31:16 +0200 Subject: [PATCH 2/4] fixed drizzle studio "infer relation" error --- .../migrations/0001_gifted_james_howlett.sql | 14 + .../migrations/meta/0001_snapshot.json | 315 ++++++++++++++++++ .../postgres/migrations/meta/_journal.json | 7 + .../postgres/tables/sessions.table.ts | 8 + 4 files changed, 344 insertions(+) create mode 100644 src/lib/server/api/databases/postgres/migrations/0001_gifted_james_howlett.sql create mode 100644 src/lib/server/api/databases/postgres/migrations/meta/0001_snapshot.json diff --git a/src/lib/server/api/databases/postgres/migrations/0001_gifted_james_howlett.sql b/src/lib/server/api/databases/postgres/migrations/0001_gifted_james_howlett.sql new file mode 100644 index 0000000..057b264 --- /dev/null +++ b/src/lib/server/api/databases/postgres/migrations/0001_gifted_james_howlett.sql @@ -0,0 +1,14 @@ +CREATE TABLE IF NOT EXISTS "files" ( + "id" text PRIMARY KEY NOT NULL, + "key" text NOT NULL, + "size" bigint NOT NULL, + "content_type" text NOT NULL, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + "updated_at" timestamp with time zone DEFAULT now() NOT NULL +); +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "users" ADD CONSTRAINT "users_avatar_files_id_fk" FOREIGN KEY ("avatar") REFERENCES "public"."files"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; diff --git a/src/lib/server/api/databases/postgres/migrations/meta/0001_snapshot.json b/src/lib/server/api/databases/postgres/migrations/meta/0001_snapshot.json new file mode 100644 index 0000000..a1c5423 --- /dev/null +++ b/src/lib/server/api/databases/postgres/migrations/meta/0001_snapshot.json @@ -0,0 +1,315 @@ +{ + "id": "00340fa1-eeb1-41d9-bbe3-972ed52f7ca1", + "prevId": "7c8066fe-53c3-4fbb-b700-34ae02d25480", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.email_verifications": { + "name": "email_verifications", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "hashed_token": { + "name": "hashed_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "requested_email": { + "name": "requested_email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "email_verifications_user_id_users_id_fk": { + "name": "email_verifications_user_id_users_id_fk", + "tableFrom": "email_verifications", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "email_verifications_user_id_unique": { + "name": "email_verifications_user_id_unique", + "nullsNotDistinct": false, + "columns": [ + "user_id" + ] + } + }, + "checkConstraints": {} + }, + "public.files": { + "name": "files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "public.login_requests": { + "name": "login_requests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "hashed_token": { + "name": "hashed_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "login_requests_email_unique": { + "name": "login_requests_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "checkConstraints": {} + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "avatar": { + "name": "avatar", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "citext", + "primaryKey": false, + "notNull": true + }, + "verified": { + "name": "verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "users_avatar_files_id_fk": { + "name": "users_avatar_files_id_fk", + "tableFrom": "users", + "tableTo": "files", + "columnsFrom": [ + "avatar" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "checkConstraints": {} + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/lib/server/api/databases/postgres/migrations/meta/_journal.json b/src/lib/server/api/databases/postgres/migrations/meta/_journal.json index cc5b97e..df4ee3b 100644 --- a/src/lib/server/api/databases/postgres/migrations/meta/_journal.json +++ b/src/lib/server/api/databases/postgres/migrations/meta/_journal.json @@ -8,6 +8,13 @@ "when": 1722983304054, "tag": "0000_clear_paper_doll", "breakpoints": true + }, + { + "idx": 1, + "version": "7", + "when": 1729196878223, + "tag": "0001_gifted_james_howlett", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/lib/server/api/databases/postgres/tables/sessions.table.ts b/src/lib/server/api/databases/postgres/tables/sessions.table.ts index dca266c..9e9bd79 100644 --- a/src/lib/server/api/databases/postgres/tables/sessions.table.ts +++ b/src/lib/server/api/databases/postgres/tables/sessions.table.ts @@ -1,3 +1,4 @@ +import { relations } from 'drizzle-orm'; import { cuid2 } from '../../../common/utils/table'; import { usersTable } from './users.table'; import { pgTable, text, timestamp } from 'drizzle-orm/pg-core'; @@ -12,3 +13,10 @@ export const sessionsTable = pgTable('sessions', { mode: 'date' }).notNull() }); + +export const sessionsRelations = relations(sessionsTable, ({ one }) => ({ + user: one(usersTable, { + fields: [sessionsTable.userId], + references: [usersTable.id], + }), + })); \ No newline at end of file From b1af2c36800626cdf4c5df8c0719c7b8a2ebfbe8 Mon Sep 17 00:00:00 2001 From: Mariusz Wachowski Date: Thu, 17 Oct 2024 22:47:49 +0200 Subject: [PATCH 3/4] added $onUpdate for updatedAt timestamp --- src/lib/server/api/common/utils/table.ts | 1 + src/routes/(app)/settings/account/+page.server.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/server/api/common/utils/table.ts b/src/lib/server/api/common/utils/table.ts index 02ed64b..361a6d0 100644 --- a/src/lib/server/api/common/utils/table.ts +++ b/src/lib/server/api/common/utils/table.ts @@ -26,4 +26,5 @@ export const timestamps = { }) .notNull() .defaultNow() + .$onUpdate(() => new Date()) }; diff --git a/src/routes/(app)/settings/account/+page.server.ts b/src/routes/(app)/settings/account/+page.server.ts index 31f55f1..a8cc726 100644 --- a/src/routes/(app)/settings/account/+page.server.ts +++ b/src/routes/(app)/settings/account/+page.server.ts @@ -25,7 +25,7 @@ export const actions = { const verifyEmailForm = await superValidate(request, zod(verifyEmailFormSchema)); console.log(verifyEmailForm) if (!verifyEmailForm.valid) return fail(StatusCodes.BAD_REQUEST, { verifyEmailForm }) - const { error } = await locals.api.iam.email.verification.$post({ json: verifyEmailForm.data }).then(locals.parseApiResponse); + const { error } = await locals.api.iam.email.verify.$post({ json: verifyEmailForm.data }).then(locals.parseApiResponse); if (error) return setError(verifyEmailForm, 'token', error); return { verifyEmailForm } } From 2d8ad8feaac193712dfb0d88dbf5390d9293a229 Mon Sep 17 00:00:00 2001 From: Mariusz Wachowski Date: Thu, 17 Oct 2024 23:15:18 +0200 Subject: [PATCH 4/4] added cascade on delete user for sessions and email-verification --- .../postgres/migrations/0002_sharp_risque.sql | 15 + .../migrations/meta/0002_snapshot.json | 315 ++++++++++++++++++ .../postgres/migrations/meta/_journal.json | 7 + .../tables/email-verifications.table.ts | 2 +- .../postgres/tables/sessions.table.ts | 2 +- 5 files changed, 339 insertions(+), 2 deletions(-) create mode 100644 src/lib/server/api/databases/postgres/migrations/0002_sharp_risque.sql create mode 100644 src/lib/server/api/databases/postgres/migrations/meta/0002_snapshot.json diff --git a/src/lib/server/api/databases/postgres/migrations/0002_sharp_risque.sql b/src/lib/server/api/databases/postgres/migrations/0002_sharp_risque.sql new file mode 100644 index 0000000..d1f8ae0 --- /dev/null +++ b/src/lib/server/api/databases/postgres/migrations/0002_sharp_risque.sql @@ -0,0 +1,15 @@ +ALTER TABLE "email_verifications" DROP CONSTRAINT "email_verifications_user_id_users_id_fk"; +--> statement-breakpoint +ALTER TABLE "sessions" DROP CONSTRAINT "sessions_user_id_users_id_fk"; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "email_verifications" ADD CONSTRAINT "email_verifications_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; diff --git a/src/lib/server/api/databases/postgres/migrations/meta/0002_snapshot.json b/src/lib/server/api/databases/postgres/migrations/meta/0002_snapshot.json new file mode 100644 index 0000000..1f4e16f --- /dev/null +++ b/src/lib/server/api/databases/postgres/migrations/meta/0002_snapshot.json @@ -0,0 +1,315 @@ +{ + "id": "5796b846-6715-463d-8a8b-15b8dad25d10", + "prevId": "00340fa1-eeb1-41d9-bbe3-972ed52f7ca1", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.email_verifications": { + "name": "email_verifications", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "hashed_token": { + "name": "hashed_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "requested_email": { + "name": "requested_email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "email_verifications_user_id_users_id_fk": { + "name": "email_verifications_user_id_users_id_fk", + "tableFrom": "email_verifications", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "email_verifications_user_id_unique": { + "name": "email_verifications_user_id_unique", + "nullsNotDistinct": false, + "columns": [ + "user_id" + ] + } + }, + "checkConstraints": {} + }, + "public.files": { + "name": "files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "public.login_requests": { + "name": "login_requests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "hashed_token": { + "name": "hashed_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "login_requests_email_unique": { + "name": "login_requests_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "checkConstraints": {} + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "avatar": { + "name": "avatar", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "citext", + "primaryKey": false, + "notNull": true + }, + "verified": { + "name": "verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "users_avatar_files_id_fk": { + "name": "users_avatar_files_id_fk", + "tableFrom": "users", + "tableTo": "files", + "columnsFrom": [ + "avatar" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "checkConstraints": {} + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/lib/server/api/databases/postgres/migrations/meta/_journal.json b/src/lib/server/api/databases/postgres/migrations/meta/_journal.json index df4ee3b..ac9cb27 100644 --- a/src/lib/server/api/databases/postgres/migrations/meta/_journal.json +++ b/src/lib/server/api/databases/postgres/migrations/meta/_journal.json @@ -15,6 +15,13 @@ "when": 1729196878223, "tag": "0001_gifted_james_howlett", "breakpoints": true + }, + { + "idx": 2, + "version": "7", + "when": 1729199803558, + "tag": "0002_sharp_risque", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/lib/server/api/databases/postgres/tables/email-verifications.table.ts b/src/lib/server/api/databases/postgres/tables/email-verifications.table.ts index 03bffb6..d007301 100644 --- a/src/lib/server/api/databases/postgres/tables/email-verifications.table.ts +++ b/src/lib/server/api/databases/postgres/tables/email-verifications.table.ts @@ -11,7 +11,7 @@ export const emailVerificationsTable = pgTable('email_verifications', { hashedToken: text('hashed_token').notNull(), userId: text('user_id') .notNull() - .references(() => usersTable.id).unique(), + .references(() => usersTable.id, { onDelete: 'cascade' }).unique(), requestedEmail: text('requested_email').notNull(), expiresAt: timestamp('expires_at', { mode: 'date', diff --git a/src/lib/server/api/databases/postgres/tables/sessions.table.ts b/src/lib/server/api/databases/postgres/tables/sessions.table.ts index 9e9bd79..24e6bde 100644 --- a/src/lib/server/api/databases/postgres/tables/sessions.table.ts +++ b/src/lib/server/api/databases/postgres/tables/sessions.table.ts @@ -7,7 +7,7 @@ export const sessionsTable = pgTable('sessions', { id: cuid2('id').primaryKey(), userId: text('user_id') .notNull() - .references(() => usersTable.id), + .references(() => usersTable.id, { onDelete: 'cascade' }), expiresAt: timestamp('expires_at', { withTimezone: true, mode: 'date'