Skip to content

Commit

Permalink
Updated Appuser primary key type (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlhaufe authored Aug 18, 2024
1 parent e238287 commit 29d2ddc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
10 changes: 4 additions & 6 deletions migrations/.snapshot-cathedral.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
"columns": {
"id": {
"name": "id",
"type": "char(254)",
"type": "uuid",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 254,
"mappedType": "character"
"mappedType": "uuid"
},
"name": {
"name": "name",
Expand Down Expand Up @@ -158,13 +157,12 @@
"columns": {
"app_user_id": {
"name": "app_user_id",
"type": "char(254)",
"type": "uuid",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"length": 254,
"mappedType": "character"
"mappedType": "uuid"
},
"organization_id": {
"name": "organization_id",
Expand Down
29 changes: 29 additions & 0 deletions migrations/Migration20240818015511.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Migration } from '@mikro-orm/migrations';

export class Migration20240818015511 extends Migration {

override async up(): Promise<void> {
this.addSql('alter table "app_user_organization_role" drop constraint "app_user_organization_role_app_user_id_foreign";');

this.addSql('alter table "app_user" alter column "id" drop default;');
this.addSql('alter table "app_user" alter column "id" type uuid using ("id"::text::uuid);');

this.addSql('alter table "app_user_organization_role" alter column "app_user_id" drop default;');
this.addSql('alter table "app_user_organization_role" alter column "app_user_id" type uuid using ("app_user_id"::text::uuid);');
this.addSql('alter table "app_user_organization_role" add constraint "app_user_organization_role_app_user_id_foreign" foreign key ("app_user_id") references "app_user" ("id") on delete cascade;');
}

override async down(): Promise<void> {
this.addSql('alter table "app_user" alter column "id" type text using ("id"::text);');

this.addSql('alter table "app_user_organization_role" alter column "app_user_id" type text using ("app_user_id"::text);');

this.addSql('alter table "app_user_organization_role" drop constraint "app_user_organization_role_app_user_id_foreign";');

this.addSql('alter table "app_user" alter column "id" type char(254) using ("id"::char(254));');

this.addSql('alter table "app_user_organization_role" alter column "app_user_id" type char(254) using ("app_user_id"::char(254));');
this.addSql('alter table "app_user_organization_role" add constraint "app_user_organization_role_app_user_id_foreign" foreign key ("app_user_id") references "app_user" ("id") on delete cascade;');
}

}
2 changes: 1 addition & 1 deletion server/data/models/AppUserSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import AppUser from "../../domain/application/AppUser.js";
export default new EntitySchema<AppUser>({
class: AppUser,
properties: {
id: { type: 'character varying', primary: true, length: 254 },
id: { type: 'uuid', primary: true },
name: { type: 'character varying', nullable: false, length: 254 },
creationDate: { type: 'datetime', nullable: false },
lastLoginDate: { type: 'datetime', nullable: true },
Expand Down

0 comments on commit 29d2ddc

Please sign in to comment.