import Immutable from "immutable"; import { NonEmptyObject, Primitive } from "ts-essentials"; import { DriverInfo } from "../db/driver.js"; import { SqlColumn, SqlNode, SqlType } from "../db/sql.js"; import { Model } from "../model/model.js"; import { Logger } from "../utils/logging.js"; import { Verse } from "../verse.js"; export interface Migration { (db: DB): void; } export type DefaultOptions = { value: Primitive; } | { sql: string; }; export type ColumnOptions = { nullable?: boolean; identity?: boolean; default?: DefaultOptions; }; export declare function column(type: SqlType, options?: ColumnOptions): (name: string) => SqlColumn; type Literal = Primitive | Date; export type ForeignKey = { table?: string | undefined; columns: keyof T | readonly (keyof T)[]; target: string; references: string | readonly string[]; }; export type TableOptions = { key?: keyof T | readonly (keyof T)[]; foreignKeys?: ForeignKey | readonly ForeignKey[] | undefined; }; export declare class DB { #private; readonly info: DriverInfo; constructor(info: DriverInfo, model: Model); get ops(): Immutable.List; createTable SqlColumn; }>(name: string, columns: NonEmptyObject, options?: TableOptions): void; dropTable(name: string): void; addPrimaryKey(table: string, ...columns: readonly string[]): void; addForeignKey(table: string, columns: string | readonly string[], references: string, referencedColumns: string | readonly string[]): void; renameTable(oldName: string, newName: string): void; addColumn(table: string, name: string, type: SqlType, options?: ColumnOptions): void; alterColumn(table: string, name: string, options: { type?: SqlType | undefined; } & ColumnOptions): void; dropColumn(table: string, name: string): void; renameColumn(table: string, oldName: string, newName: string): void; createIndex(name: string, table: string, ...columns: readonly string[]): void; dropIndex(table: string, name: string): void; createSequence(name: string, start?: number, increment?: number): void; dropSequence(name: string): void; insert(table: string, columns: readonly string[], ...rows: readonly Literal[][]): void; update(table: string, assignments: { [column: string]: Literal; }, where: { [column: string]: Literal; }): void; delete(table: string, where: { [column: string]: Literal; }): void; sql(sql: string): void; } export type MigrationInfo = { id: string; name: string; file: string; applied: boolean; }; export type MigrationStatus = { database: string; databaseExists: boolean; directory: string; directoryExists: boolean; tableExists: boolean; migrations: readonly MigrationInfo[]; }; export declare class Migrator { #private; static readonly MIGRATIONS_TABLE = "__verse_migrations"; constructor(userVerse: Verse, directory?: string, logger?: Logger); create(name: string): Promise; status(): Promise; migrate(onApplied?: (migration: MigrationInfo) => void): Promise; script(header?: boolean): Promise; } export {};