Remove deprecated SQL migration file and add new migration for default member organization flag. Update journal and snapshot metadata accordingly.

This commit is contained in:
Mauricio Siu
2025-11-02 21:57:43 -06:00
parent 71b550f7e6
commit 5949005458
5 changed files with 6702 additions and 30 deletions

View File

@@ -1,6 +0,0 @@
ALTER TABLE "application" ADD COLUMN "stopGracePeriodSwarm" bigint;--> statement-breakpoint
ALTER TABLE "mariadb" ADD COLUMN "stopGracePeriodSwarm" bigint;--> statement-breakpoint
ALTER TABLE "mongo" ADD COLUMN "stopGracePeriodSwarm" bigint;--> statement-breakpoint
ALTER TABLE "mysql" ADD COLUMN "stopGracePeriodSwarm" bigint;--> statement-breakpoint
ALTER TABLE "postgres" ADD COLUMN "stopGracePeriodSwarm" bigint;--> statement-breakpoint
ALTER TABLE "redis" ADD COLUMN "stopGracePeriodSwarm" bigint;

View File

@@ -0,0 +1 @@
ALTER TABLE "member" ADD COLUMN "is_default" boolean DEFAULT false NOT NULL;

File diff suppressed because it is too large Load Diff

View File

@@ -800,13 +800,6 @@
"tag": "0113_complete_rafael_vega",
"breakpoints": true
},
{
"idx": 114,
"version": "7",
"when": 1759643172958,
"tag": "0114_dry_black_tom",
"breakpoints": true
},
{
"idx": 115,
"version": "7",
@@ -841,6 +834,13 @@
"when": 1761920677980,
"tag": "0114_sudden_sheva_callister",
"breakpoints": true
},
{
"idx": 120,
"version": "7",
"when": 1762142154747,
"tag": "0120_plain_eternity",
"breakpoints": true
}
]
}

View File

@@ -175,28 +175,19 @@ const { handler, api } = betterAuth({
session: {
create: {
before: async (session) => {
// First try to find the default organization for this user
let member = await db.query.member.findFirst({
where: and(
eq(schema.member.userId, session.userId),
eq(schema.member.isDefault, true),
),
// Find the default organization for this user
// Priority: 1) isDefault=true, 2) most recently created
const member = await db.query.member.findFirst({
where: eq(schema.member.userId, session.userId),
orderBy: [
desc(schema.member.isDefault),
desc(schema.member.createdAt),
],
with: {
organization: true,
},
});
// If no default is set, fallback to the most recently created organization
if (!member) {
member = await db.query.member.findFirst({
where: eq(schema.member.userId, session.userId),
orderBy: desc(schema.member.createdAt),
with: {
organization: true,
},
});
}
return {
data: {
...session,