Fix ticket unique constraint definition
It was defined on the scoped_id.unique param instad of using __table_args__, and not applied to the database.
This commit is contained in:
parent
45e859130b
commit
a56cdf8ab8
|
@ -0,0 +1,23 @@
|
|||
"""Add ticket unique constraint.
|
||||
|
||||
Revision ID: c7146cb70d6b
|
||||
Revises: 0494a51dbfd0
|
||||
Create Date: 2019-01-09 12:25:27.275257
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'c7146cb70d6b'
|
||||
down_revision = '0494a51dbfd0'
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_unique_constraint(
|
||||
'uq_ticket_tracker_id_scoped_id', 'ticket', ['tracker_id', 'scoped_id'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_constraint(
|
||||
'uq_ticket_tracker_id_scoped_id', 'ticket', type_='unique')
|
|
@ -1,10 +1,14 @@
|
|||
import sqlalchemy as sa
|
||||
from srht.database import Base
|
||||
from srht.flagtype import FlagType
|
||||
from todosrht.types import TicketAccess, TicketStatus, TicketResolution, TicketSeen
|
||||
from todosrht.types import TicketAccess, TicketStatus, TicketResolution
|
||||
|
||||
class Ticket(Base):
|
||||
__tablename__ = 'ticket'
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('tracker_id', 'scoped_id',
|
||||
name="uq_ticket_tracker_id_scoped_id"),
|
||||
)
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
created = sa.Column(sa.DateTime, nullable=False)
|
||||
updated = sa.Column(sa.DateTime, nullable=False)
|
||||
|
@ -15,10 +19,7 @@ class Ticket(Base):
|
|||
tracker = sa.orm.relationship("Tracker",
|
||||
backref=sa.orm.backref("tickets", cascade="all, delete-orphan"))
|
||||
|
||||
scoped_id = sa.Column(sa.Integer,
|
||||
nullable=False,
|
||||
index=True,
|
||||
unique=sa.UniqueConstraint('scoped_id', 'tracker_id'))
|
||||
scoped_id = sa.Column(sa.Integer, nullable=False, index=True)
|
||||
|
||||
dupe_of_id = sa.Column(sa.Integer,
|
||||
sa.ForeignKey("ticket.id", ondelete="SET NULL"))
|
||||
|
|
Loading…
Reference in New Issue