UNPKG

@sphereon/ssi-sdk.data-store

Version:

67 lines (60 loc) 2.6 kB
import Debug from 'debug' import { DatabaseType, MigrationInterface, QueryRunner } from 'typeorm' import { CreateContacts1690925872592 } from '../postgres/1690925872592-CreateContacts' import { CreateContacts1690925872693 } from '../sqlite/1690925872693-CreateContacts' const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:migrations') export class CreateContacts1690925872318 implements MigrationInterface { name = 'CreateContacts1690925872318' public async up(queryRunner: QueryRunner): Promise<void> { debug('migration: creating contacts tables') const dbType: DatabaseType = queryRunner.connection.driver.options.type switch (dbType) { case 'postgres': { debug('using postgres migration file') const mig: CreateContacts1690925872592 = new CreateContacts1690925872592() await mig.up(queryRunner) debug('Migration statements executed') return } case 'sqlite': case 'expo': case 'react-native': { debug('using sqlite/react-native migration file') const mig: CreateContacts1690925872693 = new CreateContacts1690925872693() await mig.up(queryRunner) debug('Migration statements executed') 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 contacts tables') const dbType: DatabaseType = queryRunner.connection.driver.options.type switch (dbType) { case 'postgres': { debug('using postgres migration file') const mig: CreateContacts1690925872592 = new CreateContacts1690925872592() await mig.down(queryRunner) debug('Migration statements executed') return } case 'sqlite': case 'expo': case 'react-native': { debug('using sqlite/react-native migration file') const mig: CreateContacts1690925872693 = new CreateContacts1690925872693() await mig.down(queryRunner) debug('Migration statements executed') 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`, ) } } }