@clickup/pg-mig
Version:
PostgreSQL schema migration tool with microsharding and clustering support
89 lines • 3.08 kB
TypeScript
/**
* Options for the migrate() function.
*/
export interface MigrateOptions {
/** The directory the migration versions are loaded from. */
migDir: string;
/** List of PostgreSQL master hostnames or DSNs in the format:
* "host[:port][/database]" or
* "postgres://[user][:password][@]host[:port][/database]". The migration
* versions in `migDir` will be applied to all of them. */
hosts: string[];
/** PostgreSQL port on each hosts. */
port?: number;
/** PostgreSQL user on each host. */
user?: string;
/** PostgreSQL password on each host. */
pass?: string;
/** PostgreSQL database name on each host. */
db?: string;
/** If true, tries to create the given database. This is helpful when running
* the tool on a developer's machine. */
createDB?: boolean;
/** How many schemas to process in parallel (defaults to 10). */
parallelism?: number;
/** If true, prints what it plans to do, but doesn't change anything. */
dry?: boolean;
/** If true, runs before/after files on apply even if nothing is changed. */
force?: boolean;
/** SQL query returning the list of valid shard schemas. Shard schemas absent
* from the result are skipped; non-shard schemas (e.g. "public") are always
* migrated regardless. */
validShardSchemasSql?: string;
/** What to do. */
action: {
type: "make";
name: string;
} | {
type: "chain";
} | {
type: "list";
} | {
type: "list-db";
} | {
type: "digest";
} | {
type: "undo";
version: string;
} | {
type: "apply";
after?: Array<() => void | Promise<void>>;
};
}
/**
* CLI tool entry point. This function is run when `pg-mig` is called from the
* command line. Accepts parameters from process.argv. See `migrate()` for
* option names.
*
* If no options are passed, uses `PGHOST`, `PGPORT`, `PGUSER`, `PGPASSWORD`,
* `PGDATABASE` environment variables which are standard for e.g. `psql`.
*
* You can pass multiple hosts separated by comma or semicolon.
*
* Examples:
* ```
* pg-mig --make=my-migration-name@sh
* pg-mig --make=other-migration-name@sh0000
* pg-mig --undo=20191107201239.my-migration-name.sh
* pg-mig --list
* pg-mig --list=db
* pg-mig --list=digest
* pg-mig
* ```
*/
export declare function main(argsIn: string[]): Promise<boolean>;
/**
* Similar to main(), but accepts options explicitly, not from process.argv.
* This function is meant to be called from other tools.
*/
export declare function migrate(options: MigrateOptions): Promise<boolean>;
/**
* Loads the digest strings from the provided databases and chooses the one
* which reflects the database schema status the best.
*/
export declare function loadDBDigest<TDest>(dests: TDest[], sqlRunner: (dest: TDest, sql: string) => Promise<Array<Record<string, string>>>): Promise<string>;
/**
* A wrapper around main() to call it from a bin script.
*/
export declare function cli(): void;
//# sourceMappingURL=cli.d.ts.map