@hirosystems/api-toolkit
Version:
API development toolkit
48 lines (47 loc) • 2.17 kB
TypeScript
import { Logger as PgMigrateLogger, MigrationDirection } from 'node-pg-migrate/dist/types';
import { PgConnectionArgs } from './connection';
export interface MigrationOptions {
/** Bypass the NODE_ENV check when performing a "down" migration which irreversibly drops data. */
dangerousAllowDataLoss?: boolean;
/** Log all applied migrations */
logMigrations?: boolean;
/** Name of the table used for migrations. Defaults to `pgmigrations`. */
migrationsTable?: string;
/** Custom logging configuration */
logger?: PgMigrateLogger;
}
/**
* Run migrations in one direction.
* @param dir - Migrations directory
* @param direction - Migration direction (`'down'` or `'up'`)
* @param connectionArgs - Postgres connection args
* @param opts - Migration options
*/
export declare function runMigrations(dir: string, direction: MigrationDirection, connectionArgs?: PgConnectionArgs, opts?: MigrationOptions): Promise<void>;
/**
* Cycle migrations down and up.
* @param dir - Migrations directory
* @param connectionArgs - Postgres connection args
* @param opts - Migration options
*/
export declare function cycleMigrations(dir: string, connectionArgs?: PgConnectionArgs, opts?: MigrationOptions & {
/** Validates if the database was cleared completely after all `down` migrations are done */
checkForEmptyData?: boolean;
}): Promise<void>;
/**
* Check the `pg_class` table for any data structures contained in the database. We will consider
* any and all results here as "data" contained in the DB, since anything that is not a completely
* empty DB could lead to strange errors when running the API. See:
* https://www.postgresql.org/docs/current/catalog-pg-class.html
* @returns `boolean` if the DB has data
*/
export declare function databaseHasData(connectionArgs?: PgConnectionArgs, opts?: {
ignoreMigrationTables?: boolean;
migrationsTable?: string;
}): Promise<boolean>;
/**
* Drops all tables from the Postgres DB. DANGEROUS!!!
*/
export declare function dangerousDropAllTables(connectionArgs?: PgConnectionArgs, opts?: {
acknowledgePotentialCatastrophicConsequences?: 'yes';
}): Promise<void>;