Skip to content

Database migration

Migrate databases

  • Developers can add migration scripts for databases.
  • They can run that scripts anytime to migrate database structure and data.

Sample

import * as T from 'types';
import * as db from 'db-interfaces';
import * as _ from 'lodash';

async function main(g: T.IAMGlobal) {
    let order_transactions_meta = await g.sys.system.getTableMeta({
        instance: 'mysql8',
        database: 'inventory',
        table: 'order_transactions'
    });
    let hasDescriptionColumn = !!_.find(
        order_transactions_meta,
        { name: 'description' }
    );

    let order_transactions = await g.sys.system.executeQuery({
        instance: 'mysql8',
        query: "ALTER TABLE `inventory`.`order_transactions` ADD COLUMN `description` varchar(255) NULL AFTER `qty`"
    });

    return { hasDescriptionColumn, order_transactions_meta };
};
module.exports = main;