Add composite contraint of squeak hash and client addr in sent offers table (#736)

This commit is contained in:
Jonathan Zernik 2021-01-28 18:23:03 -08:00 committed by GitHub
parent 2cab41edff
commit e59a68b0a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View file

@ -0,0 +1,33 @@
"""Add composite unique constraint on squeak hash and client addr of sent offer
Revision ID: d5a06570ed3e
Revises: cd3f18ee33c8
Create Date: 2021-01-28 17:49:17.615748
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = 'd5a06570ed3e'
down_revision = 'cd3f18ee33c8'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('sent_offer', schema=None) as batch_op:
batch_op.create_unique_constraint('uq_sent_offer_squeak_hash_client_addr', [
'squeak_hash', 'client_addr'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('sent_offer', schema=None) as batch_op:
batch_op.drop_constraint(
'uq_sent_offer_squeak_hash_client_addr', type_='unique')
# ### end Alembic commands ###

View file

@ -10,6 +10,7 @@ from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy import UniqueConstraint
from sqlalchemy.types import TypeDecorator
logger = logging.getLogger(__name__)
@ -130,6 +131,8 @@ class Models:
Column("invoice_timestamp", Integer, nullable=False),
Column("invoice_expiry", Integer, nullable=False),
Column("client_addr", String(64), nullable=False),
UniqueConstraint('squeak_hash', 'client_addr',
name='uq_sent_offer_squeak_hash_client_addr')
)
self.received_payments = Table(