Skip to content

Commit

Permalink
Add order table (#2866) (minor)
Browse files Browse the repository at this point in the history
### Added

- Order table
- Column in case table with a foreign key constraint to the order id.
  • Loading branch information
islean authored Jan 24, 2024
1 parent d176eec commit 66e13cd
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
48 changes: 48 additions & 0 deletions alembic/versions/2024_01_24_a6befebf1231_add_order_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Add order table
Revision ID: a6befebf1231
Revises: 584840c706a0
Create Date: 2024-01-24 10:43:55.206551
"""
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "a6befebf1231"
down_revision = "584840c706a0"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"order",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("customer_id", sa.Integer(), nullable=False),
sa.Column("order_date", sa.DateTime(), nullable=False),
sa.Column("ticket_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["customer_id"],
["customer.id"],
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("id"),
)
op.create_index(op.f("ix_order_ticket_id"), "order", ["ticket_id"], unique=True)
op.add_column(
"case",
sa.Column(
"order_id", sa.Integer(), sa.ForeignKey("order.id", name="case_ibfk_2"), nullable=True
),
)


def downgrade():
op.drop_constraint(table_name="case", constraint_name="case_ibfk_2", type_="foreignkey")
op.drop_column("case", "order_id")
op.drop_index(index_name="ix_order_ticket_id", table_name="order")
op.drop_table("order")
# ### end Alembic commands ###
15 changes: 15 additions & 0 deletions cg/store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ class Case(Model, PriorityMixin):
internal_id = Column(types.String(32), unique=True, nullable=False)
is_compressible = Column(types.Boolean, nullable=False, default=True)
name = Column(types.String(128), nullable=False)
order_id = Column(ForeignKey("order.id"))
ordered_at = Column(types.DateTime, default=dt.datetime.now)
_panels = Column(types.Text)

Expand Down Expand Up @@ -873,3 +874,17 @@ class SampleLaneSequencingMetrics(Model):

def to_dict(self):
return to_dict(model_instance=self)


class Order(Model):
"""Model for storing orders."""

__tablename__ = "order"

id = Column(types.Integer, primary_key=True, unique=True)
customer_id = Column(types.String(64), ForeignKey("customer.id"), nullable=False)
order_date = Column(types.DateTime, nullable=False)
ticket_id = Column(types.Integer, nullable=False, unique=True, index=True)

def to_dict(self):
return to_dict(model_instance=self)

0 comments on commit 66e13cd

Please sign in to comment.