diff --git a/squeaknode/db/alembic/versions/cd3f18ee33c8_add_unique_constraint_on_payment_hash_.py b/squeaknode/db/alembic/versions/cd3f18ee33c8_add_unique_constraint_on_payment_hash_.py new file mode 100644 index 00000000..f5eed1c8 --- /dev/null +++ b/squeaknode/db/alembic/versions/cd3f18ee33c8_add_unique_constraint_on_payment_hash_.py @@ -0,0 +1,33 @@ +"""Add unique constraint on payment hash of received offer + +Revision ID: cd3f18ee33c8 +Revises: df59995f322c +Create Date: 2021-01-27 17:40:06.995928 + +""" +from alembic import op + + +# revision identifiers, used by Alembic. +revision = 'cd3f18ee33c8' +down_revision = 'df59995f322c' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('received_offer', schema=None) as batch_op: + batch_op.create_unique_constraint( + 'uq_received_offer_payment_hash', ['payment_hash']) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('received_offer', schema=None) as batch_op: + batch_op.drop_constraint( + 'uq_received_offer_payment_hash', type_='unique') + + # ### end Alembic commands ### diff --git a/squeaknode/db/models.py b/squeaknode/db/models.py index 33f2886f..2ec27d47 100644 --- a/squeaknode/db/models.py +++ b/squeaknode/db/models.py @@ -87,7 +87,7 @@ class Models: Column("created", TZDateTime, server_default=func.now(), nullable=False), Column("squeak_hash", String(64), nullable=False), - Column("payment_hash", String(64), nullable=False), + Column("payment_hash", String(64), unique=True, nullable=False), Column("nonce", String(64), nullable=False), Column("payment_point", String(66), nullable=False), Column("invoice_timestamp", Integer, nullable=False),