diff --git a/tansu/alembic/versions/2024_08_09-fcd0be8495da_unique_constraints.py b/tansu/alembic/versions/2024_08_09-fcd0be8495da_unique_constraints.py new file mode 100644 index 0000000..95ab3df --- /dev/null +++ b/tansu/alembic/versions/2024_08_09-fcd0be8495da_unique_constraints.py @@ -0,0 +1,31 @@ +"""Unique constraints + +Revision ID: fcd0be8495da +Revises: 1f84e2b6843a +Create Date: 2024-08-09 19:34:02.104464+00:00 + +""" + +from typing import Sequence, Union + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "fcd0be8495da" +down_revision: Union[str, None] = "1f84e2b6843a" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_unique_constraint( + "_action_project_key_value", "event", ["action", "project_key", "value"] + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint("_action_project_key_value", "event", type_="unique") + # ### end Alembic commands ### diff --git a/tansu/soroban_versioning_events.py b/tansu/soroban_versioning_events.py index f197573..467dbac 100644 --- a/tansu/soroban_versioning_events.py +++ b/tansu/soroban_versioning_events.py @@ -2,7 +2,7 @@ from tansu.events.ingest import events_to_db, fetch_events -contract_id = "CC3JCYWHNMPMQTOQUNDCJSCFSWRFZIE2JVSAUEXEG56DMKOMI3RL7VOH" +contract_id = "CAP52ERGUZ65UNPHP36CQBHYUPEUG2TT4NPVEV7CREWRT7UCPD7PRWEE" start_ledger = None events, _ = fetch_events(contract_id=contract_id, start_ledger=start_ledger) diff --git a/tansu/src/tansu/events/database/db_models.py b/tansu/src/tansu/events/database/db_models.py index 24eb570..d48e400 100644 --- a/tansu/src/tansu/events/database/db_models.py +++ b/tansu/src/tansu/events/database/db_models.py @@ -1,4 +1,4 @@ -from sqlalchemy import orm +from sqlalchemy import orm, UniqueConstraint from tansu.events.database.session_factory import SqlAlchemyBase @@ -12,6 +12,12 @@ class Event(SqlAlchemyBase): project_key: orm.Mapped[str] = orm.mapped_column(index=True) value: orm.Mapped[str] + __table_args__ = ( + UniqueConstraint( + "action", "project_key", "value", name="_action_project_key_value" + ), + ) + class LatestLedger(SqlAlchemyBase): __tablename__ = "latest_ledger"