@kwaeri/mysql-migrator
Version:
The @kwaeri/migration component of the @kwaer/cli user-executable framework.
285 lines (284 loc) • 8.89 kB
text/typescript
/**
* SPDX-PackageName: kwaeri/mysql-migrator
* SPDX-PackageVersion: 0.7.0
* SPDX-FileCopyrightText: © 2014 - 2022 Richard Winters <kirvedx@gmail.com> and contributors
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR MIT
*/
import { NodeKitOptions } from '@kwaeri/standards-types';
import { ServiceProviderSubscriptions, ServiceProviderHelpText, ServicePromiseBits, ServiceEventBits } from '@kwaeri/service';
import { MigratorServiceProvider } from '@kwaeri/migrator';
import { DatabaseDriver } from '@kwaeri/database-driver';
import { Configuration } from '@kwaeri/configuration';
/**
* @typedef { Object } MigrationRecord
* @property { number } id
* @property { string } date
* @property { string } name
* @property { string } sequel
* @property { boolean } applied
*/
export type MigrationRecord = {
id: number;
date: string;
name: string;
sequel: string;
applied: boolean;
};
/**
* @typedef { Object } MigrationPromise
* @property { string? } version
* @property { boolean } result
* @property { MigrationRecord } migrations
*/
export type MigrationPromise = {
version?: string;
result: boolean;
migrations: MigrationRecord[];
};
export type MySQLMigrationPromise = MigrationPromise & ServicePromiseBits;
/**
* @typedef { Object } MigrationConfiguration
* @property { string } version
* @property { any } databaseProvider
* @property { string? } type
* @property { string? } table
* @property { string? } environment
*/
export type MigratorConfiguration = {
version?: string;
databaseProvider?: any;
type?: string;
table?: string;
environment?: string;
};
/**
* @typedef { Object } MigrationMap
* @property { string } timestamp
* @property { string } name
* @property { string } path
*/
export type MigrationMap = {
timestamp: string;
name: string;
path: string;
};
export type RevertMigrationOptions = {
stepBack?: number;
};
export declare const PARAMATERIZATION: {
TYPE: {
mysql: boolean;
};
LANG: {
javascript: boolean;
};
EXT: {
javascript: string;
};
};
export type MySQLMigratorOptions = NodeKitOptions & RevertMigrationOptions;
/**
* The Migrator Class
*
* The { Migrator } class handles everything that has to do with the migration
* system, including; Setup, Management, and Execution of migrations.
*/
export declare class MysqlMigrator extends MigratorServiceProvider {
/**
* @var { string }
*/
path: string;
/**
* @var { string }
*/
confPath: string;
/**
* @var { string }
*/
file: string;
/**
* @var {string }
*/
version: string;
/**
* @var { string }
*/
table: string;
/**
* @var { Date }
*/
start?: Date;
/**
* @var { Date }
*/
end?: Date;
/**
* @var { Date }
*/
processStart?: Date;
/**
* @var { Date }
*/
processEnd?: Date;
/**
* @var { Configuration }
*/
configuration: Configuration;
/**
* @var { any }
*/
conf: any;
/**
* @var { Configuration }
*/
databaseConfiguration: Configuration;
/**
* @var { any }
*/
databaseConf: any;
/**
* @var { string }
*/
databaseType: string;
/**
* @var
*/
databaseProvider: any;
/**
* @var { DatabaseDriver }
*/
dbo?: DatabaseDriver;
/**
* Class constructor
*/
constructor(handler?: (data: ServiceEventBits) => void, configuration?: MigratorConfiguration);
getServiceProviderSubscriptions(options?: any): ServiceProviderSubscriptions;
getServiceProviderSubscriptionHelpText<T extends ServiceProviderHelpText>(options?: any): T;
/**
* Method to resettle the { NodeKitProjectGeneratorOptions }. Essentially we
* merge NodeKitOptions with FilesystemDescriptor by combining provided
* command options with either a stored configuration or sane default.
*
* @param { NodeKitOptions } options
*
* @returns { NodeKitOptions } The options object, with the configuration partially populated with user-provided information
*/
assembleOptions<T extends MySQLMigratorOptions>(options: NodeKitOptions): Promise<T>;
/**
* A method which asynchronously executes the necessary steps for creating
* a migration within a project file structure
*
* @param { NodeKitOptions } options An object which specifies parameters for this method
*
* @return { Promise<any> }
*/
renderService(options: NodeKitOptions): Promise<any>;
/**
* Checks if the migration system has been installed
*
* @pram { void }
*
* @return { Promise<undefined|null> } A promise with a boolean value indicating whether the migration system is installed.
*/
checkInstall(): Promise<undefined | null>;
/**
* Checks the actual database portion of the migration system is installed
*
* @returns { Promise<undefined } If the check passes
*/
checkDatabaseInstall(): Promise<undefined | null>;
/**
* Checks the actual filesystem portion of the migration system is installed
*
* @returns {Promise<undefined|null>}
*/
checkFilesystemInstall(): Promise<undefined | null>;
/**
* Gets the migration or database configuration
*
* @param { boolean } database True to get the database configuration, false to get the migration configuration
*
* @returns { Configuration } A {@link Configuration} object
*/
getConf(database?: boolean): Promise<any>;
/**
* Get the DBO; If `undefined` then attempt to create it, otherwise return
* the existing dbo or resolve `null` in the event that this method
* fails.
*
* @returns A new {@link DatabaseDriver} object
*/
getDbo(): Promise<DatabaseDriver>;
/**
* Installs the migration system by calling the component install routines
*
* @param { string } content The migration configuration file content
*
* @return { Promise<T> } A promise that indicates the result of installing the migration system
*/
install(content: any): Promise<undefined | null>;
/**
* Handles the migration's filesystem portion of the install
*
* @param { string } content The migration configuration file content
*
* @returns { Promise<undefined> }
*/
installFilesystemComponent(content: any): Promise<undefined>;
/**
* Handles the migration's database portion of the install
*
* @returns { Promise<undefined> }
*/
installDatabaseComponent(): Promise<undefined>;
/**
* Applies or reverts [a] migration(s)
*
* @param options Parameters that shape the migration command
*
* @returns { Promise<MigrationPromise> }
*/
migrate<T extends MigrationPromise>(options: MySQLMigratorOptions): Promise<T>;
getAvailableMigrations(): Promise<any>;
getAppliedMigrations(): Promise<any>;
getWorkingSet(available: any, applied: any, stepBack: number): any[];
/**
* Stages the migration for processing.
*
* Checks if the migration has been queued for processing, and if not - queues it. In
* the event that it has already been queued, we note that whether we are applying or
* reverting the migration.
*
* @param { any } target The target migration
* @param { Number } stepBack The number of migrations to revert
*
* @returns { Promise<undefined> } A promise that resolves undefined
*/
enqueueMigration(target: any, stepBack?: boolean): Promise<undefined>;
/**
* If migrations are being applied, it marks the queued migration as 'applied'. If
* migrations are being reverted, it marks the reverted migration as unapplied.
*
* @param { any } target The target migration
* @param { number } stepBack The number of migrations to revert
*
* @returns { Promise<undefined> } An undefined promise
*/
dequeueMigration(target: any, stepBack?: boolean): Promise<undefined>;
/**
* Prints current process information
*
* @param { string } target The name of the migration
* @param { boolean } stepBack True if the migration is moving backward, false if forward
* @param { boolean } finished True if the process is completed
*/
printProcessInfo(target: string, stepBack?: boolean, finished?: boolean): string;
/**
* Prints current process information
*
* @param { string } target The name of the migration
* @param { boolean } revert True if the migration is moving backward, false if forward
* @param { boolean } finished True if the process is completed
*/
printServiceInfo(emptySet?: boolean, stepBack?: any, processed?: number): string;
}