unoffical wafrn mirror wafrn.net
atproto social-network activitypub
at testPDSNotExplode 34 lines 1.0 kB view raw
1import { Sequelize } from 'sequelize' 2import { Umzug, SequelizeStorage } from 'umzug' 3import process from 'process' 4import { realpathSync } from 'fs' 5import { pathToFileURL } from 'url' 6import { completeEnvironment } from './utils/backendOptions.js' 7 8function wasCalledAsScript() { 9 const realPath = realpathSync(process.argv[1]) 10 const realPathAsUrl = pathToFileURL(realPath).href 11 return import.meta.url === realPathAsUrl 12} 13 14const sequelize = new Sequelize(completeEnvironment.databaseConnectionString) 15 16const umzug = new Umzug({ 17 migrations: { glob: 'migrations/*.ts' }, 18 context: sequelize.getQueryInterface(), 19 storage: new SequelizeStorage({ sequelize }), 20 logger: console 21}) 22 23// export the type helper exposed by umzug, which will have the `context` argument typed correctly 24export type Migration = typeof umzug._types.migration 25 26if (wasCalledAsScript()) { 27 if (process.argv[2] == 'init-container') { 28 await umzug.up() 29 console.log('Migrations run successfully') 30 process.exit(0) 31 } else { 32 await umzug.runAsCLI() 33 } 34}