Skip to content

Commit

Permalink
nullable fcmPushUserToken on userDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
gianlazz committed Jun 2, 2024
1 parent de1402c commit 755b6c8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dal/entity/userDevice.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class UserDevice {

@Field()
@Unique()
@Property({ fieldName: 'fcmPushUserToken' })
@Property({ fieldName: 'fcmPushUserToken', nullable: true })
public fcmPushUserToken!: string;

@Property({ type: 'json', nullable: true })
Expand Down
2 changes: 1 addition & 1 deletion src/dal/migrations/postgres/.snapshot-postgres.json
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"nullable": true,
"mappedType": "string"
},
"web_push_subscription": {
Expand Down
15 changes: 15 additions & 0 deletions src/dal/migrations/postgres/Migration20240602032851.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Migration } from '@mikro-orm/migrations';

export class Migration20240602032851 extends Migration {

async up(): Promise<void> {
this.addSql('alter table "user_device" alter column "fcmPushUserToken" type varchar(255) using ("fcmPushUserToken"::varchar(255));');
this.addSql('alter table "user_device" alter column "fcmPushUserToken" drop not null;');
}

async down(): Promise<void> {
this.addSql('alter table "user_device" alter column "fcmPushUserToken" type varchar(255) using ("fcmPushUserToken"::varchar(255));');
this.addSql('alter table "user_device" alter column "fcmPushUserToken" set not null;');
}

}
16 changes: 16 additions & 0 deletions src/dal/migrations/sqlite/Migration20240602032850.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Migration } from '@mikro-orm/migrations';

export class Migration20240602032850 extends Migration {

async up(): Promise<void> {
this.addSql('PRAGMA foreign_keys = OFF;');
this.addSql('CREATE TABLE `_knex_temp_alter323` (`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, `fcmPushUserToken` text, `userId` integer NOT NULL, `web_push_subscription` json NULL, CONSTRAINT `user_device_userId_foreign` FOREIGN KEY (`userId`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE);');
this.addSql('INSERT INTO "_knex_temp_alter323" SELECT * FROM "user_device";;');
this.addSql('DROP TABLE "user_device";');
this.addSql('ALTER TABLE "_knex_temp_alter323" RENAME TO "user_device";');
this.addSql('CREATE UNIQUE INDEX `user_device_fcmPushUserToken_unique` on `user_device` (`fcmPushUserToken`);');
this.addSql('CREATE INDEX `user_device_userId_index` on `user_device` (`userId`);');
this.addSql('PRAGMA foreign_keys = ON;');
}

}

0 comments on commit 755b6c8

Please sign in to comment.