lnbits-legend/lnbits/extensions/shop/migrations.py

145 lines
3.4 KiB
Python
Raw Normal View History

2022-01-27 12:24:38 +00:00
async def m001_initial(db):
"""
2022-07-25 10:11:03 +01:00
Initial stalls table.
2022-01-27 12:24:38 +00:00
"""
await db.execute(
"""
2022-12-20 08:21:48 +00:00
CREATE TABLE shop.stalls (
2022-01-27 12:24:38 +00:00
id TEXT PRIMARY KEY,
2022-07-25 10:11:03 +01:00
wallet TEXT NOT NULL,
name TEXT NOT NULL,
publickey TEXT,
relays TEXT,
2022-08-18 10:49:04 +01:00
shippingzones TEXT NOT NULL,
rating INTEGER DEFAULT 0
2022-01-27 12:24:38 +00:00
);
"""
)
"""
2022-07-25 10:11:03 +01:00
Initial products table.
2022-01-27 12:24:38 +00:00
"""
await db.execute(
2022-08-18 10:49:04 +01:00
f"""
2022-12-20 08:21:48 +00:00
CREATE TABLE shop.products (
2022-01-27 12:24:38 +00:00
id TEXT PRIMARY KEY,
2022-07-25 10:11:03 +01:00
stall TEXT NOT NULL REFERENCES {db.references_schema}stalls (id),
product TEXT NOT NULL,
categories TEXT,
description TEXT,
image TEXT,
price INTEGER NOT NULL,
quantity INTEGER NOT NULL,
2022-08-18 10:49:04 +01:00
rating INTEGER DEFAULT 0
2022-01-27 12:24:38 +00:00
);
"""
)
"""
Initial zones table.
"""
await db.execute(
"""
2022-12-20 08:21:48 +00:00
CREATE TABLE shop.zones (
2022-01-27 12:24:38 +00:00
id TEXT PRIMARY KEY,
"user" TEXT NOT NULL,
2022-01-27 12:24:38 +00:00
cost TEXT NOT NULL,
countries TEXT NOT NULL
);
"""
)
"""
Initial orders table.
"""
await db.execute(
2022-08-18 10:49:04 +01:00
f"""
2022-12-20 08:21:48 +00:00
CREATE TABLE shop.orders (
2022-07-25 10:11:03 +01:00
id {db.serial_primary_key},
2022-08-16 12:08:27 +01:00
wallet TEXT NOT NULL,
2022-08-18 10:49:04 +01:00
username TEXT,
2022-08-16 12:08:27 +01:00
pubkey TEXT,
2022-08-18 10:49:04 +01:00
shippingzone TEXT NOT NULL,
2022-01-27 12:24:38 +00:00
address TEXT NOT NULL,
email TEXT NOT NULL,
2022-08-16 12:08:27 +01:00
total INTEGER NOT NULL,
2022-01-27 12:24:38 +00:00
invoiceid TEXT NOT NULL,
paid BOOLEAN NOT NULL,
shipped BOOLEAN NOT NULL,
time TIMESTAMP NOT NULL DEFAULT """
+ db.timestamp_now
+ """
2022-01-27 12:24:38 +00:00
);
"""
)
2022-07-25 10:11:03 +01:00
"""
Initial order details table.
"""
await db.execute(
2022-08-18 10:49:04 +01:00
f"""
2022-12-20 08:21:48 +00:00
CREATE TABLE shop.order_details (
2022-07-25 10:11:03 +01:00
id TEXT PRIMARY KEY,
2022-08-18 10:49:04 +01:00
order_id INTEGER NOT NULL REFERENCES {db.references_schema}orders (id),
product_id TEXT NOT NULL REFERENCES {db.references_schema}products (id),
2022-08-16 12:08:27 +01:00
quantity INTEGER NOT NULL
2022-07-25 10:11:03 +01:00
);
"""
)
2022-07-27 15:28:58 +01:00
"""
Initial market table.
"""
await db.execute(
"""
2022-12-20 08:21:48 +00:00
CREATE TABLE shop.markets (
2022-07-27 15:28:58 +01:00
id TEXT PRIMARY KEY,
usr TEXT NOT NULL,
name TEXT
);
"""
)
"""
Initial market stalls table.
"""
await db.execute(
2022-08-18 10:49:04 +01:00
f"""
2022-12-20 08:21:48 +00:00
CREATE TABLE shop.market_stalls (
2022-07-27 15:28:58 +01:00
id TEXT PRIMARY KEY,
marketid TEXT NOT NULL REFERENCES {db.references_schema}markets (id),
stallid TEXT NOT NULL REFERENCES {db.references_schema}stalls (id)
);
"""
)
2022-09-30 10:16:34 +01:00
2022-09-30 17:29:35 +01:00
2022-09-30 10:16:34 +01:00
async def m002_add_chat_messages(db):
"""
Initial chat messages table.
"""
await db.execute(
f"""
2022-12-20 08:21:48 +00:00
CREATE TABLE shop.messages (
2022-09-30 10:16:34 +01:00
id {db.serial_primary_key},
msg TEXT NOT NULL,
pubkey TEXT NOT NULL,
id_conversation TEXT NOT NULL,
timestamp TIMESTAMP NOT NULL DEFAULT """
+ db.timestamp_now
+ """
);
"""
)
2022-11-15 00:59:41 +00:00
if db.type != "SQLITE":
"""
Create indexes for message fetching
"""
await db.execute(
2022-12-20 08:21:48 +00:00
"CREATE INDEX idx_messages_timestamp ON shop.messages (timestamp DESC)"
2022-11-15 00:59:41 +00:00
)
await db.execute(
2022-12-20 08:21:48 +00:00
"CREATE INDEX idx_messages_conversations ON shop.messages (id_conversation)"
2022-11-15 00:59:41 +00:00
)