-
Notifications
You must be signed in to change notification settings - Fork 4
/
migrations.py
82 lines (73 loc) · 2.09 KB
/
migrations.py
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
from lnbits.db import Database
async def m001_initial(db: Database):
await db.execute(
f"""
CREATE TABLE IF NOT EXISTS tipjar.TipJars (
id {db.serial_primary_key},
name TEXT NOT NULL,
wallet TEXT NOT NULL,
onchain TEXT,
webhook TEXT
);
"""
)
await db.execute(
f"""
CREATE TABLE IF NOT EXISTS tipjar.Tips (
id TEXT PRIMARY KEY,
wallet TEXT NOT NULL,
name TEXT NOT NULL,
message TEXT NOT NULL,
sats {db.big_int} NOT NULL,
tipjar {db.big_int} NOT NULL,
FOREIGN KEY(tipjar) REFERENCES {db.references_schema}TipJars(id)
);
"""
)
async def m002_add_onchain_limit(db: Database):
await db.execute(
"""
ALTER TABLE tipjar.TipJars ADD COLUMN onchain_limit INTEGER;
"""
)
async def m003_tipjar_id_string_rename_tables(db: Database):
await db.execute(
"""
CREATE TABLE IF NOT EXISTS tipjar.tipjar (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
wallet TEXT NOT NULL,
onchain TEXT,
webhook TEXT,
onchain_limit INTEGER
);
"""
)
await db.execute(
"""
INSERT INTO tipjar.tipjar (id, name, wallet, onchain, webhook, onchain_limit)
SELECT id, name, wallet, onchain, webhook, onchain_limit
FROM tipjar.TipJars;
"""
)
await db.execute(
f"""
CREATE TABLE IF NOT EXISTS tipjar.tip (
id TEXT PRIMARY KEY,
tipjar TEXT NOT NULL,
wallet TEXT NOT NULL,
name TEXT NOT NULL,
message TEXT NOT NULL,
sats {db.big_int} NOT NULL
);
"""
)
await db.execute(
"""
INSERT INTO tipjar.tip (id, tipjar, wallet, name, message, sats)
SELECT id, tipjar, wallet, name, message, sats
FROM tipjar.Tips;
"""
)
await db.execute("DROP TABLE tipjar.Tips;")
await db.execute("DROP TABLE tipjar.TipJars;")