|
1 | 1 | # pg-partsmith 1.0 — API cheat sheet (what changed from 0.5, for porting tests and docs) |
2 | 2 |
|
3 | | -Source of truth is the code; this page is the map. |
| 3 | +Source of truth is the code; this page is the map. Two entries were superseded in 1.1 — |
| 4 | +the hook signatures and the executor's single-partition entry points — and say so where |
| 5 | +they stand; the [changelog](../changelog.md) has that migration. |
4 | 6 |
|
5 | 7 | ## Pure core (shared by aio and sync) |
6 | 8 |
|
@@ -44,15 +46,15 @@ TablePartitionConfig(table_name="regions", scheme=ListPartitioning(key="region", |
44 | 46 |
|
45 | 47 | Service wiring: `PartitionLifecycleService(repo, metadata, locks, hooks=None)` — **no `period_calculator` argument**; the calculator/tz/codec live in `TimeBoundaries`. `PostgresMetadataProvider(engine, marker_prefix=, boundary_codec=, ddl_timezone=)` (codec only for `is_partition_closed`). |
46 | 48 |
|
47 | | -Service methods: `inspect(config) -> ActualTree | None`, `plan(config, *, mode=, now=, windows=) -> MaintenancePlan` (no lock, no DDL), `apply(config, plan, *, continue_on_error=) -> MaintenanceResult` (lock), `maintain(config, *, skip_create, skip_detach, skip_drop, continue_on_error)` (= `maintain_lifecycle`, lock; plan + apply), `reconcile(config)`, `ensure_partition(config, period|Window) -> PartitionInfo | None`, `ensure_partitions(config, periods) -> list[PartitionInfo]`, granular `create_future_partitions(config)`, `get_partitions_for_pruning(config)`, `detach_old_partitions(table, partitions)`, `drop_detached_partitions(table, names)`; movers `partition_data(config, *, batch_rows, max_batches) -> MigrationResult` and `unpartition(config, into, *, batch_rows, max_batches, drop_emptied)` (both take the lock). |
| 49 | +Service methods: `inspect(config) -> ActualTree | None`, `plan(config, *, mode=, now=, windows=) -> MaintenancePlan` (no lock, no DDL), `apply(config, plan, *, continue_on_error=) -> MaintenanceResult` (lock), `maintain(config, *, skip_create, skip_detach, skip_drop, continue_on_error)` (= `maintain_lifecycle`, lock; plan + apply), `reconcile(config)`, `ensure_partition(config, period|Window) -> PartitionInfo | None`, `ensure_partitions(config, periods) -> list[PartitionInfo]`, granular `create_future_partitions(config)`, `get_partitions_for_pruning(config)`, `detach_old_partitions(config, partitions)`, `drop_detached_partitions(config, names)` (both took the parent's name until 1.1); movers `partition_data(config, *, batch_rows, max_batches) -> MigrationResult` and `unpartition(config, into, *, batch_rows, max_batches, drop_emptied)` (both take the lock). |
48 | 50 |
|
49 | | -Executor (`aio/services/execution.py` `PlanExecutor(repo, metadata, hooks)`): `apply(config, plan, continue_on_error)`, extension points `create_partition(config, plan, op, *, issues, fill=None) -> bool`, `detach_single_partition(table_name, DetachPartition)`, `drop_single_partition(table_name, DropPartition)`. Mover (`services/migration.py` `DataMover(repo, metadata, executor)`). Inspector (`services/inspection.py` `PartitionInspector(metadata)`): `inspect(config, measure=)`, `context(config, now=, mode=, explicit_windows=)`. Validation unchanged in spirit (`PartitionValidationService(metadata).validate_config(config)`). |
| 51 | +Executor (`aio/services/execution.py` `PlanExecutor(repo, metadata, hooks)`): `apply(config, plan, continue_on_error)`, extension points `create_partition(config, plan, op, *, issues, fill=None) -> bool`, `detach_single_partition(config, DetachPartition)`, `drop_single_partition(config, DropPartition)` (both took the parent's name until 1.1). Mover (`services/migration.py` `DataMover(repo, metadata, executor)`). Inspector (`services/inspection.py` `PartitionInspector(metadata)`): `inspect(config, measure=)`, `context(config, now=, mode=, explicit_windows=)`. Validation unchanged in spirit (`PartitionValidationService(metadata).validate_config(config)`). |
50 | 52 |
|
51 | 53 | Repository protocol (`PartitionRepository`): `create_table_like(template_name, table_name, partition_by: PartitionBy | None, *, physical: LocalLeaves | None = None)`, `create_foreign_table_like(template_name, table_name, *, server, options)`, `move_rows(source, target, *, limit=None) -> int`, `attach_partition(parent, partition, bounds: PartitionBounds, *, key_arity=1)`, `detach_partition(parent, partition, *, mode=DetachMode.AUTO)`, `drop_partition(partition, *, expected_oid=None)`, `adopt_partition(table, partition) -> bool`, `reconcile_default_rows(*, default_partition_name, target_partition_name, key_columns, from_value, to_value, limit=None) -> int`. Old `create_partition/create_branch/create_subpartition_table/attach_subpartition/attach_composite_partition` are gone. |
52 | 54 |
|
53 | 55 | Metadata protocol (`PartitionMetadataProvider`): `get_partition_type`, `get_partition_columns`, `get_actual_tree(table) -> ActualTree | None`, `measure(tree, *, targets, facts, sql_predicates) -> ActualTree`, `get_partition_tree(name) -> PartitionNode | None`, `get_default_partition`, `partition_exists`, `is_partition_attached`, `get_relation_oid(name)`, `get_unique_constraint_columns`, `get_key_high_water_mark(table, column, *, sequence=False)`, `get_leading_key_minimum(table, key_columns)`, `list_partitions`. Plus on the Postgres implementation: `get_partition_column` (single-column only), `get_partition_boundaries`, `is_partition_closed`, `evaluate_sql_predicate`. |
54 | 56 |
|
55 | | -Hooks: `before_create(config, partition: PartitionInfo)` (was `(config, name, from_value, to_value)`); the other five unchanged. Hooks fire for partitions directly under the root only (lifecycle units / root set members), never per leaf of a subtree. |
| 57 | +Hooks: in 1.0 `before_create(config, partition: PartitionInfo)` (was `(config, name, from_value, to_value)`) and the other five unchanged. **Superseded in 1.1**: every method takes one `PartitionEvent`, and there are eight phases plus `on_event` — see the changelog. Hooks fire for partitions directly under the root only (lifecycle units / root set members), never per leaf of a subtree. |
56 | 58 |
|
57 | 59 | Semantics to test: attach-last subtree creation; a converged tree costs zero DDL; ownership by alignment (an attached partition whose bounds are not on the scheme's grid is `UNMANAGED_PARTITION` INFO and never touched; a finer-than-grid one is managed); orphan `COMMENT` marker line 1 unchanged, line 2 `pg-partsmith:detached-at=<iso>`; `DropAfter(grace)` keeps orphans until `detached_at + grace`, unknown instant = eligible; `DropNever` leaves detached tables alone; drops revalidate OID (`PlanStaleError` on a recreated table, recorded as an issue with `continue_on_error`, otherwise raised); detach revalidates OID and attachment; topology conflicts at apply time (`PartitionTopologyError`, e.g. DEFAULT holding rows for a hash bucket) are recorded as issues and never abort; other errors abort unless `continue_on_error`. |
58 | 60 |
|
|
0 commit comments