diff --git a/app/lib/schema.ts b/app/lib/schema.ts index 3a1cdcd..d3e4f0e 100644 --- a/app/lib/schema.ts +++ b/app/lib/schema.ts @@ -35,6 +35,7 @@ export const accounts = sqliteTable( compoundKey: primaryKey({ columns: [account.provider, account.providerAccountId], }), + userIdIdx: index("account_user_id_idx").on(account.userId), }) ) @@ -48,6 +49,7 @@ export const emails = sqliteTable("email", { expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(), }, (table) => ({ expiresAtIdx: index("email_expires_at_idx").on(table.expiresAt), + userIdIdx: index("email_user_id_idx").on(table.userId), })) export const messages = sqliteTable("message", { @@ -69,6 +71,7 @@ export const messages = sqliteTable("message", { .$defaultFn(() => new Date()), }, (table) => ({ emailIdIdx: index("message_email_id_idx").on(table.emailId), + emailIdReceivedAtTypeIdx: index("message_email_id_received_at_type_idx").on(table.emailId, table.receivedAt, table.type), })) export const webhooks = sqliteTable('webhook', { @@ -84,7 +87,9 @@ export const webhooks = sqliteTable('webhook', { updatedAt: integer('updated_at', { mode: 'timestamp_ms' }) .notNull() .$defaultFn(() => new Date()), -}) +}, (table) => ({ + userIdIdx: index('webhook_user_id_idx').on(table.userId), +})) export const roles = sqliteTable("role", { id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()), @@ -100,6 +105,7 @@ export const userRoles = sqliteTable("user_role", { createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(() => new Date()), }, (table) => ({ pk: primaryKey({ columns: [table.userId, table.roleId] }), + userIdIdx: index("user_role_user_id_idx").on(table.userId), })); export const apiKeys = sqliteTable('api_keys', { @@ -111,7 +117,8 @@ export const apiKeys = sqliteTable('api_keys', { expiresAt: integer('expires_at', { mode: 'timestamp' }), enabled: integer('enabled', { mode: 'boolean' }).notNull().default(true), }, (table) => ({ - nameUserIdUnique: uniqueIndex('name_user_id_unique').on(table.name, table.userId) + nameUserIdUnique: uniqueIndex('name_user_id_unique').on(table.name, table.userId), + userIdIdx: index('api_keys_user_id_idx').on(table.userId), })); export const emailShares = sqliteTable('email_share', { diff --git a/drizzle/0017_superb_calypso.sql b/drizzle/0017_superb_calypso.sql new file mode 100644 index 0000000..d247b50 --- /dev/null +++ b/drizzle/0017_superb_calypso.sql @@ -0,0 +1,6 @@ +CREATE INDEX `account_user_id_idx` ON `account` (`userId`);--> statement-breakpoint +CREATE INDEX `api_keys_user_id_idx` ON `api_keys` (`user_id`);--> statement-breakpoint +CREATE INDEX `email_user_id_idx` ON `email` (`userId`);--> statement-breakpoint +CREATE INDEX `message_email_id_received_at_type_idx` ON `message` (`emailId`,`received_at`,`type`);--> statement-breakpoint +CREATE INDEX `user_role_user_id_idx` ON `user_role` (`user_id`);--> statement-breakpoint +CREATE INDEX `webhook_user_id_idx` ON `webhook` (`user_id`); \ No newline at end of file diff --git a/drizzle/meta/0017_snapshot.json b/drizzle/meta/0017_snapshot.json new file mode 100644 index 0000000..f099d69 --- /dev/null +++ b/drizzle/meta/0017_snapshot.json @@ -0,0 +1,854 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "0ae57607-60f1-48fa-a37c-4afc523f5863", + "prevId": "10fa71e9-1e9e-43ef-bcfc-bfec5e46af8e", + "tables": { + "account": { + "name": "account", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "providerAccountId": { + "name": "providerAccountId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "token_type": { + "name": "token_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "session_state": { + "name": "session_state", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "account_user_id_idx": { + "name": "account_user_id_idx", + "columns": [ + "userId" + ], + "isUnique": false + } + }, + "foreignKeys": { + "account_userId_user_id_fk": { + "name": "account_userId_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "account_provider_providerAccountId_pk": { + "columns": [ + "provider", + "providerAccountId" + ], + "name": "account_provider_providerAccountId_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "api_keys": { + "name": "api_keys", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + } + }, + "indexes": { + "api_keys_key_unique": { + "name": "api_keys_key_unique", + "columns": [ + "key" + ], + "isUnique": true + }, + "name_user_id_unique": { + "name": "name_user_id_unique", + "columns": [ + "name", + "user_id" + ], + "isUnique": true + }, + "api_keys_user_id_idx": { + "name": "api_keys_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "api_keys_user_id_user_id_fk": { + "name": "api_keys_user_id_user_id_fk", + "tableFrom": "api_keys", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "email_share": { + "name": "email_share", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "email_id": { + "name": "email_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "email_share_token_unique": { + "name": "email_share_token_unique", + "columns": [ + "token" + ], + "isUnique": true + }, + "email_share_email_id_idx": { + "name": "email_share_email_id_idx", + "columns": [ + "email_id" + ], + "isUnique": false + }, + "email_share_token_idx": { + "name": "email_share_token_idx", + "columns": [ + "token" + ], + "isUnique": false + } + }, + "foreignKeys": { + "email_share_email_id_email_id_fk": { + "name": "email_share_email_id_email_id_fk", + "tableFrom": "email_share", + "tableTo": "email", + "columnsFrom": [ + "email_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "email": { + "name": "email", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "email_address_unique": { + "name": "email_address_unique", + "columns": [ + "address" + ], + "isUnique": true + }, + "email_expires_at_idx": { + "name": "email_expires_at_idx", + "columns": [ + "expires_at" + ], + "isUnique": false + }, + "email_user_id_idx": { + "name": "email_user_id_idx", + "columns": [ + "userId" + ], + "isUnique": false + } + }, + "foreignKeys": { + "email_userId_user_id_fk": { + "name": "email_userId_user_id_fk", + "tableFrom": "email", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "message_share": { + "name": "message_share", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "message_share_token_unique": { + "name": "message_share_token_unique", + "columns": [ + "token" + ], + "isUnique": true + }, + "message_share_message_id_idx": { + "name": "message_share_message_id_idx", + "columns": [ + "message_id" + ], + "isUnique": false + }, + "message_share_token_idx": { + "name": "message_share_token_idx", + "columns": [ + "token" + ], + "isUnique": false + } + }, + "foreignKeys": { + "message_share_message_id_message_id_fk": { + "name": "message_share_message_id_message_id_fk", + "tableFrom": "message_share", + "tableTo": "message", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "message": { + "name": "message", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "emailId": { + "name": "emailId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "from_address": { + "name": "from_address", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "to_address": { + "name": "to_address", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "html": { + "name": "html", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "received_at": { + "name": "received_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sent_at": { + "name": "sent_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "message_email_id_idx": { + "name": "message_email_id_idx", + "columns": [ + "emailId" + ], + "isUnique": false + }, + "message_email_id_received_at_type_idx": { + "name": "message_email_id_received_at_type_idx", + "columns": [ + "emailId", + "received_at", + "type" + ], + "isUnique": false + } + }, + "foreignKeys": { + "message_emailId_email_id_fk": { + "name": "message_emailId_email_id_fk", + "tableFrom": "message", + "tableTo": "email", + "columnsFrom": [ + "emailId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "role": { + "name": "role", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user_role": { + "name": "user_role", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role_id": { + "name": "role_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "user_role_user_id_idx": { + "name": "user_role_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "user_role_user_id_user_id_fk": { + "name": "user_role_user_id_user_id_fk", + "tableFrom": "user_role", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_role_role_id_role_id_fk": { + "name": "user_role_role_id_role_id_fk", + "tableFrom": "user_role", + "tableTo": "role", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "user_role_user_id_role_id_pk": { + "columns": [ + "user_id", + "role_id" + ], + "name": "user_role_user_id_role_id_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "emailVerified": { + "name": "emailVerified", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "user_email_unique": { + "name": "user_email_unique", + "columns": [ + "email" + ], + "isUnique": true + }, + "user_username_unique": { + "name": "user_username_unique", + "columns": [ + "username" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "webhook": { + "name": "webhook", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "webhook_user_id_idx": { + "name": "webhook_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "webhook_user_id_user_id_fk": { + "name": "webhook_user_id_user_id_fk", + "tableFrom": "webhook", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index faee049..57f11c2 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -120,6 +120,13 @@ "when": 1760460028481, "tag": "0016_hesitant_thing", "breakpoints": true + }, + { + "idx": 17, + "version": "6", + "when": 1767113936600, + "tag": "0017_superb_calypso", + "breakpoints": true } ] } \ No newline at end of file