loom.core.repository.sqlalchemy.migrations.operations

Alembic operations for the guard, so generated revisions carry calls and never SQL.

A revision reads op.protect_scoped_table("notes", scopes, privileges); the implementation executes a constant statement with bound parameters. The schema is the one the runner configured as the version table schema.

Functions

_call_guard(bind, schema, op)

_call_partitions(bind, schema, op)

_detached(bind, schema, op)

run_guard_operation(operations, op)

Run one guard operation with the guard resolved before the application schema.

Classes

GuardOperations(*args, **kwargs)

The part of Alembic's Operations a guard operation needs.

HandWrittenProtectOp(*args, **kwargs)

Stop a downgrade where only the developer knows the scopes of the target revision.

_Bind(*args, **kwargs)

_Context(*args, **kwargs)

class loom.core.repository.sqlalchemy.migrations.operations.OpenHatchOp(*args, **kwargs)

Bases: MigrateOperation

Open the guard’s hatch for the rest of the revision’s transaction.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

class loom.core.repository.sqlalchemy.migrations.operations.ProtectScopedTableOp(*args, **kwargs)

Bases: MigrateOperation

Protect a scoped table of the application schema.

Parameters:
  • table (str)

  • scopes (Sequence[dict[str, Any]])

  • privileges (Sequence[str])

class loom.core.repository.sqlalchemy.migrations.operations.UnprotectScopedTableOp(*args, **kwargs)

Bases: MigrateOperation

Unprotect a scoped table of the application schema; needs the open hatch.

Parameters:
  • table (str)

  • scopes (Sequence[dict[str, Any]])

  • privileges (Sequence[str])

class loom.core.repository.sqlalchemy.migrations.operations.GrantTableOp(*args, **kwargs)

Bases: MigrateOperation

Grant the declared privileges of an unscoped table to the schema’s groups.

Parameters:
  • table (str)

  • readers (Sequence[str])

  • writers (Sequence[str])

class loom.core.repository.sqlalchemy.migrations.operations.EnsureRangePartitionsOp(*args, **kwargs)

Bases: MigrateOperation

Create the missing partitions of a range-partitioned scoped table covering [start, end).

The guard creates, registers and protects each partition in the revision’s transaction; one that already exists is left alone.

Parameters:
  • table (str)

  • start (dt.date | str)

  • end (dt.date | str)

  • interval (Interval)

class loom.core.repository.sqlalchemy.migrations.operations.DetachRangePartitionsOp(*args, **kwargs)

Bases: MigrateOperation

Unprotect and detach, and with drop drop, the partitions covering [start, end).

Parameters:
  • table (str)

  • start (dt.date | str)

  • end (dt.date | str)

  • interval (Interval)

  • drop (bool)

class loom.core.repository.sqlalchemy.migrations.operations.DropPartitionsOp(*args, **kwargs)

Bases: MigrateOperation

Unprotect, detach and drop every partition of a table, before the table is dropped.

Parameters:

table (str)

class loom.core.repository.sqlalchemy.migrations.operations.HandWrittenProtectOp(*args, **kwargs)[source]

Bases: MigrateOperation

Stop a downgrade where only the developer knows the scopes of the target revision.

Parameters:

table (str)

class loom.core.repository.sqlalchemy.migrations.operations.GuardOperations(*args, **kwargs)[source]

Bases: Protocol

The part of Alembic’s Operations a guard operation needs.

loom.core.repository.sqlalchemy.migrations.operations.run_guard_operation(operations, op)[source]

Run one guard operation with the guard resolved before the application schema.

The guard name comes from run_migrations; outside it the operation is refused, so a revision can never reach a routine the application schema shadows.

Parameters:
Return type:

None