<R2 = never>(options: Migrator.MigratorOptions<R2>): Effect.Effect<
ReadonlyArray<readonly [id: number, name: string]>,
Migrator.MigrationError | SqlError,
Client.SqlClient | R2
>Runs SQL migrations for a SQLite database using the shared Migrator implementation and the current SqlClient.
export const const run: <R2 = never>(
options: Migrator.MigratorOptions<R2>
) => Effect.Effect<
ReadonlyArray<
readonly [id: number, name: string]
>,
Migrator.MigrationError | SqlError,
Client.SqlClient | R2
>
Runs SQL migrations for a SQLite database using the shared Migrator implementation and the current SqlClient.
run: <function (type parameter) R2 in <R2 = never>(options: Migrator.MigratorOptions<R2>): Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, Client.SqlClient | R2>R2 = never>(
options: Migrator.MigratorOptions<R2>(parameter) options: {
loader: Loader<R>;
schemaDirectory: string;
table: string;
}
options: import MigratorMigrator.interface MigratorOptions<R = never>Options for running SQL migrations, including the migration loader, optional
schema dump directory, and migrations table name.
MigratorOptions<function (type parameter) R2 in <R2 = never>(options: Migrator.MigratorOptions<R2>): Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, Client.SqlClient | R2>R2>
) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<
interface ReadonlyArray<T>ReadonlyArray<readonly [numberid: number, stringname: string]>,
import MigratorMigrator.class MigrationErrorclass MigrationError {
name: string;
message: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
kind: 'BadState' | 'ImportError' | 'Failed' | 'Duplicates' | 'Locked';
}
Error raised while loading, validating, locking, or running SQL migrations.
MigrationError | class SqlErrorclass SqlError {
cause: ConnectionError | AuthenticationError | AuthorizationError | SqlSyntaxError | UniqueViolation | ConstraintError | DeadlockError | SerializationError | LockTimeoutError | StatementTimeoutError | UnknownError;
message: string;
isRetryable: boolean;
_tag: 'SqlError';
reason: ConnectionError | AuthenticationError | AuthorizationError | SqlSyntaxError | UniqueViolation | ConstraintError | DeadlockError | SerializationError | LockTimeoutError | StatementTimeoutError | UnknownError;
name: string;
stack: string;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
Error wrapper for SQL failures whose message, cause, and isRetryable
values are derived from its SqlErrorReason.
SqlError,
import ClientClient.SqlClient | function (type parameter) R2 in <R2 = never>(options: Migrator.MigratorOptions<R2>): Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, Client.SqlClient | R2>R2
> = import MigratorMigrator.const make: <RD = never>({
dumpSchema,
}: {
dumpSchema?: (
path: string,
migrationsTable: string
) => Effect.Effect<
void,
Migrator.MigrationError,
RD
>
}) => <R2 = never>({
loader,
schemaDirectory,
table,
}: Migrator.MigratorOptions<R2>) => Effect.Effect<
ReadonlyArray<
readonly [id: number, name: string]
>,
Migrator.MigrationError | SqlError,
Client.SqlClient | RD | R2
>
Creates a migrator that ensures the migrations table exists, runs pending
migrations in a transaction, and optionally dumps the schema after successful
migrations.
make({
// dumpSchema(path, table) {
// const dump = (args: Array<string>) =>
// Effect.gen(function*() {
// const sql = yield* SqliteClient
// const dump = yield* pipe(
// Command.make("sqlite3", sql.config.filename, ...args),
// Command.string
// )
// return dump.replace(/^create table sqlite_sequence\(.*$/im, "")
// .replace(/\n{2,}/gm, "\n\n")
// .trim()
// }).pipe(
// Effect.mapError((error) => new Migrator.MigrationError({ kind: "Failed", message: error.message }))
// )
//
// const dumpSchema = dump([".schema"])
//
// const dumpMigrations = dump([
// "--cmd",
// `.mode insert ${table}`,
// `select * from ${table}`
// ])
//
// const dumpAll = Effect.map(
// Effect.all([dumpSchema, dumpMigrations], { concurrency: 2 }),
// ([schema, migrations]) => schema + "\n\n" + migrations
// )
//
// const dumpFile = (file: string) =>
// Effect.gen(function*() {
// const fs = yield* FileSystem
// const path = yield* Path
// const dump = yield* dumpAll
// yield* fs.makeDirectory(path.dirname(file), { recursive: true })
// yield* fs.writeFileString(file, dump)
// }).pipe(
// Effect.mapError((error) => new Migrator.MigrationError({ kind: "Failed", message: error.message }))
// )
//
// return dumpFile(path)
// }
})