@gati-framework/runtime
Version:
Gati runtime execution engine for running handler-based applications
139 lines • 3.99 kB
TypeScript
import type { TSV } from './types.js';
export interface DBSchemaMetadata {
version: string;
migrations: string[];
rollback: string[];
compatibleWith?: string[];
}
export interface DBSchemaVersion {
schemaVersion: string;
tsv: TSV;
handlerPath: string;
appliedAt?: number;
rolledBackAt?: number;
status: 'pending' | 'applied' | 'rolled_back' | 'failed';
error?: string;
}
export interface MigrationResult {
success: boolean;
schemaVersion: string;
executedMigrations: string[];
error?: string;
duration: number;
}
export interface RollbackResult {
success: boolean;
schemaVersion: string;
executedRollbacks: string[];
error?: string;
duration: number;
}
export interface DBSchemaManagerConfig {
/**
* Function to execute a migration script
* Should return true if successful, false otherwise
*/
executeMigration: (script: string) => Promise<boolean>;
/**
* Function to execute a rollback script
* Should return true if successful, false otherwise
*/
executeRollback: (script: string) => Promise<boolean>;
/**
* Optional callback when schema is applied
*/
onSchemaApplied?: (schemaVersion: string, tsv: TSV) => void;
/**
* Optional callback when schema is rolled back
*/
onSchemaRolledBack?: (schemaVersion: string, tsv: TSV) => void;
/**
* Whether to run migrations in a transaction (if supported)
*/
useTransaction?: boolean;
/**
* Timeout for migration execution (ms)
*/
migrationTimeout?: number;
}
/**
* Manages database schema versions alongside TSV versions
*/
export declare class DBSchemaManager {
private schemas;
private activeSchemas;
private schemaUsage;
private config;
constructor(config: DBSchemaManagerConfig);
/**
* Register a schema version from TSV metadata
*/
registerSchema(tsv: TSV, handlerPath: string, schemaMetadata: DBSchemaMetadata): void;
/**
* Apply migrations for a schema version
*/
applyMigrations(schemaVersion: string, metadata: DBSchemaMetadata): Promise<MigrationResult>;
/**
* Rollback a schema version
*/
rollbackSchema(schemaVersion: string, metadata: DBSchemaMetadata): Promise<RollbackResult>;
/**
* Check if a schema is active
*/
isSchemaActive(schemaVersion: string): boolean;
/**
* Check if a schema is used by other versions
*/
isSchemaUsedByOthers(schemaVersion: string, excludeTsv?: TSV): boolean;
/**
* Get all TSVs using a schema version
*/
getSchemaUsage(schemaVersion: string): TSV[];
/**
* Activate a version (apply schema if needed)
*/
activateVersion(tsv: TSV, handlerPath: string, schemaMetadata?: DBSchemaMetadata): Promise<MigrationResult | null>;
/**
* Deactivate a version (rollback schema if no other versions use it)
*/
deactivateVersion(tsv: TSV, schemaMetadata?: DBSchemaMetadata): Promise<RollbackResult | null>;
/**
* Get schema status
*/
getSchemaStatus(schemaVersion: string): DBSchemaVersion | undefined;
/**
* Get all active schemas
*/
getActiveSchemas(): string[];
/**
* Get all schemas
*/
getAllSchemas(): DBSchemaVersion[];
/**
* Check if schemas are compatible
*/
areCompatible(schema1: string, schema2: string, metadata: DBSchemaMetadata): boolean;
/**
* Get statistics
*/
getStatistics(): {
totalSchemas: number;
activeSchemas: number;
pendingSchemas: number;
failedSchemas: number;
rolledBackSchemas: number;
};
/**
* Clear all schemas (for testing)
*/
clear(): void;
/**
* Execute migration with timeout
*/
private executeMigrationWithTimeout;
/**
* Execute rollback with timeout
*/
private executeRollbackWithTimeout;
}
//# sourceMappingURL=db-schema.d.ts.map