@adonisjs/lucid
Version:
SQL ORM built on top of Active Record pattern
75 lines (74 loc) • 3.18 kB
TypeScript
import { type SpawnOptions } from 'node:child_process';
import { type ConnectionConfig, type QueryClientContract } from '../../types/database.js';
/**
* Contract implemented by dialect-specific schema dump handlers.
*/
export interface SchemaStateContract {
dump(path: string): Promise<void>;
load(path: string): Promise<void>;
}
/**
* Base implementation shared across all dialects. Dialect-specific classes are
* only responsible for producing the structural SQL dump. This class appends
* Lucid migration metadata afterwards.
*/
export declare abstract class BaseSchemaState implements SchemaStateContract {
protected client: QueryClientContract;
protected connectionConfig: ConnectionConfig;
protected schemaTableName: string;
protected schemaVersionsTableName: string;
constructor(client: QueryClientContract, connectionConfig: ConnectionConfig, schemaTableName: string, schemaVersionsTableName: string);
/**
* Dump the structural schema first and then append migrations metadata.
*/
dump(path: string): Promise<void>;
/**
* Dialects must implement schema restore explicitly. Throwing here prevents
* partial support from failing silently.
*/
load(_path: string): Promise<void>;
/**
* Dump the dialect-specific structural schema to the provided path.
*/
protected abstract dumpSchema(path: string): Promise<void>;
/**
* Export rows from Lucid's schema bookkeeping tables as `INSERT` statements.
*/
protected dumpMigrationMetadata(): Promise<string>;
/**
* Stringify an insert statement using the active dialect query builder, so
* values are escaped consistently with the current client.
*/
protected stringifyInsert(tableName: string, row: Record<string, any>): string;
/**
* Helper to write a fully materialized dump to disk.
*/
protected writeContents(path: string, contents: string): Promise<void>;
/**
* Collect stdout and stderr emitted by a child process. Individual helpers can
* then decide which stream should be surfaced in case of failure.
*/
private collectProcessOutput;
/**
* Wait for a spawned process to exit. Spawning failures reject immediately
* through the `error` event.
*/
private waitForProcessExit;
/**
* Create a user-facing process error, preferring stderr and then stdout for
* tools that only report actionable details through standard output.
*/
private createCommandError;
/**
* Stream CLI output directly to disk to avoid buffering large dumps in memory.
*/
protected spawnToFile(command: string, args: string[], outputPath: string, options?: Omit<SpawnOptions, 'stdio'>): Promise<void>;
/**
* Stream a SQL file to a CLI process using stdin.
*/
protected spawnFromFile(command: string, args: string[], inputPath: string, options?: Omit<SpawnOptions, 'stdio'>): Promise<void>;
/**
* Execute a CLI command and collect its output for actionable failures.
*/
protected spawnCommand(command: string, args: string[], options?: Omit<SpawnOptions, 'stdio'>): Promise<string>;
}