# Install & setup # API Reference **Kind**: global class **Extends**: SqlMigrator * [KnexMigrator](#KnexMigrator) ⇐ SqlMigrator * [new KnexMigrator()](#new_KnexMigrator_new) * _instance_ * [.init(args)](#KnexMigrator+init) * [.sync()](#KnexMigrator+sync) * [.clean(args)](#KnexMigrator+clean) * [.migrationsCreate(args)](#KnexMigrator+migrationsCreate) ⇒ object \| String \| String * [.migrationsDelete(args)](#KnexMigrator+migrationsDelete) ⇒ String \| String * [.migrationsUp(args)](#KnexMigrator+migrationsUp) * [.migrationsDown(args)](#KnexMigrator+migrationsDown) * [.migrationsWrite(args)](#KnexMigrator+migrationsWrite) * [.migrationsList(args)](#KnexMigrator+migrationsList) ⇒ Object \| Object \| Object \| String \| String * [.migrationsToSql(args)](#KnexMigrator+migrationsToSql) ⇒ Object \| Object \| Object \| String \| String * [.migrationsSquash(args)](#KnexMigrator+migrationsSquash) * [.migrationsCreateManually(args)](#KnexMigrator+migrationsCreateManually) * [.migrationsRenameProjectKey(args)](#KnexMigrator+migrationsRenameProjectKey) ⇒ Result * [.migrationsCreateEnv(args)](#KnexMigrator+migrationsCreateEnv) ⇒ Promise.<void> * [.migrationsDeleteEnv(args)](#KnexMigrator+migrationsDeleteEnv) ⇒ Promise.<void> * [.migrationsCreateEnvDb(args)](#KnexMigrator+migrationsCreateEnvDb) ⇒ Result * _static_ * [.KnexMigrator](#KnexMigrator.KnexMigrator) * [new KnexMigrator()](#new_KnexMigrator.KnexMigrator_new) ### new KnexMigrator() Class to create an instance of KnexMigrator ### knexMigrator.init(args) Initialises migration project Creates project json file in pwd of where command is run. Creates xmigrator folder in pwd, within which migrations for all dbs will be sored **Kind**: instance method of [KnexMigrator](#KnexMigrator) | Param | Type | Description | | --- | --- | --- | | args | object | | | args.type | String | type of database (mysql | pg | oracle | mssql | sqlite) | | args.title | String | Name of Project | | args.folder | String | Project Dir | ### knexMigrator.sync() Sync is called after init() or any change to config.xc.json file This initialises databases and migration tables within each connection of config.xc.json **Kind**: instance method of [KnexMigrator](#KnexMigrator) ### knexMigrator.clean(args) **Kind**: instance method of [KnexMigrator](#KnexMigrator) | Param | Type | | --- | --- | | args | Object | | args.env | Object | | args.dbAlias | Object | | args.json | Object | ### knexMigrator.migrationsCreate(args) ⇒ object \| String \| String Creates up and down migration files within migration folders **Kind**: instance method of [KnexMigrator](#KnexMigrator) **Returns**: object - filesString - files.upString - files.down | Param | Type | Description | | --- | --- | --- | | args | object | | | args.dbAlias | String | Database alias within environment | ### knexMigrator.migrationsDelete(args) ⇒ String \| String Creates up and down migration files within migration folders **Kind**: instance method of [KnexMigrator](#KnexMigrator) **Returns**: String - files.upString - files.down | Param | Type | | --- | --- | | args | object | | args.env | String | | args.dbAlias | String | ### knexMigrator.migrationsUp(args) migrationsUp **Kind**: instance method of [KnexMigrator](#KnexMigrator) | Param | Type | Description | | --- | --- | --- | | args | object | | | args.env | String | | | args.dbAlias | String | | | args.folder | String | | | args.steps | Number | number of steps to migrate | | args.file | String | till which file to migration | | args.sqlContentMigrate | Number | defaults to 1 , on zero sqlContent is ignored and only filenames are migrated to _evolution table | ### knexMigrator.migrationsDown(args) migrationsDown **Kind**: instance method of [KnexMigrator](#KnexMigrator) | Param | Type | Description | | --- | --- | --- | | args | object | | | args.env | String | | | args.dbAlias | String | | | args.folder | String | | | args.steps | Number | number of steps to migrate | | args.file | String | till which file to migration | | args.sqlContentMigrate | Number | defaults to 1 , on zero sqlContent is ignored and only filenames are migrated to _evolution table | ### knexMigrator.migrationsWrite(args) Migrations write **Kind**: instance method of [KnexMigrator](#KnexMigrator) | Param | Type | Description | | --- | --- | --- | | args | \* | | | args.env | String | | | args.dbAlias | String | | | args.folder | String | | | args.upStatement | Array.<Object> | array of sql statements in obj | | args.upStatement[].sql | String | sql statements without ';' | | args.downStatement | Array.<Object> | | | args.downStatement[].sql | String | sql statements without ';' | | args.up | String | up filename - up filename (only name not entire path) | | args.down | String | down filename - down filename (only name not entire path) | ### knexMigrator.migrationsList(args) ⇒ Object \| Object \| Object \| String \| String Migrations List **Kind**: instance method of [KnexMigrator](#KnexMigrator) **Returns**: Object - ResultObject - Result.dataObject - Result.data.objectString - Result.data.object.listString - Result.data.object.pending | Param | Type | Description | | --- | --- | --- | | args | object | | | args.env | String | | | args.dbAlias | String | | | args.steps | Number | number of steps to migrate | | args.file | String | till which file to migration | ### knexMigrator.migrationsToSql(args) ⇒ Object \| Object \| Object \| String \| String Migrations to SQL **Kind**: instance method of [KnexMigrator](#KnexMigrator) **Returns**: Object - ResultObject - Result.dataObject - Result.data.objectString - Result.data.object.upString - Result.data.object.down | Param | Type | | --- | --- | | args | \* | | args.env | String | | args.dbAlias | String | | args.folder | String | ### knexMigrator.migrationsSquash(args) Migrations Squash **Kind**: instance method of [KnexMigrator](#KnexMigrator) | Param | Type | | --- | --- | | args | \* | | args.env | String | | args.dbAlias | String | | args.folder | String | | args.file | String | | args.steps | String | | args.up | String | | args.down | String | ### knexMigrator.migrationsCreateManually(args) Migrations Create Manual **Kind**: instance method of [KnexMigrator](#KnexMigrator) | Param | Type | | --- | --- | | args | \* | | args.env | String | | args.dbAlias | String | | args.folder | String | | args.file | String | | args.steps | String | | args.up | String | | args.down | String | ### knexMigrator.migrationsRenameProjectKey(args) ⇒ Result **Kind**: instance method of [KnexMigrator](#KnexMigrator) | Param | Type | Description | | --- | --- | --- | | args | | | | args.folder | String | defaults to process.cwd() | | args.key | String | | | args.value | String | | ### knexMigrator.migrationsCreateEnv(args) ⇒ Promise.<void> update json update sqlite project reopen **Kind**: instance method of [KnexMigrator](#KnexMigrator) | Param | Type | | --- | --- | | args | | | args.folder | String | | args.env | String | | args.envValue | String | ### knexMigrator.migrationsDeleteEnv(args) ⇒ Promise.<void> update json update sqlite project reopen **Kind**: instance method of [KnexMigrator](#KnexMigrator) | Param | Type | | --- | --- | | args | | | args.folder | String | | args.env | String | ### knexMigrator.migrationsCreateEnvDb(args) ⇒ Result **Kind**: instance method of [KnexMigrator](#KnexMigrator) | Param | Type | | --- | --- | | args | | | args.folder | String | | args.env | String | | args.db | String | ### KnexMigrator.KnexMigrator **Kind**: static class of [KnexMigrator](#KnexMigrator) #### new KnexMigrator() Creates an instance of KnexMigrator. test