diff --git a/drizzle/0000_ambitious_jocasta.sql b/drizzle/0000_soft_wraith.sql similarity index 65% rename from drizzle/0000_ambitious_jocasta.sql rename to drizzle/0000_soft_wraith.sql index e532564..aa756eb 100644 --- a/drizzle/0000_ambitious_jocasta.sql +++ b/drizzle/0000_soft_wraith.sql @@ -74,4 +74,15 @@ CREATE TABLE "note" ( --> statement-breakpoint ALTER TABLE "auth"."account" ADD CONSTRAINT "account_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "auth"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "auth"."session" ADD CONSTRAINT "session_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "auth"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint -ALTER TABLE "note" ADD CONSTRAINT "note_ownerId_user_id_fk" FOREIGN KEY ("ownerId") REFERENCES "auth"."user"("id") ON DELETE no action ON UPDATE no action; \ No newline at end of file +ALTER TABLE "note" ADD CONSTRAINT "note_ownerId_user_id_fk" FOREIGN KEY ("ownerId") REFERENCES "auth"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +CREATE INDEX "idx_auth_account_userid" ON "auth"."account" USING btree ("user_id");--> statement-breakpoint +CREATE INDEX "idx_auth_account_refreshtokenexpiresat" ON "auth"."account" USING btree ("refresh_token_expires_at");--> statement-breakpoint +CREATE INDEX "idx_auth_account_providerid" ON "auth"."account" USING btree ("provider_id");--> statement-breakpoint +CREATE INDEX "idx_auth_ratelimit_key" ON "auth"."rate_limit" USING btree ("key");--> statement-breakpoint +CREATE INDEX "idx_auth_session_ip_address" ON "auth"."session" USING btree ("ip_address");--> statement-breakpoint +CREATE INDEX "idx_auth_session_userid" ON "auth"."session" USING btree ("user_id");--> statement-breakpoint +CREATE INDEX "idx_auth_verification_identifier" ON "auth"."verification" USING btree ("identifier");--> statement-breakpoint +CREATE INDEX "idx_auth_verification_expires_at" ON "auth"."verification" USING btree ("expires_at");--> statement-breakpoint +CREATE INDEX "idx_note_ownerid" ON "note" USING btree ("ownerId");--> statement-breakpoint +CREATE INDEX "idx_note_createdat" ON "note" USING btree ("createdAt");--> statement-breakpoint +CREATE INDEX "idx_note_deletedat" ON "note" USING btree ("deletedAt"); \ No newline at end of file diff --git a/drizzle/meta/0000_snapshot.json b/drizzle/meta/0000_snapshot.json index 5e1d8bc..3ab4076 100644 --- a/drizzle/meta/0000_snapshot.json +++ b/drizzle/meta/0000_snapshot.json @@ -1,5 +1,5 @@ { - "id": "38b37b1d-93e4-4f9a-8d7e-a77b0632afb4", + "id": "b58e6198-1838-4903-a137-a91a6605653c", "prevId": "00000000-0000-0000-0000-000000000000", "version": "7", "dialect": "postgresql", @@ -87,7 +87,53 @@ "notNull": true } }, - "indexes": {}, + "indexes": { + "idx_auth_account_userid": { + "name": "idx_auth_account_userid", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_auth_account_refreshtokenexpiresat": { + "name": "idx_auth_account_refreshtokenexpiresat", + "columns": [ + { + "expression": "refresh_token_expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_auth_account_providerid": { + "name": "idx_auth_account_providerid", + "columns": [ + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, "foreignKeys": { "account_user_id_user_id_fk": { "name": "account_user_id_user_id_fk", @@ -176,7 +222,23 @@ "notNull": false } }, - "indexes": {}, + "indexes": { + "idx_auth_ratelimit_key": { + "name": "idx_auth_ratelimit_key", + "columns": [ + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, "foreignKeys": {}, "compositePrimaryKeys": {}, "uniqueConstraints": {}, @@ -237,7 +299,38 @@ "notNull": true } }, - "indexes": {}, + "indexes": { + "idx_auth_session_ip_address": { + "name": "idx_auth_session_ip_address", + "columns": [ + { + "expression": "ip_address", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_auth_session_userid": { + "name": "idx_auth_session_userid", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, "foreignKeys": { "session_user_id_user_id_fk": { "name": "session_user_id_user_id_fk", @@ -372,7 +465,38 @@ "notNull": false } }, - "indexes": {}, + "indexes": { + "idx_auth_verification_identifier": { + "name": "idx_auth_verification_identifier", + "columns": [ + { + "expression": "identifier", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_auth_verification_expires_at": { + "name": "idx_auth_verification_expires_at", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, "foreignKeys": {}, "compositePrimaryKeys": {}, "uniqueConstraints": {}, @@ -428,7 +552,53 @@ "notNull": true } }, - "indexes": {}, + "indexes": { + "idx_note_ownerid": { + "name": "idx_note_ownerid", + "columns": [ + { + "expression": "ownerId", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_note_createdat": { + "name": "idx_note_createdat", + "columns": [ + { + "expression": "createdAt", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_note_deletedat": { + "name": "idx_note_deletedat", + "columns": [ + { + "expression": "deletedAt", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, "foreignKeys": { "note_ownerId_user_id_fk": { "name": "note_ownerId_user_id_fk", diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 9fdfc2b..3ab2cdc 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -5,8 +5,8 @@ { "idx": 0, "version": "7", - "when": 1737386379330, - "tag": "0000_ambitious_jocasta", + "when": 1737390835611, + "tag": "0000_soft_wraith", "breakpoints": true } ] diff --git a/src/db/schema/auth.ts b/src/db/schema/auth.ts index bac513a..d14e28b 100644 --- a/src/db/schema/auth.ts +++ b/src/db/schema/auth.ts @@ -1,59 +1,78 @@ -import { text, integer, timestamp, boolean, pgSchema } from "drizzle-orm/pg-core"; +import { + text, + integer, + timestamp, + boolean, + pgSchema, + index, +} from "drizzle-orm/pg-core"; -export const authSchema = pgSchema('auth'); +export const authSchema = pgSchema("auth"); -export const user = authSchema.table("user", { - id: text("id").primaryKey(), - name: text('name').notNull(), - email: text('email').notNull().unique(), - emailVerified: boolean('email_verified').notNull(), - image: text('image'), - createdAt: timestamp('created_at').notNull(), - updatedAt: timestamp('updated_at').notNull() -}); +export const user = authSchema.table( + "user", + { + id: text("id").primaryKey(), + name: text("name").notNull(), + email: text("email").notNull().unique(), + emailVerified: boolean("email_verified").notNull(), + image: text("image"), + createdAt: timestamp("created_at").notNull(), + updatedAt: timestamp("updated_at").notNull(), + }, +); export const session = authSchema.table("session", { id: text("id").primaryKey(), - expiresAt: timestamp('expires_at').notNull(), - token: text('token').notNull().unique(), - createdAt: timestamp('created_at').notNull(), - updatedAt: timestamp('updated_at').notNull(), - ipAddress: text('ip_address'), - userAgent: text('user_agent'), - userId: text('user_id').notNull().references(() => user.id) -}); + expiresAt: timestamp("expires_at").notNull(), + token: text("token").notNull().unique(), + createdAt: timestamp("created_at").notNull(), + updatedAt: timestamp("updated_at").notNull(), + ipAddress: text("ip_address"), + userAgent: text("user_agent"), + userId: text("user_id") + .notNull() + .references(() => user.id), +}, +(table) => [index("idx_auth_session_ip_address").on(table.ipAddress), index("idx_auth_session_userid").on(table.userId)] +); export const account = authSchema.table("account", { id: text("id").primaryKey(), - accountId: text('account_id').notNull(), - providerId: text('provider_id').notNull(), - userId: text('user_id').notNull().references(() => user.id), - accessToken: text('access_token'), - refreshToken: text('refresh_token'), - idToken: text('id_token'), - accessTokenExpiresAt: timestamp('access_token_expires_at'), - refreshTokenExpiresAt: timestamp('refresh_token_expires_at'), - scope: text('scope'), - password: text('password'), - createdAt: timestamp('created_at').notNull(), - updatedAt: timestamp('updated_at').notNull() -}); + accountId: text("account_id").notNull(), + providerId: text("provider_id").notNull(), + userId: text("user_id") + .notNull() + .references(() => user.id), + accessToken: text("access_token"), + refreshToken: text("refresh_token"), + idToken: text("id_token"), + accessTokenExpiresAt: timestamp("access_token_expires_at"), + refreshTokenExpiresAt: timestamp("refresh_token_expires_at"), + scope: text("scope"), + password: text("password"), + createdAt: timestamp("created_at").notNull(), + updatedAt: timestamp("updated_at").notNull(), +}, +(table) => [index("idx_auth_account_userid").on(table.userId), index("idx_auth_account_refreshtokenexpiresat").on(table.refreshTokenExpiresAt), index("idx_auth_account_providerid").on(table.providerId)]); export const verification = authSchema.table("verification", { id: text("id").primaryKey(), - identifier: text('identifier').notNull(), - value: text('value').notNull(), - expiresAt: timestamp('expires_at').notNull(), - createdAt: timestamp('created_at'), - updatedAt: timestamp('updated_at') -}); + identifier: text("identifier").notNull(), + value: text("value").notNull(), + expiresAt: timestamp("expires_at").notNull(), + createdAt: timestamp("created_at"), + updatedAt: timestamp("updated_at"), +}, +(table) => [index("idx_auth_verification_identifier").on(table.identifier), index("idx_auth_verification_expires_at").on(table.expiresAt)]); export const rateLimit = authSchema.table("rate_limit", { id: text("id").primaryKey(), - key: text('key'), - count: integer('count'), - lastRequest: integer('last_request') -}); + key: text("key"), + count: integer("count"), + lastRequest: integer("last_request"), +}, +(table) => [index("idx_auth_ratelimit_key").on(table.key)]); export const jwks = authSchema.table("jwks", { id: text("id").primaryKey(), diff --git a/src/db/schema/note.ts b/src/db/schema/note.ts index fd19f7a..fb803ac 100644 --- a/src/db/schema/note.ts +++ b/src/db/schema/note.ts @@ -1,4 +1,4 @@ -import { pgTable, text, timestamp } from "drizzle-orm/pg-core"; +import { index, pgTable, text, timestamp } from "drizzle-orm/pg-core"; import { createId } from '@paralleldrive/cuid2' import { user } from "./auth"; @@ -10,4 +10,7 @@ export const note = pgTable("note", { updatedAt: timestamp(), deletedAt: timestamp(), ownerId: text().notNull().references(() => user.id) -}) \ No newline at end of file +}, + +(table) => [index("idx_note_ownerid").on(table.ownerId), index("idx_note_createdat").on(table.createdAt), index("idx_note_deletedat").on(table.deletedAt)] +) \ No newline at end of file