UNPKG

@iarayan/ch-orm

Version:

A Developer-First ClickHouse ORM with Powerful CLI Tools

78 lines 2.12 kB
import { Schema } from "./Schema"; /** * Abstract base class for database migrations * Provides structure and common functionality for migrations */ export class Migration { /** * Create a new Migration instance * @param connection - ClickHouse connection */ constructor(connection) { /** * Indicates if migration has been applied */ this.applied = false; this.connection = connection; this.schema = new Schema(connection); this.name = this.constructor.name; } /** * Apply the migration * @returns Promise that resolves when the migration is applied */ async apply() { if (this.applied) { throw new Error(`Migration ${this.name} has already been applied`); } try { // Apply the migration await this.up(); // Mark as applied this.applied = true; } catch (error) { throw new Error(`Failed to apply migration ${this.name}: ${error}`); } } /** * Revert the migration * @returns Promise that resolves when the migration is reverted */ async revert() { if (!this.applied) { throw new Error(`Migration ${this.name} has not been applied yet`); } try { // Revert the migration await this.down(); // Mark as not applied this.applied = false; } catch (error) { throw new Error(`Failed to revert migration ${this.name}: ${error}`); } } /** * Get the migration name * @returns Migration name */ getName() { return this.name; } /** * Check if the migration has been applied * @returns True if the migration has been applied, false otherwise */ isApplied() { return this.applied; } /** * Set the applied state of the migration * @param state - Applied state */ setApplied(state) { this.applied = state; } } //# sourceMappingURL=Migration.js.map