UNPKG

arango-migrate

Version:
1 lines 41.9 kB
{"version":3,"file":"cli.cjs","sources":["../src/ArangoMigrate.ts","../src/cli.ts"],"sourcesContent":["import { Config } from 'arangojs/connection'\nimport glob from 'glob'\nimport path from 'path'\nimport { aql, Database } from 'arangojs'\nimport { CollectionType, CreateCollectionOptions, DocumentCollection, EdgeCollection } from 'arangojs/collection'\nimport fs from 'fs'\nimport slugify from 'slugify'\nimport { TransactionOptions } from 'arangojs/database'\nimport { pathToFileURL } from 'url'\n\ntype Collection = DocumentCollection<any> & EdgeCollection<any>\n\nexport interface CollectionOptions {\n collectionName: string\n options?: CreateCollectionOptions & {\n type?: CollectionType\n }\n}\n\nexport type Collections = Array<string | CollectionOptions>\n\nexport type StepFunction = (callback) => Promise<any>\n\nexport interface Migration {\n /**\n * Optional function that will be called after the migration's `down` function is executed.\n * @param {Database} db - Database instance.\n * @param {*} data - Optional value received from the `beforeDown` function.\n * @returns {Promise<*>} - Value returned will be passed to the `afterDown` function.\n */\n afterDown?: (db: Database, data?: any) => Promise<any>,\n /**\n * Optional function that will be called after the migration's `up` function is executed.\n * @param {Database} db - Database instance.\n * @param {*} data - Value returned from the `up` function.\n * @returns {Promise<*>} - Value returned will be passed to the `afterUp` function.\n */\n afterUp?: (db: Database, data?: any) => Promise<void>,\n /**\n * Optional function that will be called before the migration's `down` function is executed.\n * @param {Database} db - Database instance.\n * @returns {Promise<*>} - Value returned will be passed to the `down` function.\n */\n beforeDown?: (db: Database) => Promise<any>,\n /**\n * Optional function that will be called before the migration's `up` function is executed.\n * @param {Database} db - Database instance.\n * @returns {Promise<*>} - Value returned will be passed to the `up` function.\n */\n beforeUp?: (db: Database) => Promise<any>\n /**\n * Defines all the collections that will be used as part of this migration.\n * @returns {Promise<Collections>} An array of collection names or an array of collection options.\n */\n collections(): Promise<Collections>;\n /**\n * Optional description of what the migration does. This value will be stored in the migration log.\n */\n description?: string,\n /**\n * Function that will be called to perform the `down` migration.\n * @param {Database} db - Database instance.\n * @param {StepFunction} - step The `step` function is used to add valid ArangoDB operations to the transaction.\n * @param {*} data - Optional value received from the `beforeDown` function.\n */\n down?: (db: Database, step: StepFunction, data?: any) => Promise<any>;\n /**\n * Optional function that configures how the transaction will be executed. See ArangoDB documentation for more information.\n * @returns {Promise<TransactionOptions>} - The transaction options.\n */\n transactionOptions?: () => Promise<TransactionOptions>;\n /**\n * Function that will be called to perform the `up` migration.\n * @param {Database} - db Database instance.\n * @param {StepFunction} - step The `step` function is used to add valid ArangoDB operations to the transaction.\n * @param {*} data Optional value received from the `beforeUp` function.\n */\n up: (db: Database, step: StepFunction, data?: any) => Promise<any>;\n}\n\nexport interface MigrationHistory {\n _id: string;\n _key: string;\n counter: number;\n createdAt: string;\n description?: string;\n direction: 'up' | 'down';\n name: string;\n version: number;\n}\n\nexport interface ArangoMigrateOptions {\n /**\n * Automatically create referenced collections if they do not exist. Defaults to `true`.\n */\n autoCreateNewCollections?: boolean,\n /**\n * ArangoDB connection options.\n */\n dbConfig: Config,\n /**\n * The collection in which the migration history will be stored. Defaults to `migration_history`.\n */\n migrationHistoryCollection?: string,\n /**\n * Path to the directory containing the migration files.\n */\n migrationsPath: string\n}\n\nconst isString = (s): boolean => {\n return typeof (s) === 'string' || s instanceof String\n}\n\nconst MIGRATION_TEMPLATE_JS = `/**\n * @typedef { import(\"arango-migrate\").Migration } Migration\n */\n\n/**\n * @type { Migration }\n */\nconst migration = {\n async collections () {\n return []\n },\n async up (db, step) {\n }\n}\n\nexport default migration\n`\n\nconst MIGRATION_TEMPLATE_TS = `import { Collections, Migration, StepFunction } from 'arango-migrate'\nimport { Database } from 'arangojs'\n\nconst migration: Migration = {\n async collections (): Promise<Collections> {\n return []\n },\n async up (db: Database, step: StepFunction) {}\n}\n\nexport default migration\n`\n\nexport const DEFAULT_CONFIG_PATH = './config.migrate.js'\nexport const DEFAULT_MIGRATIONS_PATH = './migrations'\nexport const DEFAULT_MIGRATION_HISTORY_COLLECTION = 'migration_history'\n\nexport class ArangoMigrate {\n private readonly options: ArangoMigrateOptions\n private readonly migrationHistoryCollection: string\n private db: Database\n private readonly migrationPaths: string[]\n private readonly migrationsPath: string\n\n constructor (options: ArangoMigrateOptions) {\n this.options = options\n this.migrationsPath = this.options.migrationsPath || DEFAULT_MIGRATIONS_PATH\n this.migrationHistoryCollection = this.options.migrationHistoryCollection || DEFAULT_MIGRATION_HISTORY_COLLECTION\n this.migrationPaths = this.loadMigrationPaths(this.migrationsPath)\n }\n\n public static async loadConfig (configPath: string = DEFAULT_CONFIG_PATH): Promise<ArangoMigrateOptions> {\n const p = path.resolve(configPath)\n if (!fs.existsSync((p))) {\n throw new Error(`Config file ${p} not found.`)\n }\n\n const importedConfig = await import(pathToFileURL(p).href)\n\n const config: ArangoMigrateOptions = importedConfig.default\n\n if (!config.dbConfig) {\n throw new Error('Config object must contain a dbConfig property.')\n }\n\n return config\n }\n\n public loadMigrationPaths (migrationsPath: string) {\n return glob.sync(migrationsPath + '/*').reduce((acc, filePath) => {\n return [\n ...acc,\n path.resolve(filePath)\n ]\n }, []).sort((a, b) => a.localeCompare(b))\n }\n\n public getMigrationPaths (): string[] {\n return this.migrationPaths\n }\n\n public async initialize (): Promise<void> {\n const name = this.options.dbConfig.databaseName\n\n try {\n this.db = new Database({ ...this.options.dbConfig, databaseName: undefined })\n this.db = await this.db.createDatabase(name)\n } catch (err) {\n this.db = new Database(this.options.dbConfig)\n this.db = this.db.database(name)\n }\n }\n\n public migrationExists (version: number): boolean {\n return this.getMigrationPathFromVersion(version) !== undefined\n }\n\n public getMigrationPathFromVersion (version: number): string {\n return this.migrationPaths.find(x => {\n const basename = path.basename(x)\n return version === Number(basename.split('_')[0])\n })\n }\n\n public async getMigrationFromVersion (version: number): Promise<Migration> {\n const migrationPath = this.migrationPaths.find(x => {\n const basename = path.basename(x)\n\n return version === Number(basename.split('_')[0]) && fs.existsSync(path.resolve(x))\n })\n\n const importedMigration = await import(pathToFileURL(migrationPath).href)\n return importedMigration.default\n }\n\n public async getMigrationHistoryCollection () {\n let collection: DocumentCollection\n try {\n collection = await this.db.createCollection(this.migrationHistoryCollection)\n } catch {\n collection = this.db.collection(this.migrationHistoryCollection)\n }\n return collection\n }\n\n public async getMigrationHistory (direction: 'ASC' | 'DESC' = 'ASC'): Promise<MigrationHistory[]> {\n const collection = await this.getMigrationHistoryCollection()\n\n return await (await this.db.query(aql`\n FOR x IN ${collection}\n SORT x.counter ${direction}\n RETURN x`)).all()\n }\n\n public async getLatestMigration (): Promise<MigrationHistory | null> {\n const collection = await this.getMigrationHistoryCollection()\n\n return await (await this.db.query(aql`\n FOR x IN ${collection}\n SORT x.counter DESC\n LIMIT 1\n RETURN x`)).next()\n }\n\n public async writeMigrationHistory (direction: 'up' | 'down', name: string, description: string, version: number) {\n const collection = await this.getMigrationHistoryCollection()\n\n const latest = await this.getLatestMigration()\n\n await collection.save({\n name,\n description,\n version,\n direction,\n counter: latest ? latest.counter + 1 : 1,\n createdAt: new Date()\n })\n }\n\n public async initializeTransactionCollections (collections: Collections) {\n const newCollections = new Set<Collection>()\n const allCollectionNames = new Set<string>()\n\n const transactionCollections = []\n\n let createdCollectionCount = 0\n\n for (const collectionData of collections) {\n const data = (isString(collectionData)\n ? {\n collectionName: collectionData\n }\n : collectionData) as CollectionOptions\n allCollectionNames.add(data.collectionName)\n let collection\n try {\n if (this.options.autoCreateNewCollections !== false) {\n /**\n * NOTE: arangojs *.d.ts invites user to pass \"literal\" options object\n * to infer typeof collection. Thus there is no another way to support\n * collections() API but using this ugly \"as any\" cast\n */\n collection = await this.db.createCollection(data.collectionName, data.options as any)\n createdCollectionCount++\n newCollections.add(collection)\n }\n } catch {\n collection = this.db.collection(data.collectionName)\n if (!collection) {\n throw new Error(`Collection ${data.collectionName} not found.`)\n }\n }\n if (collection) {\n transactionCollections.push(collection)\n }\n }\n\n return {\n transactionCollections,\n newCollections,\n allCollectionNames,\n createdCollectionCount\n }\n }\n\n public async runUpMigrations (to?: number, dryRun?: boolean, noHistory?: boolean): Promise<{\n appliedMigrations: number\n createdCollections: number\n }> {\n const versions = this.getVersionsFromMigrationPaths()\n\n if (!to) {\n to = versions[versions.length - 1]\n }\n\n const history = await this.getMigrationHistory('DESC')\n\n const versionsToRun = versions.filter((version) => {\n const migration = history.find((migration) => migration.version === version)\n return (migration?.direction !== 'up') && version <= to\n })\n\n let appliedMigrations = 0\n let createdCollections = 0\n\n for (const i of versionsToRun) {\n let migration: Migration\n try {\n migration = await this.getMigrationFromVersion(i)\n } catch (err) {\n console.log(err)\n return\n }\n\n const name = path.basename(this.getMigrationPathFromVersion(i))\n\n const collectionNames = migration.collections ? await migration.collections() : []\n\n const { transactionCollections, newCollections, createdCollectionCount } = await this.initializeTransactionCollections(collectionNames)\n createdCollections += createdCollectionCount\n\n let beforeUpData\n if (migration.beforeUp) {\n beforeUpData = await migration.beforeUp(this.db)\n }\n\n const transactionOptions = await migration.transactionOptions?.()\n\n const transaction = await this.db.beginTransaction(transactionCollections, transactionOptions)\n\n let error\n let upResult\n\n if (migration.up) {\n try {\n upResult = await migration.up(this.db, (callback: () => Promise<any>) => transaction.step(callback), beforeUpData)\n } catch (err) {\n console.log(err)\n error = new Error(`Running up failed for migration ${i}.`)\n }\n }\n\n if (!dryRun) {\n try {\n const transactionStatus = await transaction.commit()\n\n if (transactionStatus.status !== 'committed') {\n error = new Error(`Transaction failed with status ${transactionStatus.status} for migration ${name}.`)\n }\n } catch (err) {\n error = new Error('Transaction failed.')\n }\n }\n\n try {\n if (migration.afterUp) {\n await migration.afterUp(this.db, upResult)\n }\n } catch (err) {\n error = new Error(`afterUp threw an error ${err}.`)\n }\n\n if (error) {\n for (const collection of Array.from(newCollections)) {\n await collection.drop()\n }\n }\n\n if (!error) {\n if (!dryRun && noHistory !== true) {\n await this.writeMigrationHistory('up', name, migration.description, i)\n }\n }\n\n if (error) {\n throw error\n }\n appliedMigrations += 1\n }\n return { appliedMigrations, createdCollections }\n }\n\n public async runDownMigrations (to?: number, dryRun?: boolean, noHistory?: boolean, disallowMissingVersions?: boolean): Promise<{ appliedMigrations: number, createdCollections: number; }> {\n const latestMigration = await this.getLatestMigration()\n\n if (!latestMigration) {\n throw new Error('No migrations have been applied.')\n }\n\n if (!to) {\n to = 1\n }\n\n let appliedMigrations = 0\n let createdCollections = 0\n\n let version = latestMigration.version\n while (version >= to) {\n if (!this.migrationExists(version) && !disallowMissingVersions) {\n version--\n continue\n }\n\n let migration: Migration\n try {\n migration = await this.getMigrationFromVersion(version)\n } catch (err) {\n console.log(err)\n return\n }\n\n const name = path.basename(this.getMigrationPathFromVersion(version))\n\n const collectionNames = migration.collections ? await migration.collections() : []\n\n const { transactionCollections, newCollections, createdCollectionCount } = await this.initializeTransactionCollections(collectionNames)\n\n createdCollections += createdCollectionCount\n\n let error\n\n let beforeDownData\n\n if (migration.beforeDown) {\n beforeDownData = await migration.beforeDown(this.db)\n }\n\n const transaction = await this.db.beginTransaction(transactionCollections)\n\n let downResult\n\n if (migration.down) {\n try {\n downResult = await migration.down(this.db, (callback: () => Promise<any>) => transaction.step(callback), beforeDownData)\n } catch (err) {\n console.log(err)\n error = new Error(`Running up failed for migration ${version}.`)\n }\n }\n\n if (!dryRun) {\n try {\n const transactionStatus = await transaction.commit()\n\n if (transactionStatus.status !== 'committed') {\n error = new Error(`Transaction failed with status ${transactionStatus.status} for migration ${name}.`)\n }\n } catch (err) {\n error = new Error('Transaction failed.')\n }\n }\n\n try {\n if (migration.afterDown) {\n await migration.afterDown(this.db, downResult)\n }\n } catch (err) {\n error = new Error(`afterDown threw an error ${err}.`)\n }\n\n if (error) {\n for (const collection of Array.from(newCollections)) {\n await collection.drop()\n }\n }\n\n if (!error) {\n if (!dryRun && noHistory !== true) {\n await this.writeMigrationHistory('down', name, migration.description, version)\n }\n }\n\n if (error) {\n throw error\n }\n appliedMigrations += 1\n version--\n }\n return { appliedMigrations, createdCollections }\n }\n\n public getVersionsFromMigrationPaths (): number[] {\n return this.migrationPaths.map(migrationPath => {\n return Number(path.basename(migrationPath).split('_')[0])\n }).sort((a, b) => a - b)\n }\n\n public validateMigrationFolderNotEmpty () {\n if (this.migrationPaths.length === 0) {\n throw new Error('No migrations.')\n }\n }\n\n public validateMigrationVersions () {\n const versions = this.getVersionsFromMigrationPaths()\n\n if (!versions || versions.length !== new Set(versions).size) {\n throw new Error('Migration versions must be unique.')\n }\n }\n\n public async validateMigrationVersion (version: number) {\n const latestMigration = await this.getLatestMigration()\n\n if (!latestMigration && version > 1) {\n throw new Error(`Migration sequence must start with 1, not ${version}.`)\n }\n\n if (latestMigration && version > Number(latestMigration.version) + 1) {\n throw new Error(`Migration must be ran in sequence. ${version} must immediately follow ${latestMigration.version}.`)\n }\n\n if (latestMigration && version <= Number(latestMigration.version)) {\n const name = this.getMigrationPathFromVersion((version))\n\n throw new Error(`Cannot run up migration ${name} because migration has already been applied.`)\n }\n }\n\n public writeNewMigration (name: string, typescript: boolean): string {\n name = slugify(name, '_')\n const version = Date.now()\n\n if (!fs.existsSync(path.resolve(this.migrationsPath))) {\n fs.mkdirSync(path.resolve(this.migrationsPath))\n }\n\n const res = path.resolve(`${this.migrationsPath}/${version}_${name}${typescript ? '.ts' : '.js'}`)\n\n fs.writeFileSync(res, typescript ? MIGRATION_TEMPLATE_TS : MIGRATION_TEMPLATE_JS)\n\n return res\n }\n\n public async hasNewMigrations (): Promise<boolean> {\n const history = await this.getMigrationHistory('DESC')\n if (!history.length) {\n return true\n }\n\n const versions = this.getVersionsFromMigrationPaths()\n\n return versions.filter((version) => {\n const migration = history.find((migration) => migration.version === version)\n return (migration?.direction !== 'up')\n }).length !== 0\n }\n}\n","#!/usr/bin/env node\n\nimport { Command } from 'commander'\nimport * as path from 'path'\nimport { ArangoMigrate, DEFAULT_CONFIG_PATH } from './ArangoMigrate'\n\ninterface CommanderOptions {\n config?: string,\n disallowMissingVersions?: boolean,\n down?: boolean,\n dryRun?: boolean,\n init?: string,\n list?: boolean,\n noHistory?: boolean,\n single?: number,\n to?: number,\n typescript?: boolean,\n up?: boolean\n}\n\n(async () => {\n const program = new Command()\n\n program\n .option('-c, --config <config>', 'path to a js config file. Defaults to ./config.migrate.js')\n .option('-u, --up', 'run up migrations. Defaults to running all un-applied migrations if no --to parameter is provided')\n .option('-d, --down', 'run down migrations')\n .option('-t, --to <version>', 'run migrations to and including a specific version')\n .option('-i --init <name>', 'initialize a new migration file')\n .option('-l --list', 'list all applied migrations')\n .option('-dr --dry-run', 'dry run. Executes migration lifecycle functions but never commits the transaction to the database or writes to the migration history log')\n .option('-nh --no-history', 'Skips writing to the migration history log. Use this with caution since the applied migrations will not be saved in the migration history log, opening the possibility of applying the same migration multiple times and potentially dirtying your data')\n .option('--disallow-missing-versions', 'raise an exception if there are missing versions when running down migrations')\n\n program.parse(process.argv)\n\n const options: CommanderOptions = program.opts()\n\n const configPath = path.resolve(options.config || DEFAULT_CONFIG_PATH)\n\n const config = await ArangoMigrate.loadConfig(configPath)\n\n const am = new ArangoMigrate(config)\n\n am.initialize().then(async () => {\n if (options.list) {\n const history = await am.getMigrationHistory()\n if (!history.length) {\n console.log('No migration history.')\n } else {\n console.table(history)\n }\n process.exit(0)\n } else if (options.init) {\n console.log(`Migration created at ${am.writeNewMigration(options.init, options.typescript)}.`)\n process.exit(0)\n } else if (options.up) {\n am.validateMigrationFolderNotEmpty()\n am.validateMigrationVersions()\n\n const single = (Number(options.single) >= 0)\n\n const to = Number(single ? options.single : options.to)\n\n if (!await am.hasNewMigrations() && !options.dryRun) {\n console.log('No new migrations to run.')\n process.exit(0)\n }\n const { createdCollections, appliedMigrations } = await am.runUpMigrations(to, options.dryRun, options.noHistory)\n console.log(`${createdCollections} collections created.`)\n if (options.dryRun) {\n console.log(`${appliedMigrations} \\`up\\` migrations dry ran.`)\n } else {\n console.log(`${appliedMigrations} \\`up\\` migrations applied.`)\n }\n\n process.exit(0)\n } else if (options.down) {\n am.validateMigrationFolderNotEmpty()\n am.validateMigrationVersions()\n\n const to = Number(options.to)\n\n const { createdCollections, appliedMigrations } = await am.runDownMigrations(to, options.dryRun, options.noHistory, options.disallowMissingVersions)\n console.log(`${createdCollections} collections created.`)\n if (options.dryRun) {\n console.log(`${appliedMigrations} \\`down\\` migrations dry ran.`)\n } else {\n console.log(`${appliedMigrations} \\`down\\` migrations applied.`)\n }\n\n process.exit(0)\n }\n })\n})()\n"],"names":["isString","s","String","MIGRATION_TEMPLATE_JS","MIGRATION_TEMPLATE_TS","DEFAULT_CONFIG_PATH","DEFAULT_MIGRATIONS_PATH","DEFAULT_MIGRATION_HISTORY_COLLECTION","ArangoMigrate","constructor","options","migrationHistoryCollection","db","migrationPaths","migrationsPath","loadMigrationPaths","loadConfig","configPath","p","path","resolve","fs","existsSync","Error","importedConfig","pathToFileURL","href","config","default","dbConfig","glob","sync","reduce","acc","filePath","sort","a","b","localeCompare","getMigrationPaths","initialize","name","databaseName","Database","undefined","createDatabase","err","database","migrationExists","version","getMigrationPathFromVersion","find","x","basename","Number","split","getMigrationFromVersion","migrationPath","importedMigration","getMigrationHistoryCollection","collection","createCollection","getMigrationHistory","direction","query","aql","all","getLatestMigration","next","writeMigrationHistory","description","latest","save","counter","createdAt","Date","initializeTransactionCollections","collections","newCollections","Set","allCollectionNames","transactionCollections","createdCollectionCount","collectionData","data","collectionName","add","autoCreateNewCollections","push","runUpMigrations","to","dryRun","noHistory","versions","getVersionsFromMigrationPaths","length","history","versionsToRun","filter","migration","appliedMigrations","createdCollections","i","console","log","collectionNames","beforeUpData","beforeUp","transactionOptions","transaction","beginTransaction","error","upResult","up","callback","step","transactionStatus","commit","status","afterUp","Array","from","drop","runDownMigrations","disallowMissingVersions","latestMigration","beforeDownData","beforeDown","downResult","down","afterDown","map","validateMigrationFolderNotEmpty","validateMigrationVersions","size","validateMigrationVersion","writeNewMigration","typescript","slugify","now","mkdirSync","res","writeFileSync","hasNewMigrations","program","Command","option","parse","process","argv","opts","am","then","list","table","exit","init","single"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8GA,MAAMA,QAAQ,GAAIC,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