Skip to content

feat(db): add monthly event partitions#363

Merged
KurodaKayn merged 6 commits into
mainfrom
feat/monthly-event-partitions
Jun 22, 2026
Merged

feat(db): add monthly event partitions#363
KurodaKayn merged 6 commits into
mainfrom
feat/monthly-event-partitions

Conversation

@KurodaKayn

Copy link
Copy Markdown
Owner

Change Description

  • Add PostgreSQL monthly partition setup for publish, extension execution, project activity, and workspace activity event tables.
  • Make those append-only tables use (id, created_at) primary keys so the schema is compatible with created_at range partitioning.
  • Update the database optimization plan to mark the Phase 4 event/activity monthly partitioning item complete.

Implementation Approach

  • Create partition parent tables and rolling monthly partitions during PostgreSQL schema initialization before GORM AutoMigrate runs.
  • Preserve extension callback idempotency without a global event_id unique constraint by serializing duplicate checks with a PostgreSQL advisory transaction lock.
  • Mirror the partition-compatible key shape in SQLite testsupport and add schema-level regression coverage.

Testing

  • go test ./... from backend passed.
  • bash script/ci/backend.sh passed.
  • Pre-commit backend-format and backend-lint passed for each commit.

Event and activity tables need a partition-compatible target schema before Phase 4 can move beyond row-level archiving.

Create PostgreSQL monthly partition parents and rolling partitions for publish, extension, project activity, and workspace activity events.

Event tables now use created_at-aware primary keys, and extension callback deduplication stays serialized without relying on a global unique event id.
The partitioned event schema changes the primary key shape for append-only event and activity tables.

Add schema assertions for the created_at-aware keys and mirror that shape in the SQLite service test fixture.

Tests now catch regressions that would make the monthly partition DDL incompatible with the Go models.
The database optimization plan should reflect the completed monthly partitioning slice for event and activity tables.

Mark the Phase 4 checklist item complete and add the new schema and test files as verification entry points.

The roadmap now shows the remaining Phase 4 work around browser sessions, collaboration batches, cold export, and recovery.
Review found that monthly partitions could age out in long-lived processes and extension event deduplication was no longer a durable database invariant.

Add default partitions for event tables and introduce an unpartitioned extension event claim table keyed by event id.

Future-dated event inserts now have a partition fallback, and duplicate extension callbacks are blocked consistently across database backends.
Duplicate extension callbacks need idempotent claim handling on PostgreSQL without aborting the transaction.

Schema sync now backfills extension event claims and drains default rows into real monthly partitions.

Existing callbacks stay deduplicated and future partition maintenance preserves pruning.
Archived extension events leave durable callback claims behind after the event rows are removed.

The archive delete phase now runs an optional hook and removes claims for archived extension event IDs in the same transaction.

Old claims stop blocking reused event IDs while hot event claims remain intact.
@KurodaKayn KurodaKayn merged commit dddc3bd into main Jun 22, 2026
14 checks passed
@KurodaKayn KurodaKayn deleted the feat/monthly-event-partitions branch June 22, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant