-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmigrations.py
More file actions
93 lines (86 loc) · 2.86 KB
/
Copy pathmigrations.py
File metadata and controls
93 lines (86 loc) · 2.86 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
from lnbits.db import Database
async def m001_initial(db: Database):
"""
Fresh install schema for the inventory extension.
Creates inventories, items, managers, and audit_logs tables with omit_tags included.
"""
await db.execute(
f"""
CREATE TABLE IF NOT EXISTS inventory.inventories (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
name TEXT NOT NULL,
currency TEXT NOT NULL,
global_discount_percentage REAL DEFAULT 0.00,
default_tax_rate REAL DEFAULT 0.00,
is_tax_inclusive BOOLEAN DEFAULT TRUE,
tags TEXT,
omit_tags TEXT,
created_at TIMESTAMP NOT NULL DEFAULT {db.timestamp_now},
updated_at TIMESTAMP NOT NULL DEFAULT {db.timestamp_now}
);
"""
)
async def m002_add_item_weight(db: Database):
"""
Add optional weight (grams) to inventory items.
"""
await db.execute(
f"""
CREATE TABLE IF NOT EXISTS inventory.items (
id TEXT PRIMARY KEY,
inventory_id TEXT NOT NULL,
name TEXT NOT NULL,
description TEXT,
images TEXT,
sku TEXT,
quantity_in_stock INTEGER CHECK (
quantity_in_stock IS NULL OR quantity_in_stock >= 0
),
price REAL NOT NULL,
discount_percentage REAL DEFAULT 0.00,
tax_rate REAL,
reorder_threshold INTEGER,
weight_grams INTEGER,
unit_cost REAL,
external_id TEXT,
is_active BOOLEAN DEFAULT TRUE,
tags TEXT,
omit_tags TEXT,
internal_note TEXT,
manager_id TEXT,
is_approved BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP NOT NULL DEFAULT {db.timestamp_now},
updated_at TIMESTAMP NOT NULL DEFAULT {db.timestamp_now}
);
"""
)
await db.execute(
f"""
CREATE TABLE IF NOT EXISTS inventory.managers (
id TEXT PRIMARY KEY,
inventory_id TEXT NOT NULL,
name TEXT NOT NULL,
email TEXT,
tags TEXT,
created_at TIMESTAMP NOT NULL DEFAULT {db.timestamp_now},
updated_at TIMESTAMP NOT NULL DEFAULT {db.timestamp_now}
);
"""
)
await db.execute(
f"""
CREATE TABLE IF NOT EXISTS inventory.audit_logs (
id {db.serial_primary_key},
inventory_id TEXT NOT NULL,
item_id TEXT NOT NULL,
quantity_change INTEGER NOT NULL,
quantity_before INTEGER NOT NULL,
quantity_after INTEGER NOT NULL,
source TEXT NOT NULL,
idempotency_key TEXT NOT NULL,
metadata TEXT,
created_at TIMESTAMP NOT NULL DEFAULT {db.timestamp_now}
);
"""
)