Contains shared infrastructure for all coop services: - shared/ (factory, urls, user_loader, context, internal_api, jinja_setup) - models/ (User, Order, Calendar, Ticket, Product, Ghost CMS) - db/ (SQLAlchemy async session, base) - suma_browser/app/ (csrf, middleware, errors, authz, redis_cacher, payments, filters, utils) - suma_browser/templates/ (shared base layouts, macros, error pages) - static/ (CSS, JS, fonts, images) - alembic/ (database migrations) - config/ (app-config.yaml) - editor/ (Lexical editor Node.js build) - requirements.txt Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
79 lines
2.0 KiB
Python
79 lines
2.0 KiB
Python
"""Add cart_items table for shopping cart"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = "0002_add_cart_items"
|
|
down_revision = "0001_initial_schema"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"cart_items",
|
|
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
|
|
|
# Either a logged-in user *or* an anonymous session_id
|
|
sa.Column(
|
|
"user_id",
|
|
sa.Integer(),
|
|
sa.ForeignKey("users.id", ondelete="CASCADE"),
|
|
nullable=True,
|
|
),
|
|
sa.Column("session_id", sa.String(length=128), nullable=True),
|
|
|
|
# IMPORTANT: reference products.id (PK), not slug
|
|
sa.Column(
|
|
"product_id",
|
|
sa.Integer(),
|
|
sa.ForeignKey("products.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
),
|
|
|
|
sa.Column(
|
|
"quantity",
|
|
sa.Integer(),
|
|
nullable=False,
|
|
server_default="1",
|
|
),
|
|
sa.Column(
|
|
"created_at",
|
|
sa.DateTime(timezone=True),
|
|
nullable=False,
|
|
server_default=sa.text("now()"),
|
|
),
|
|
sa.Column(
|
|
"updated_at",
|
|
sa.DateTime(timezone=True),
|
|
nullable=False,
|
|
server_default=sa.text("now()"),
|
|
),
|
|
sa.Column(
|
|
"deleted_at",
|
|
sa.DateTime(timezone=True),
|
|
nullable=True,
|
|
),
|
|
)
|
|
|
|
# Indexes to speed up cart lookups
|
|
op.create_index(
|
|
"ix_cart_items_user_product",
|
|
"cart_items",
|
|
["user_id", "product_id"],
|
|
unique=False,
|
|
)
|
|
op.create_index(
|
|
"ix_cart_items_session_product",
|
|
"cart_items",
|
|
["session_id", "product_id"],
|
|
unique=False,
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_cart_items_session_product", table_name="cart_items")
|
|
op.drop_index("ix_cart_items_user_product", table_name="cart_items")
|
|
op.drop_table("cart_items")
|