UNPKG

@clickup/pg-mig

Version:

PostgreSQL schema migration tool with microsharding and clustering support

137 lines 4.7 kB
import { Psql } from "./Psql"; /** * A destination database+schema to run the migrations against. */ export declare class Dest { readonly host: string; readonly port: number; readonly user: string; readonly pass: string; readonly db: string; readonly schema: string; private portIsSignificant; private dbIsSignificant; protected constructor(host: string, port: number, user: string, pass: string, db: string, schema?: string); /** * Creates a Dest from a host name, host spec (host:port/db) or DSN URL. */ static create(hostSpecOrDsn: string, defaults: { host?: string; port?: number; user?: string; pass?: string; db?: string; schema?: string; }): Dest; /** * Loads the digests from multiple databases using a custom SQL query runner. * The goal is to load at least one digest successfully from at least one * database. If we can't, then an error is thrown. */ static loadDigests<TDest>(dests: TDest[], sqlRunner: (dest: TDest, sql: string) => Promise<Array<Record<string, string>>>): Promise<string[]>; /** * Saves the digest to all Dests in the list in parallel. If some Dest fail, * it's not a big deal, since in the loading logic, we take care of partial * consensus situation. */ static saveDigests(dests: Dest[], value: { digest: string; } | { reset: "before-undo" | "after-undo"; }): Promise<void>; /** * Check that all dests rerun fingerprint match their expected values, so the * migration can be entirely skipped when there are no new migration versions. */ static checkRerunFingerprint(dests: Dest[], depFiles: string[]): Promise<boolean>; /** * Saves (or resets) rerun fingerprints on all dests. */ static saveRerunFingerprint(dests: Dest[], depFiles: string[], value: "up-to-date" | "reset"): Promise<void>; /** * When rendering the Dest name, we may sometimes omit the port or the db if * they are all the same across all of the Dests. */ setSignificance({ portIsSignificant, dbIsSignificant, }: { portIsSignificant: boolean; dbIsSignificant: boolean; }): this; /** * Returns a Dest switched to a different schema. */ createSchemaDest(schema: string): Dest; /** * Returns a Dest switched to "no current database" mode (allows to e.g. * create databases). */ createNoDBDest(): Dest; /** * Returns a short human-readable representation of the Dest. */ name(short?: "short"): string; /** * Returns host:port/db spec. */ hostSpec(): string; /** * Returns a human-readable representation of the Dest with schema. */ toString(): string; /** * Ensures that the DB exists. If the server can't be connected, retries until * it can be reachable (assuming this method is running in a dev or test * environment). */ createDB(onRetry: (e: string) => void): Promise<"already-exists" | "created">; /** * Runs a migration file for the current schema & DB. * If newVersions is passed, it's applied in the end of the transaction. */ runFile(fileName: string, newVersions: string[] | null, onOut?: (proc: Psql) => void): Promise<Psql>; /** * Returns all the shard-like schemas from the DB. */ loadSchemas(): Promise<string[]>; /** * Given a list of schemas, extracts versions for each schema (which is a list * of migration names). */ loadVersionsBySchema(schemas: string[]): Promise<Map<string, string[]>>; /** * Saves the given digest in a const function. */ private saveDigest; /** * Sets the "rerun fingerprint" for the Dest. Next time we run the migration, * and the fingerprint appear different (e.g. after.sql failed last time, or * the list of schemas in the database changed), then the full migration * sequence will run even if no new versions. */ private saveRerunFingerprint; /** * Loads the previously saved "rerun fingerprint". */ private loadRerunFingerprint; /** * Builds the current "rerun fingerprint" based on the database structure and * dependency files. */ private buildRerunFingerprint; /** * SQL value quoting. */ private escape; /** * SQL identifier quoting. */ private escapeIdent; /** * Queries a 2d table from the DB. */ private query; /** * Same as query(), but queries just the 1st column. */ private queryCol; } //# sourceMappingURL=Dest.d.ts.map