Skip to content

Commit

Permalink
Add unique contraints
Browse files Browse the repository at this point in the history
  • Loading branch information
tupui committed Aug 9, 2024
1 parent c4fd48f commit f6e2c52
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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 ###
2 changes: 1 addition & 1 deletion tansu/soroban_versioning_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion tansu/src/tansu/events/database/db_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy import orm
from sqlalchemy import orm, UniqueConstraint

from tansu.events.database.session_factory import SqlAlchemyBase

Expand All @@ -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"
Expand Down

0 comments on commit f6e2c52

Please sign in to comment.