From 29d2ddce1970c30d879f45dcb73d94169b0dc933 Mon Sep 17 00:00:00 2001 From: Michael Haufe Date: Sat, 17 Aug 2024 21:35:44 -0500 Subject: [PATCH] Updated Appuser primary key type (#329) --- migrations/.snapshot-cathedral.json | 10 ++++----- migrations/Migration20240818015511.ts | 29 +++++++++++++++++++++++++++ server/data/models/AppUserSchema.ts | 2 +- 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 migrations/Migration20240818015511.ts diff --git a/migrations/.snapshot-cathedral.json b/migrations/.snapshot-cathedral.json index 357acf25..63e694a4 100644 --- a/migrations/.snapshot-cathedral.json +++ b/migrations/.snapshot-cathedral.json @@ -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", @@ -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", diff --git a/migrations/Migration20240818015511.ts b/migrations/Migration20240818015511.ts new file mode 100644 index 00000000..f0c945de --- /dev/null +++ b/migrations/Migration20240818015511.ts @@ -0,0 +1,29 @@ +import { Migration } from '@mikro-orm/migrations'; + +export class Migration20240818015511 extends Migration { + + override async up(): Promise { + 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 { + 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;'); + } + +} diff --git a/server/data/models/AppUserSchema.ts b/server/data/models/AppUserSchema.ts index c15ff1b6..0991b712 100644 --- a/server/data/models/AppUserSchema.ts +++ b/server/data/models/AppUserSchema.ts @@ -4,7 +4,7 @@ import AppUser from "../../domain/application/AppUser.js"; export default new EntitySchema({ 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 },