feat: add RUN_SEED support and nullable tenantId migration
- New migration: make users.tenantId nullable for super_admin - Dockerfile: RUN_SEED=true env var triggers seed after migrations - Seed uses npx tsx (available in node_modules)
This commit is contained in:
@@ -34,4 +34,4 @@ COPY --from=builder /app/packages/db/src ./packages/db/src
|
||||
ENV NODE_ENV=production
|
||||
EXPOSE 3001
|
||||
ENTRYPOINT ["dumb-init", "--"]
|
||||
CMD ["sh", "-c", "cd packages/db && npx prisma migrate deploy && cd /app && node dist/main"]
|
||||
CMD ["sh", "-c", "cd packages/db && npx prisma migrate deploy && if [ \"$RUN_SEED\" = \"true\" ]; then echo 'Seeding database...' && npx tsx prisma/seed.ts; fi && cd /app && node dist/main"]
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
-- AlterTable: make tenantId nullable for super_admin users
|
||||
ALTER TABLE "users" ALTER COLUMN "tenantId" DROP NOT NULL;
|
||||
|
||||
-- Fix FK to allow NULL (super_admin has no tenant)
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_tenantId_fkey";
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_tenantId_fkey"
|
||||
FOREIGN KEY ("tenantId") REFERENCES "tenants"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- Drop unique index that requires tenantId (email must be unique globally for super_admin)
|
||||
DROP INDEX IF EXISTS "users_tenantId_email_key";
|
||||
CREATE UNIQUE INDEX "users_tenantId_email_key" ON "users"("tenantId", "email") WHERE "tenantId" IS NOT NULL;
|
||||
CREATE UNIQUE INDEX "users_email_key" ON "users"("email") WHERE "tenantId" IS NULL;
|
||||
Reference in New Issue
Block a user