Add workspace constraint on defaultRoleId and activationStatus (#11191)
Part of https://github.com/twentyhq/core-team-issues/issues/526 An active workspace's defaultRoleId should never be null. We can't rely on a simple postgres NOT NULL constraint as defaultRoleId will always be initially null when the workspace is first created since the roles do not exist at that time. Since a suspended workspace can be active again, we should maintain that rule during the workspace suspension. The only moment defaultRoleId can have a null value is during the onboarding. this pr enforces that
This commit is contained in:
@ -0,0 +1,17 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddWorkspaceConstraint1742998832316 implements MigrationInterface {
|
||||
name = 'AddWorkspaceConstraint1742998832316';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."workspace" ADD CONSTRAINT "onboarded_workspace_requires_default_role" CHECK ("activationStatus" IN ('PENDING_CREATION', 'ONGOING_CREATION') OR "defaultRoleId" IS NOT NULL)`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."workspace" DROP CONSTRAINT "onboarded_workspace_requires_default_role"`,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user