File size: 2,490 Bytes
4420fdb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""Business schema and deterministic seed for site_id=article.

Opened through the generated backend integration seam only; the tables live in
this site's own bound SQLite database (volume identity websitebench-article-data).
"""

from __future__ import annotations

import sqlite3

SYNTHETIC_ACCOUNTS = [
    {
        "subject_id": "article-shopper-1",
        "email": "shopper@article.test",
        "display_name": "Alex Shopper",
        "password": "ArticleDemo!2026",
    },
]


def migrate(connection: sqlite3.Connection) -> None:
    """Create the cart, favorite and order tables this clone owns."""

    connection.execute(
        """
        CREATE TABLE IF NOT EXISTS article_cart_items (
            cart_item_id INTEGER PRIMARY KEY AUTOINCREMENT,
            owner_key    TEXT NOT NULL,
            product_id   TEXT NOT NULL,
            quantity     INTEGER NOT NULL CHECK (quantity > 0),
            created_at   INTEGER NOT NULL,
            UNIQUE (owner_key, product_id)
        )
        """
    )
    connection.execute(
        "CREATE INDEX IF NOT EXISTS article_cart_owner ON article_cart_items(owner_key)"
    )
    connection.execute(
        """
        CREATE TABLE IF NOT EXISTS article_favorites (
            favorite_id INTEGER PRIMARY KEY AUTOINCREMENT,
            owner_key   TEXT NOT NULL,
            product_id  TEXT NOT NULL,
            created_at  INTEGER NOT NULL,
            UNIQUE (owner_key, product_id)
        )
        """
    )
    connection.execute(
        """
        CREATE TABLE IF NOT EXISTS article_orders (
            order_id     INTEGER PRIMARY KEY AUTOINCREMENT,
            order_number TEXT NOT NULL UNIQUE,
            owner_key    TEXT NOT NULL,
            email        TEXT NOT NULL,
            ship_to      TEXT NOT NULL,
            subtotal_cents INTEGER NOT NULL,
            created_at   INTEGER NOT NULL
        )
        """
    )
    connection.execute(
        """
        CREATE TABLE IF NOT EXISTS article_order_items (
            order_item_id INTEGER PRIMARY KEY AUTOINCREMENT,
            order_id      INTEGER NOT NULL REFERENCES article_orders(order_id),
            product_id    TEXT NOT NULL,
            name          TEXT NOT NULL,
            unit_cents    INTEGER NOT NULL,
            quantity      INTEGER NOT NULL
        )
        """
    )


def seed(connection: sqlite3.Connection) -> None:
    """No business rows are pre-seeded; the catalog is a read-only fixture."""

    return None