···93939494 if (hasCreatedAt.rows.length === 0) {
9595 console.log("📝 Adding created_at column to invitation table...");
9696+ // Add column as nullable first
9697 await db.execute(sql`
9798 ALTER TABLE "invitation"
9898- ADD COLUMN "created_at" timestamp DEFAULT NOW() NOT NULL;
9999+ ADD COLUMN "created_at" timestamp;
100100+ `);
101101+102102+ // Set default value for existing rows (use expires_at - 1 month as a reasonable default)
103103+ await db.execute(sql`
104104+ UPDATE "invitation"
105105+ SET "created_at" = COALESCE("expires_at" - INTERVAL '1 month', NOW())
106106+ WHERE "created_at" IS NULL;
107107+ `);
108108+109109+ // Now make it NOT NULL with default
110110+ await db.execute(sql`
111111+ ALTER TABLE "invitation"
112112+ ALTER COLUMN "created_at" SET DEFAULT NOW(),
113113+ ALTER COLUMN "created_at" SET NOT NULL;
99114 `);
100115 console.log(
101116 "✅ Successfully added created_at column to invitation table",