added db indexing
This commit is contained in:
parent
027847f996
commit
cbb30d05a6
5 changed files with 256 additions and 53 deletions
|
|
@ -74,4 +74,15 @@ CREATE TABLE "note" (
|
||||||
--> statement-breakpoint
|
--> 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"."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 "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;
|
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");
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"id": "38b37b1d-93e4-4f9a-8d7e-a77b0632afb4",
|
"id": "b58e6198-1838-4903-a137-a91a6605653c",
|
||||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||||
"version": "7",
|
"version": "7",
|
||||||
"dialect": "postgresql",
|
"dialect": "postgresql",
|
||||||
|
|
@ -87,7 +87,53 @@
|
||||||
"notNull": true
|
"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": {
|
"foreignKeys": {
|
||||||
"account_user_id_user_id_fk": {
|
"account_user_id_user_id_fk": {
|
||||||
"name": "account_user_id_user_id_fk",
|
"name": "account_user_id_user_id_fk",
|
||||||
|
|
@ -176,7 +222,23 @@
|
||||||
"notNull": false
|
"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": {},
|
"foreignKeys": {},
|
||||||
"compositePrimaryKeys": {},
|
"compositePrimaryKeys": {},
|
||||||
"uniqueConstraints": {},
|
"uniqueConstraints": {},
|
||||||
|
|
@ -237,7 +299,38 @@
|
||||||
"notNull": true
|
"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": {
|
"foreignKeys": {
|
||||||
"session_user_id_user_id_fk": {
|
"session_user_id_user_id_fk": {
|
||||||
"name": "session_user_id_user_id_fk",
|
"name": "session_user_id_user_id_fk",
|
||||||
|
|
@ -372,7 +465,38 @@
|
||||||
"notNull": false
|
"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": {},
|
"foreignKeys": {},
|
||||||
"compositePrimaryKeys": {},
|
"compositePrimaryKeys": {},
|
||||||
"uniqueConstraints": {},
|
"uniqueConstraints": {},
|
||||||
|
|
@ -428,7 +552,53 @@
|
||||||
"notNull": true
|
"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": {
|
"foreignKeys": {
|
||||||
"note_ownerId_user_id_fk": {
|
"note_ownerId_user_id_fk": {
|
||||||
"name": "note_ownerId_user_id_fk",
|
"name": "note_ownerId_user_id_fk",
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
{
|
{
|
||||||
"idx": 0,
|
"idx": 0,
|
||||||
"version": "7",
|
"version": "7",
|
||||||
"when": 1737386379330,
|
"when": 1737390835611,
|
||||||
"tag": "0000_ambitious_jocasta",
|
"tag": "0000_soft_wraith",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -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", {
|
export const user = authSchema.table(
|
||||||
id: text("id").primaryKey(),
|
"user",
|
||||||
name: text('name').notNull(),
|
{
|
||||||
email: text('email').notNull().unique(),
|
id: text("id").primaryKey(),
|
||||||
emailVerified: boolean('email_verified').notNull(),
|
name: text("name").notNull(),
|
||||||
image: text('image'),
|
email: text("email").notNull().unique(),
|
||||||
createdAt: timestamp('created_at').notNull(),
|
emailVerified: boolean("email_verified").notNull(),
|
||||||
updatedAt: timestamp('updated_at').notNull()
|
image: text("image"),
|
||||||
});
|
createdAt: timestamp("created_at").notNull(),
|
||||||
|
updatedAt: timestamp("updated_at").notNull(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export const session = authSchema.table("session", {
|
export const session = authSchema.table("session", {
|
||||||
id: text("id").primaryKey(),
|
id: text("id").primaryKey(),
|
||||||
expiresAt: timestamp('expires_at').notNull(),
|
expiresAt: timestamp("expires_at").notNull(),
|
||||||
token: text('token').notNull().unique(),
|
token: text("token").notNull().unique(),
|
||||||
createdAt: timestamp('created_at').notNull(),
|
createdAt: timestamp("created_at").notNull(),
|
||||||
updatedAt: timestamp('updated_at').notNull(),
|
updatedAt: timestamp("updated_at").notNull(),
|
||||||
ipAddress: text('ip_address'),
|
ipAddress: text("ip_address"),
|
||||||
userAgent: text('user_agent'),
|
userAgent: text("user_agent"),
|
||||||
userId: text('user_id').notNull().references(() => user.id)
|
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", {
|
export const account = authSchema.table("account", {
|
||||||
id: text("id").primaryKey(),
|
id: text("id").primaryKey(),
|
||||||
accountId: text('account_id').notNull(),
|
accountId: text("account_id").notNull(),
|
||||||
providerId: text('provider_id').notNull(),
|
providerId: text("provider_id").notNull(),
|
||||||
userId: text('user_id').notNull().references(() => user.id),
|
userId: text("user_id")
|
||||||
accessToken: text('access_token'),
|
.notNull()
|
||||||
refreshToken: text('refresh_token'),
|
.references(() => user.id),
|
||||||
idToken: text('id_token'),
|
accessToken: text("access_token"),
|
||||||
accessTokenExpiresAt: timestamp('access_token_expires_at'),
|
refreshToken: text("refresh_token"),
|
||||||
refreshTokenExpiresAt: timestamp('refresh_token_expires_at'),
|
idToken: text("id_token"),
|
||||||
scope: text('scope'),
|
accessTokenExpiresAt: timestamp("access_token_expires_at"),
|
||||||
password: text('password'),
|
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
|
||||||
createdAt: timestamp('created_at').notNull(),
|
scope: text("scope"),
|
||||||
updatedAt: timestamp('updated_at').notNull()
|
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", {
|
export const verification = authSchema.table("verification", {
|
||||||
id: text("id").primaryKey(),
|
id: text("id").primaryKey(),
|
||||||
identifier: text('identifier').notNull(),
|
identifier: text("identifier").notNull(),
|
||||||
value: text('value').notNull(),
|
value: text("value").notNull(),
|
||||||
expiresAt: timestamp('expires_at').notNull(),
|
expiresAt: timestamp("expires_at").notNull(),
|
||||||
createdAt: timestamp('created_at'),
|
createdAt: timestamp("created_at"),
|
||||||
updatedAt: timestamp('updated_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", {
|
export const rateLimit = authSchema.table("rate_limit", {
|
||||||
id: text("id").primaryKey(),
|
id: text("id").primaryKey(),
|
||||||
key: text('key'),
|
key: text("key"),
|
||||||
count: integer('count'),
|
count: integer("count"),
|
||||||
lastRequest: integer('last_request')
|
lastRequest: integer("last_request"),
|
||||||
});
|
},
|
||||||
|
(table) => [index("idx_auth_ratelimit_key").on(table.key)]);
|
||||||
|
|
||||||
export const jwks = authSchema.table("jwks", {
|
export const jwks = authSchema.table("jwks", {
|
||||||
id: text("id").primaryKey(),
|
id: text("id").primaryKey(),
|
||||||
|
|
|
||||||
|
|
@ -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 { createId } from '@paralleldrive/cuid2'
|
||||||
import { user } from "./auth";
|
import { user } from "./auth";
|
||||||
|
|
||||||
|
|
@ -10,4 +10,7 @@ export const note = pgTable("note", {
|
||||||
updatedAt: timestamp(),
|
updatedAt: timestamp(),
|
||||||
deletedAt: timestamp(),
|
deletedAt: timestamp(),
|
||||||
ownerId: text().notNull().references(() => user.id)
|
ownerId: text().notNull().references(() => user.id)
|
||||||
})
|
},
|
||||||
|
|
||||||
|
(table) => [index("idx_note_ownerid").on(table.ownerId), index("idx_note_createdat").on(table.createdAt), index("idx_note_deletedat").on(table.deletedAt)]
|
||||||
|
)
|
||||||
Loading…
Add table
Reference in a new issue