Migrations for PostgreSQL (Effect's @effect/sql-pg PgMigrator):
Migrator's runner, dumping the schema with pg_dump.
pg_dump connects with the client's own libpq parameters (the URL and
explicit fields, socket, user, database, application_name,
options, TLS, connect timeout); the password goes through
PGPASSWORD and nothing else of the environment but PATH. A dump
that fails is logged, as for every driver.
Re-exports#
- From
pyfect.sql.error:SqlError - From
pyfect.sql.migrator:from_record,Loader,MigrationError - From
pyfect.sql.migrator_file_system:from_file_system
Values#
| Attribute | Type | Description |
|---|---|---|
run | Runner[DumpServices] | Run the new migrations of |
Types#
| Type | Definition | Description |
|---|---|---|
DumpServices | type DumpServices = PgClient | ChildProcessSpawner | FileSystem | Path |
Functions#
dump_schema#
dump_schema(path, table) -> Effect[None, MigrationError, DumpServices]Write the schema and the migrations table's rows to path.
| Parameter | Type | Description |
|---|---|---|
path | str | |
table | str |
Returns Effect[None, MigrationError, DumpServices]
def dump_schema(path: str, table: str) -> Effect[None, MigrationError, DumpServices]:
"""Write the schema and the migrations table's rows to ``path``."""
def body():
fs = yield from FileSystem()
paths = yield from Path()
dump = yield from _dump_all(table)
yield from fs.make_directory(paths.dirname(path), recursive=True)
yield from fs.write_file_string(path, dump)
def failed(error: Exception) -> Effect[Never, MigrationError]:
message = getattr(error, "message", None) or str(error)
return fail(MigrationError(kind="Failed", message=str(message), cause=error))
written: Effect[None, Exception, DumpServices] = gen(body)
return written.catch_all(failed)layer#
layer[R = Never](*, loader, schema_directory=None, table='effect_sql_migrations') -> Layer[Never, MigrationError | SqlError, SqlClient | DumpServices | R]Runs the migrations when built.
| Parameter | Type | Description |
|---|---|---|
loader | Loader[R] | |
schema_directory | str | None = None | |
table | str = 'effect_sql_migrations' |
Returns Layer[Never, MigrationError | SqlError, SqlClient | DumpServices | R]
def layer[R = Never](
*,
loader: Loader[R],
schema_directory: str | None = None,
table: str = "effect_sql_migrations",
) -> Layer[Never, MigrationError | SqlError, SqlClient | DumpServices | R]:
"""Runs the migrations when built."""
return layer_effect_discard(run(loader=loader, schema_directory=schema_directory, table=table))