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

fix: add integration tests for user domain #2322

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
29 changes: 29 additions & 0 deletions migrations/1738684563598-wallet_user_id_nullable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { MigrationInterface, QueryRunner } from 'typeorm';

export class WalletUserIdNullable1738684563598 implements MigrationInterface {
name = 'WalletUserIdNullable1738684563598';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "wallets" DROP CONSTRAINT "FK_wallets_user_id"`,
);
await queryRunner.query(
`ALTER TABLE "wallets" ALTER COLUMN "user_id" SET NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "wallets" ADD CONSTRAINT "FK_wallets_user_id" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "wallets" DROP CONSTRAINT "FK_wallets_user_id"`,
);
await queryRunner.query(
`ALTER TABLE "wallets" ALTER COLUMN "user_id" DROP NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "wallets" ADD CONSTRAINT "FK_wallets_user_id" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
}
}
1 change: 1 addition & 0 deletions src/datasources/wallets/entities/wallets.entity.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class Wallet implements z.infer<typeof WalletSchema> {

@ManyToOne(() => User, (user: User) => user.id, {
onDelete: 'CASCADE',
nullable: false,
Copy link
Member Author

Choose a reason for hiding this comment

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

This otherwise defaults to true meaning that Wallets could be added without a User.

})
@JoinColumn({
name: 'user_id',
Expand Down
Loading
Loading