Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migration to restrict users without workspaces #5369

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we added "type: 'text'" to the entity file a few weeks ago, this shouldn't create any issue. We should probably use enum in the end though!

);
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`,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ describe('TokenService', () => {
};
const mockUser = { id: '1', email: 'user@example.com' };

const mockedNewDate = new Date();

jest.spyOn(global, 'Date').mockImplementation(() => mockedNewDate);
jest
.spyOn(appTokenRepository, 'findOne')
.mockResolvedValue(mockToken as AppToken);
Expand All @@ -173,7 +176,7 @@ describe('TokenService', () => {
where: {
value: hashedToken,
type: AppTokenType.PasswordResetToken,
expiresAt: MoreThan(new Date()),
expiresAt: MoreThan(mockedNewDate),
revokedAt: IsNull(),
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class User {

@Field(() => Workspace, { nullable: false })
@ManyToOne(() => Workspace, (workspace) => workspace.users, {
onDelete: 'SET NULL',
onDelete: 'RESTRICT',
})
defaultWorkspace: Relation<Workspace>;

Expand Down
Loading