Merge pull request #96 from groombook/feat/impersonation-indexes-gh95

feat(db): add indexes on impersonation tables
This commit was merged in pull request #96.
This commit is contained in:
groombook-ceo[bot]
2026-03-21 23:44:18 +00:00
committed by GitHub
4 changed files with 1520 additions and 25 deletions
@@ -0,0 +1,6 @@
-- Add indexes on impersonation tables to prevent full table scans
-- Ref: GitHub #95
CREATE INDEX "impersonation_sessions_staff_id_status_idx" ON "impersonation_sessions" USING btree ("staff_id","status");--> statement-breakpoint
CREATE INDEX "impersonation_sessions_client_id_idx" ON "impersonation_sessions" USING btree ("client_id");--> statement-breakpoint
CREATE INDEX "impersonation_audit_logs_session_id_idx" ON "impersonation_audit_logs" USING btree ("session_id");
File diff suppressed because it is too large Load Diff
@@ -78,6 +78,13 @@
"when": 1742500800000, "when": 1742500800000,
"tag": "0010_impersonation_sessions", "tag": "0010_impersonation_sessions",
"breakpoints": true "breakpoints": true
},
{
"idx": 11,
"version": "7",
"when": 1742587200000,
"tag": "0011_impersonation_indexes",
"breakpoints": true
} }
] ]
} }
+19 -5
View File
@@ -1,5 +1,6 @@
import { import {
boolean, boolean,
index,
integer, integer,
jsonb, jsonb,
numeric, numeric,
@@ -232,7 +233,9 @@ export const impersonationSessionStatusEnum = pgEnum(
["active", "ended", "expired"] ["active", "ended", "expired"]
); );
export const impersonationSessions = pgTable("impersonation_sessions", { export const impersonationSessions = pgTable(
"impersonation_sessions",
{
id: uuid("id").primaryKey().defaultRandom(), id: uuid("id").primaryKey().defaultRandom(),
staffId: uuid("staff_id") staffId: uuid("staff_id")
.notNull() .notNull()
@@ -241,14 +244,23 @@ export const impersonationSessions = pgTable("impersonation_sessions", {
.notNull() .notNull()
.references(() => clients.id, { onDelete: "restrict" }), .references(() => clients.id, { onDelete: "restrict" }),
reason: text("reason"), reason: text("reason"),
status: impersonationSessionStatusEnum("status").notNull().default("active"), status: impersonationSessionStatusEnum("status")
.notNull()
.default("active"),
startedAt: timestamp("started_at").notNull().defaultNow(), startedAt: timestamp("started_at").notNull().defaultNow(),
endedAt: timestamp("ended_at"), endedAt: timestamp("ended_at"),
expiresAt: timestamp("expires_at").notNull(), expiresAt: timestamp("expires_at").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(), createdAt: timestamp("created_at").notNull().defaultNow(),
}); },
(t) => [
index("impersonation_sessions_staff_id_status_idx").on(t.staffId, t.status),
index("impersonation_sessions_client_id_idx").on(t.clientId),
]
);
export const impersonationAuditLogs = pgTable("impersonation_audit_logs", { export const impersonationAuditLogs = pgTable(
"impersonation_audit_logs",
{
id: uuid("id").primaryKey().defaultRandom(), id: uuid("id").primaryKey().defaultRandom(),
sessionId: uuid("session_id") sessionId: uuid("session_id")
.notNull() .notNull()
@@ -257,7 +269,9 @@ export const impersonationAuditLogs = pgTable("impersonation_audit_logs", {
pageVisited: text("page_visited"), pageVisited: text("page_visited"),
metadata: jsonb("metadata").$type<Record<string, unknown>>(), metadata: jsonb("metadata").$type<Record<string, unknown>>(),
createdAt: timestamp("created_at").notNull().defaultNow(), createdAt: timestamp("created_at").notNull().defaultNow(),
}); },
(t) => [index("impersonation_audit_logs_session_id_idx").on(t.sessionId)]
);
export const businessSettings = pgTable("business_settings", { export const businessSettings = pgTable("business_settings", {
id: uuid("id").primaryKey().defaultRandom(), id: uuid("id").primaryKey().defaultRandom(),