Make events PK composite (id, ingested_at) for TimescaleDB hypertable partitioning requirement
Some checks failed
build-and-deploy / build (push) Failing after 15s

This commit is contained in:
sirius0xdev 2026-07-07 18:29:50 -04:00
parent f7de9555a9
commit 49d5756ceb
No known key found for this signature in database

View file

@ -38,9 +38,11 @@ def upgrade() -> None:
) )
# events (will become hypertable) # events (will become hypertable)
# NOTE: TimescaleDB requires the partitioning column (ingested_at) to be
# part of the primary key / any unique index, so the PK is composite.
op.create_table( op.create_table(
'events', 'events',
sa.Column('id', UUID(as_uuid=True), primary_key=True), sa.Column('id', UUID(as_uuid=True), nullable=False),
sa.Column('source_type', sa.Enum('rss', 'gdel-t2', 'social', 'earthquake', 'disaster', 'weather', 'fire', 'satellite', name='event_source_type'), nullable=False, index=True), sa.Column('source_type', sa.Enum('rss', 'gdel-t2', 'social', 'earthquake', 'disaster', 'weather', 'fire', 'satellite', name='event_source_type'), nullable=False, index=True),
sa.Column('source_id', UUID(as_uuid=True)), sa.Column('source_id', UUID(as_uuid=True)),
sa.Column('title', sa.Text()), sa.Column('title', sa.Text()),
@ -57,6 +59,7 @@ def upgrade() -> None:
sa.Column('ingested_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False), sa.Column('ingested_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column('source_timestamp', sa.DateTime(timezone=True), nullable=False), sa.Column('source_timestamp', sa.DateTime(timezone=True), nullable=False),
sa.Column('search_vector', TSVECTOR), sa.Column('search_vector', TSVECTOR),
sa.PrimaryKeyConstraint('id', 'ingested_at'),
) )
# Convert events to TimescaleDB hypertable # Convert events to TimescaleDB hypertable