forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration to restrict users without workspaces (twentyhq#5369)
- update set null ON DELETE constraint to RESTRICT - update missing updates
- Loading branch information
Showing
3 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...er/src/database/typeorm/core/migrations/1715593226719-updateInconsistentUserConstraint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class UpdateInconsistentUserConstraint1715593226719 | ||
implements MigrationInterface | ||
{ | ||
name = 'UpdateInconsistentUserConstraint1715593226719'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`ALTER TABLE "core"."user" DROP CONSTRAINT "FK_2ec910029395fa7655621c88908"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "status" TYPE text`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "interval" TYPE text`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "core"."workspace" ALTER COLUMN "subscriptionStatus" TYPE text`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "core"."user" ADD CONSTRAINT "FK_2ec910029395fa7655621c88908" FOREIGN KEY ("defaultWorkspaceId") REFERENCES "core"."workspace"("id") ON DELETE RESTRICT ON UPDATE NO ACTION`, | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`ALTER TABLE "core"."user" DROP CONSTRAINT "FK_2ec910029395fa7655621c88908"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "core"."workspace" ALTER COLUMN "subscriptionStatus" TYPE character varying`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "interval" TYPE character varying`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "status" TYPE character varying`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "core"."user" ADD CONSTRAINT "FK_2ec910029395fa7655621c88908" FOREIGN KEY ("defaultWorkspaceId") REFERENCES "core"."workspace"("id") ON DELETE SET NULL ON UPDATE NO ACTION`, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters