import sqlite3
c = sqlite3.connect('db.sqlite3')
cur = c.cursor()

# Create erp_shipment table
cur.execute("""
CREATE TABLE IF NOT EXISTS erp_shipment (
    id                    VARCHAR(36) PRIMARY KEY,
    tenant_id             VARCHAR(36) NOT NULL,
    created_at            DATETIME NOT NULL,
    updated_at            DATETIME NOT NULL,
    reference_number      VARCHAR(32) NOT NULL,
    customer_name         VARCHAR(255) NOT NULL,
    customer_email        VARCHAR(255),
    shipment_type         VARCHAR(16) NOT NULL DEFAULT 'IMPORT',
    status                VARCHAR(32) NOT NULL DEFAULT 'DRAFT',
    origin                VARCHAR(255) NOT NULL,
    destination           VARCHAR(255) NOT NULL,
    carrier               VARCHAR(255),
    tracking_number       VARCHAR(128),
    bill_of_lading        VARCHAR(128),
    customs_entry_number  VARCHAR(128),
    estimated_arrival     DATE,
    declared_value        DECIMAL(18,2) NOT NULL DEFAULT 0.00,
    duty_amount           DECIMAL(18,2) NOT NULL DEFAULT 0.00,
    freight_amount        DECIMAL(18,2) NOT NULL DEFAULT 0.00,
    currency              VARCHAR(3) NOT NULL DEFAULT 'PHP',
    notes                 TEXT,
    UNIQUE (tenant_id, reference_number)
)
""")
c.commit()
print("erp_shipment table created")

# Verify
cur.execute("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'erp_%'")
print("ERP tables now:", [r[0] for r in cur.fetchall()])
