import { MigrationStorage } from "./core.mjs";
import { DatabaseError } from "./errors.mjs";
import { Effect } from "effect";
//#region src/db/run-migrations.d.ts
interface Migration {
  idx: number;
  when: number;
  tag: string;
  hash: string;
  sql: string[];
}
/**
 * Minimal structural view of a drizzle PgDatabase — the concrete per-workspace
 * `PgDatabase<PgQueryResultHKT, TSchema>` values satisfy this.
 */
interface MigrationDatabase {
  execute(query: unknown): Promise<unknown>;
  transaction<T>(fn: (tx: {
    execute(query: unknown): Promise<unknown>;
  }) => Promise<T>): Promise<T>;
}
interface LoadedMigrations {
  migrations: Migration[];
  source: "virtual" | "disk";
}
interface DriftReport {
  status: "healthy" | "empty" | "untracked-existing-schema" | "drift-safe-repair" | "drift-manual";
  expectedTables: string[];
  missingTables: string[];
  appliedHashes: number;
  localHashes: number;
  storage: MigrationStorage;
}
interface MigrationReport {
  applied: number;
  total: number;
  storage: MigrationStorage;
  schema: string | undefined;
}
interface RunMigrationsOptions {
  schemaName?: string;
  journal?: MigrationStorage;
  duplicateSqlStates?: readonly string[];
}
interface LoadMigrationsOptions {
  /** Directory containing the workspace's drizzle `migrations/` folder for the disk fallback. */
  fromDir?: string;
  /**
   * Bundler-provided virtual-module loader (e.g. `virtual:drizzle-migrations.sql`
   * registered by rspack). Lives at the call site — the shared package must not
   * name the virtual module, which only exists inside plugin bundles.
   */
  virtual?: () => Promise<{
    default?: Migration[];
  }>;
}
declare function loadMigrations(opts?: LoadMigrationsOptions): Effect.Effect<LoadedMigrations, DatabaseError>;
/**
 * Apply pending migrations to the target database.
 *
 * Namespace model: `opts.schemaName` (`plugin_<slug>`) scopes data tables; the
 * journal lives in `opts.journal` (default the shared `drizzle.__drizzle_migrations`).
 * Undefined `schemaName` means public-schema (api) or dedicated-DB (auth) topology.
 *
 * Concurrency: the run serializes on a journal-scoped Postgres advisory
 * transaction lock, so the dev double-boot (plugin dev-server + the host's
 * in-process load), parallel test files, and overlapping production replicas
 * converge instead of colliding in pg_catalog. SAVEPOINT-based duplicate-DDL
 * tolerance stays as defense-in-depth for non-participants (drizzle-kit).
 *
 * Reliability floor: hash-tracked idempotence with a preflight that records
 * fully-overlapped migrations as applied, everything in one locked
 * transaction, retried on deadlock/serialization/lock-timeout/connection
 * states — a failed attempt rolls back cleanly and re-runs.
 */
declare function runMigrations(db: MigrationDatabase, migrations: Migration[], opts?: RunMigrationsOptions): Effect.Effect<MigrationReport, DatabaseError>;
/**
 * Detect drift between the local migration set and the database journal.
 *
 * Pass an explicit `journal` resolved from the caller's workspace for reliable
 * slug derivation; the default relies on `process.env.npm_package_name`, which is
 * unreliable under bundlers and Module Federation remotes.
 */
declare function detectDrift(db: MigrationDatabase, migrations: Migration[], journal?: MigrationStorage, schemaName?: string): Effect.Effect<DriftReport, DatabaseError>;
//#endregion
export { DriftReport, LoadMigrationsOptions, LoadedMigrations, Migration, MigrationDatabase, MigrationReport, RunMigrationsOptions, detectDrift, loadMigrations, runMigrations };
//# sourceMappingURL=run-migrations.d.mts.map