mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
feat(impersonation): migrate to betterauth admin plugin for admin status, add impersonation
This commit is contained in:
3
packages/db/migrations/0142_solid_black_bolt.sql
Normal file
3
packages/db/migrations/0142_solid_black_bolt.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE "session" ADD COLUMN "impersonated_by" text;--> statement-breakpoint
|
||||
ALTER TABLE "user" ADD COLUMN "role" text;--> statement-breakpoint
|
||||
ALTER TABLE "session" ADD CONSTRAINT "session_impersonated_by_user_id_fk" FOREIGN KEY ("impersonated_by") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
|
||||
10288
packages/db/migrations/meta/0142_snapshot.json
Normal file
10288
packages/db/migrations/meta/0142_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -988,6 +988,13 @@
|
||||
"when": 1768421319400,
|
||||
"tag": "0141_daffy_marten_broadcloak",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 142,
|
||||
"version": "7",
|
||||
"when": 1768518361916,
|
||||
"tag": "0142_solid_black_bolt",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ export const user = pgTable('user', {
|
||||
updatedAt: timestamp('updated_at').notNull(),
|
||||
stripeCustomerId: text('stripe_customer_id'),
|
||||
isSuperUser: boolean('is_super_user').notNull().default(false),
|
||||
role: text('role'), // Used by Better Auth admin plugin for impersonation
|
||||
})
|
||||
|
||||
export const session = pgTable(
|
||||
@@ -57,6 +58,7 @@ export const session = pgTable(
|
||||
activeOrganizationId: text('active_organization_id').references(() => organization.id, {
|
||||
onDelete: 'set null',
|
||||
}),
|
||||
impersonatedBy: text('impersonated_by').references(() => user.id, { onDelete: 'cascade' }), // Admin user ID when impersonating
|
||||
},
|
||||
(table) => ({
|
||||
userIdIdx: index('session_user_id_idx').on(table.userId),
|
||||
|
||||
Reference in New Issue
Block a user