For agentic workers: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
Goal: Establish versioned database migrations, stable business identifiers, API contract checks and a reusable outbox before adding cross-store features.
Architecture: PostgreSQL stores migration history and transactional outbox records. Domain commands write local state and events in one transaction; independent idempotent consumers update Neo4j, n8n or the knowledge index. OpenAPI route inventory is regenerated in CI and reviewed as a contract diff.
Tech Stack: Flask, SQLAlchemy, PostgreSQL 16, Alembic, pytest, Neo4j, Docker Compose.
Files:
requirements.txtalembic.inimigrations/env.pymigrations/versions/20260716_01_baseline.pyCreate: tests/test_database_migrations.py
[ ] Write a test that creates an empty PostgreSQL test database, runs alembic upgrade head twice and asserts the six current tables plus alembic_version exist.
[ ] Add Alembic and configure env.py to read SQLALCHEMY_DATABASE_URI; never embed credentials.
[ ] Build a stamped baseline that represents current database/*.sql without dropping pre-existing production objects.
[ ] Verify clean install, idempotent re-run and alembic downgrade -1 behavior in a disposable database.
Files:
migrations/versions/20260716_02_governance_uids.pyapp/core/common/identifiers.pyapp/core/business_domain/business_domain.pyapp/core/meta_data/meta_data.pyapp/core/data_flow/dataflows.pyCreate: tests/test_governance_identifiers.py
[ ] Test that new BusinessDomain, DataMeta and DataFlow objects receive UUIDv7-compatible string IDs and retries preserve the same ID.
[ ] Add uid uniqueness constraints/indexes to Neo4j initialization and backfill logic that never uses id(n) as the durable external key.
[ ] Keep legacy numeric IDs readable during migration, but return uid in all new response contracts.
[ ] Add a reconciliation command that reports objects without uid before enforcing required IDs.
Files:
migrations/versions/20260716_03_outbox.pyapp/core/events/outbox.pyapp/core/events/consumer.pyapp/commands/process_outbox.pyCreate: tests/test_outbox.py
[ ] Test atomic command/event persistence, duplicate delivery, retry backoff, dead-letter transition and consumer restart.
[ ] Create outbox_events(event_id UUID, aggregate_type, aggregate_id, event_type, payload JSONB, status, attempts, available_at, published_at, last_error) with unique event_id.
[ ] Implement SELECT ... FOR UPDATE SKIP LOCKED batching and handler idempotency storage.
[ ] Expose backlog, oldest-event age and failed-event counts through internal health data without exposing payload secrets.
Files:
scripts/generate_openapi.pytests/test_architecture_artifacts.py.github/workflows/contracts.ymlModify: docs/architecture/OPENAPI.yaml
[ ] Add a test that regenerates OpenAPI into a temporary path and byte-compares it with the committed contract.
[ ] Fail CI when a Flask route changes without regenerating the contract.
[ ] Add operation-level request/response schemas incrementally, beginning with system auth, workflow versioning and workbench endpoints.
[ ] Require contract review for removed or incompatible operations.
Files:
tests/integration/test_cross_store_consistency.pydeploy/docker/docker-compose.ymlModify: deploy/docker/README.md
[ ] Run integration tests against the local stack with Neo4j/n8n temporarily unavailable after PostgreSQL commit.
[ ] Assert the API reports accepted/processing, the event remains retryable, duplicate delivery causes no duplicate object, and recovery drains the backlog.
[ ] Document operator commands for retry, dead-letter inspection and reconciliation.
[ ] Run the complete test/build/smoke suite before enabling dependent feature plans.