Skip to content

Migrator

9 exports Added in v1.0.0 Source

Constructor

make

Added in v1.0.0 Source

Signature

declare function make<RD = never>(__namedParameters: {
  dumpSchema?: (path: string, migrationsTable: string) => Effect<void, MigrationError, RD>;
}): <R2 = never>(__namedParameters: MigratorOptions<R2>) => Effect<readonly Array<readonly [number, string]>, MigrationError | SqlError, SqlClient | RD | R2>

Errors

Signature

declare class MigrationError extends YieldableError<this> & {
  readonly _tag: "MigrationError";
} & Readonly<{
  readonly _tag: "MigrationError";
  readonly cause?: unknown;
  readonly message: string;
  readonly reason: "bad-state" | "import-error" | "failed" | "duplicates" | "locked";
}> {
  constructor(args: {
    readonly cause?: unknown;
    readonly message: string;
    readonly reason: "bad-state" | "import-error" | "failed" | "duplicates" | "locked";
  });
}

Loaders

Signature

declare function fromBabelGlob(migrations: Record<string, any>): Loader;

fromGlob

Added in v1.0.0 Source

Signature

declare function fromGlob(migrations: Record<string, () => Promise<any>>): Loader;

fromRecord

Added in v1.0.0 Source

Signature

declare function fromRecord(
  migrations: Record<string, Effect.Effect<void, unknown, Client.SqlClient>>,
): Loader;

Model

Loader type

Added in v1.0.0 Source

Signature

type Loader<R = never> = Effect.Effect<ReadonlyArray<ResolvedMigration>, MigrationError, R>;

Migration interface

Added in v1.0.0 Source

Signature

interface Migration {
  readonly createdAt: Date;
  readonly id: number;
  readonly name: string;
}

MigratorOptions interface

Added in v1.0.0 Source

Signature

interface MigratorOptions<R = never> {
  readonly loader: Loader<R>;
  readonly schemaDirectory?: string;
  readonly table?: string;
}

ResolvedMigration type

Added in v1.0.0 Source

Signature

type ResolvedMigration = readonly [
  id: number,
  name: string,
  load: Effect.Effect<any, any, Client.SqlClient>,
];