-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add PhysicalAddress migrations to postgres
- Loading branch information
Showing
3 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
packages/data-store/src/migrations/generic/8-CreatePhysicalAddressTable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
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<void> { | ||
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<void> { | ||
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`, | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/data-store/src/migrations/postgres/1712695589134-CreatePhysicalAddressTable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class CreatePhysicalAddressTable1712695589134 implements MigrationInterface { | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
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<void> { | ||
await queryRunner.query(`DROP TABLE "PhysicalAddress"`) | ||
} | ||
|
||
} |