Repository: fossasia/open-event-server

Issue:
Remove unique ticket_id constraint on TicketHolder model
**Describe the bug**
The `TicketHolder` model has a unique constraint on `ticket_id`. As a result, for a particular ticket, only one attendee(or ticket holder) can be created.
```python
class TicketHolder(SoftDeletionModel):
    __tablename__ = "ticket_holders"
    __table_args__ = (
        db.UniqueConstraint('ticket_id', name='ticket_event'),
        )

```

**To Reproduce**
Steps to reproduce the behavior:
1. Create an attendee with any ticket id
2. Create one more attendee for the same ticket_id
3. You will see the error

**Expected behavior**
Multiple attendees should be allowed for a particular ticket until its quantity is exhausted.

**Stacktrace**
```sh
sqlalchemy.exc.IntegrityError: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely) (psycopg2.IntegrityError) duplicate key value violates unique constraint "ticket_event"
DETAIL:  Key (ticket_id)=(11) already exists.
 [SQL: 'INSERT INTO ticket_holders (deleted_at, firstname, lastname, email, address, city, state, country, job_title, phone, tax_business_info, billing_address, home_address, shipping_address, company, work_address, work_phone, website, blog, twitter, facebook, github, gender, birth_date, pdf_url, ticket_id, order_id, is_checked_in, checkin_times, attendee_notes, event_id) VALUES (%(deleted_at)s, %(firstname)s, %(lastname)s, %(email)s, %(address)s, %(city)s, %(state)s, %(country)s, %(job_title)s, %(phone)s, %(tax_business_info)s, %(billing_address)s, %(home_address)s, %(shipping_address)s, %(company)s, %(work_address)s, %(work_phone)s, %(website)s, %(blog)s, %(twitter)s, %(facebook)s, %(github)s, %(gender)s, %(birth_date)s, %(pdf_url)s, %(ticket_id)s, %(order_id)s, %(is_checked_in)s, %(checkin_times)s, %(attendee_notes)s, %(event_id)s) RETURNING ticket_holders.id'] [parameters: {'deleted_at': None, 'firstname': 'John', 'lastname': 'Doe', 'email': 'joh2112ndoe@example.com', 'address': 'address', 'city': 'example', 'state': 'example', 'country': 'IN', 'job_title': None, 'phone': None, 'tax_business_info': None, 'billing_address': None, 'home_address': None, 'shipping_address': None, 'company': None, 'work_address': None, 'work_phone': None, 'website': None, 'blog': None, 'twitter': None, 'facebook': None, 'github': None, 'gender': None, 'birth_date': None, 'pdf_url': None, 'ticket_id': 11, 'order_id': None, 'is_checked_in': False, 'checkin_times': None, 'attendee_notes': 'example', 'event_id': None}]
```
**Additional details (please complete the following information):**
 - OS: Ubuntu 18.04
 - Python Version 3.6
 - `HEAD` Commit hash [e.g. `4629c62`]



Discussion:

Resolving patch:
diff --git a/app/models/ticket_holder.py b/app/models/ticket_holder.py
--- a/app/models/ticket_holder.py
+++ b/app/models/ticket_holder.py
@@ -9,9 +9,6 @@
 
 class TicketHolder(SoftDeletionModel):
     __tablename__ = "ticket_holders"
-    __table_args__ = (
-        db.UniqueConstraint('ticket_id', name='ticket_event'),
-        )
 
     id = db.Column(db.Integer, primary_key=True)
     firstname = db.Column(db.String, nullable=False)
diff --git a/migrations/versions/f6e303f33d28_.py b/migrations/versions/f6e303f33d28_.py
new file mode 100644
--- /dev/null
+++ b/migrations/versions/f6e303f33d28_.py
@@ -0,0 +1,34 @@
+"""empty message
+
+Revision ID: f6e303f33d28
+Revises: a79f1dc2fd67
+Create Date: 2018-06-29 15:36:45.543502
+
+"""
+
+from alembic import op
+import sqlalchemy as sa
+import sqlalchemy_utils
+
+
+# revision identifiers, used by Alembic.
+revision = 'f6e303f33d28'
+down_revision = 'a79f1dc2fd67'
+
+
+def upgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.alter_column('ticket_holders', 'lastname',
+               existing_type=sa.VARCHAR(),
+               nullable=False)
+    op.drop_constraint('ticket_event', 'ticket_holders', type_='unique')
+    # ### end Alembic commands ###
+
+
+def downgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.create_unique_constraint('ticket_event', 'ticket_holders', ['ticket_id'])
+    op.alter_column('ticket_holders', 'lastname',
+               existing_type=sa.VARCHAR(),
+               nullable=True)
+    # ### end Alembic commands ###


Test patch: