From 0862dbd4a479f120302afb83a4a21c70c9fe6e08 Mon Sep 17 00:00:00 2001 From: John Melati Date: Wed, 10 Apr 2024 13:06:52 +0200 Subject: [PATCH] fix: rework fix to include missing table in existing migration --- .../generic/8-CreatePhysicalAddressTable.ts | 59 ------------------- .../src/migrations/generic/index.ts | 3 +- .../postgres/1659463079428-CreateContacts.ts | 19 ++++++ ...712695589134-CreatePhysicalAddressTable.ts | 29 --------- 4 files changed, 20 insertions(+), 90 deletions(-) delete mode 100644 packages/data-store/src/migrations/generic/8-CreatePhysicalAddressTable.ts delete mode 100644 packages/data-store/src/migrations/postgres/1712695589134-CreatePhysicalAddressTable.ts diff --git a/packages/data-store/src/migrations/generic/8-CreatePhysicalAddressTable.ts b/packages/data-store/src/migrations/generic/8-CreatePhysicalAddressTable.ts deleted file mode 100644 index 4f9d4664a..000000000 --- a/packages/data-store/src/migrations/generic/8-CreatePhysicalAddressTable.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { DatabaseType, MigrationInterface, QueryRunner } from 'typeorm' -import Debug from 'debug' -import { CreatePhysicalAddressTable1712695589134 } from '../postgres/1712695589134-CreatePhysicalAddressTable' - -const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:migrations') - -export class CreatePhysicalAddressTable1708098041262 implements MigrationInterface { - name = 'CreatePhysicalAddressTable1708098041262' - - public async up(queryRunner: QueryRunner): Promise { - debug('migration: creating physical address tables on postgres') - const dbType: DatabaseType = queryRunner.connection.driver.options.type - - switch (dbType) { - case 'postgres': { - debug('using postgres migration file') - const mig: CreatePhysicalAddressTable1712695589134 = new CreatePhysicalAddressTable1712695589134() - await mig.up(queryRunner) - debug('Migration statements executed') - return - } - case 'sqlite': - case 'expo': - case 'react-native': { - debug('No need to execute migration for this update') - return - } - default: - return Promise.reject( - `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`, - ) - } - } - - public async down(queryRunner: QueryRunner): Promise { - debug('migration: reverting machine state tables') - const dbType: DatabaseType = queryRunner.connection.driver.options.type - - switch (dbType) { - case 'postgres': { - debug('using postgres migration file') - const mig: CreatePhysicalAddressTable1712695589134 = new CreatePhysicalAddressTable1712695589134() - await mig.down(queryRunner) - debug('Migration statements executed') - return - } - case 'sqlite': - case 'expo': - case 'react-native': { - debug('No need to execute migration for this update') - return - } - default: - return Promise.reject( - `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`, - ) - } - } -} diff --git a/packages/data-store/src/migrations/generic/index.ts b/packages/data-store/src/migrations/generic/index.ts index 70a94c013..9769074fb 100644 --- a/packages/data-store/src/migrations/generic/index.ts +++ b/packages/data-store/src/migrations/generic/index.ts @@ -5,7 +5,6 @@ import { CreateStatusList1693866470000 } from './4-CreateStatusList' import { CreateAuditEvents1701635835330 } from './5-CreateAuditEvents' import { CreateDigitalCredential1708525189000 } from './6-CreateDigitalCredential' import { CreateMachineStateStore1708098041262 } from './7-CreateMachineStateStore' -import { CreatePhysicalAddressTable1708098041262 } from './8-CreatePhysicalAddressTable' /** * The migrations array that SHOULD be used when initializing a TypeORM database connection. @@ -16,7 +15,7 @@ import { CreatePhysicalAddressTable1708098041262 } from './8-CreatePhysicalAddre */ // Individual migrations per purpose. Allows parties to not run migrations and thus create/update tables if they are not using a particular feature (yet) -export const DataStoreContactMigrations = [CreateContacts1659463079429, CreateContacts1690925872318, CreatePhysicalAddressTable1708098041262] +export const DataStoreContactMigrations = [CreateContacts1659463079429, CreateContacts1690925872318] export const DataStoreIssuanceBrandingMigrations = [CreateIssuanceBranding1659463079429] export const DataStoreStatusListMigrations = [CreateStatusList1693866470000] export const DataStoreEventLoggerMigrations = [CreateAuditEvents1701635835330] diff --git a/packages/data-store/src/migrations/postgres/1659463079428-CreateContacts.ts b/packages/data-store/src/migrations/postgres/1659463079428-CreateContacts.ts index 4016ee730..5868c1483 100644 --- a/packages/data-store/src/migrations/postgres/1659463079428-CreateContacts.ts +++ b/packages/data-store/src/migrations/postgres/1659463079428-CreateContacts.ts @@ -42,6 +42,24 @@ export class CreateContacts1659463079428 implements MigrationInterface { await queryRunner.query( `ALTER TABLE "Connection" ADD CONSTRAINT "FK_Connection_identityId" FOREIGN KEY ("identityId") REFERENCES "Identity"("id") ON DELETE CASCADE ON UPDATE NO ACTION`, ) + + await queryRunner.query(` + CREATE TABLE "PhysicalAddress" ( + "id" text PRIMARY KEY NOT NULL, + "type" varchar(255) NOT NULL, + "street_name" varchar(255) NOT NULL, + "street_number" varchar(255) NOT NULL, + "postal_code" varchar(255) NOT NULL, + "city_name" varchar(255) NOT NULL, + "province_name" varchar(255) NOT NULL, + "country_code" varchar(2) NOT NULL, + "building_name" varchar(255), + "partyId" uuid, + "created_at" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + "last_updated_at" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT "FK_PhysicalAddressEntity_partyId" FOREIGN KEY ("partyId") REFERENCES "Party" ("id") ON DELETE CASCADE + );` + ); } public async down(queryRunner: QueryRunner): Promise { @@ -59,5 +77,6 @@ export class CreateContacts1659463079428 implements MigrationInterface { await queryRunner.query(`DROP TYPE "public"."CorrelationIdentifier_type_enum"`) await queryRunner.query(`DROP INDEX "public"."IDX_BaseConfigEntity_type"`) await queryRunner.query(`DROP TABLE "BaseConfigEntity"`) + await queryRunner.query(`DROP TABLE "PhysicalAddress"`) } } diff --git a/packages/data-store/src/migrations/postgres/1712695589134-CreatePhysicalAddressTable.ts b/packages/data-store/src/migrations/postgres/1712695589134-CreatePhysicalAddressTable.ts deleted file mode 100644 index 9fe3a3bf6..000000000 --- a/packages/data-store/src/migrations/postgres/1712695589134-CreatePhysicalAddressTable.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class CreatePhysicalAddressTable1712695589134 implements MigrationInterface { - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - CREATE TABLE "PhysicalAddress" ( - "id" text PRIMARY KEY NOT NULL, - "type" varchar(255) NOT NULL, - "street_name" varchar(255) NOT NULL, - "street_number" varchar(255) NOT NULL, - "postal_code" varchar(255) NOT NULL, - "city_name" varchar(255) NOT NULL, - "province_name" varchar(255) NOT NULL, - "country_code" varchar(2) NOT NULL, - "building_name" varchar(255), - "partyId" uuid, - "created_at" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "last_updated_at" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT "FK_PhysicalAddressEntity_partyId" FOREIGN KEY ("partyId") REFERENCES "Party" ("id") ON DELETE CASCADE - );` - ); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP TABLE "PhysicalAddress"`) - } - -}