-
Notifications
You must be signed in to change notification settings - Fork 9
/
migrations.py
141 lines (127 loc) · 3.6 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
async def m001_initial(db):
"""
Creates an improved withdraw table and migrates the existing data.
"""
await db.execute(
f"""
CREATE TABLE withdraw.withdraw_links (
id TEXT PRIMARY KEY,
wallet TEXT,
title TEXT,
min_withdrawable {db.big_int} DEFAULT 1,
max_withdrawable {db.big_int} DEFAULT 1,
uses INTEGER DEFAULT 1,
wait_time INTEGER,
is_unique INTEGER DEFAULT 0,
unique_hash TEXT UNIQUE,
k1 TEXT,
open_time INTEGER,
used INTEGER DEFAULT 0,
usescsv TEXT
);
"""
)
async def m002_change_withdraw_table(db):
"""
Creates an improved withdraw table and migrates the existing data.
"""
await db.execute(
f"""
CREATE TABLE withdraw.withdraw_link (
id TEXT PRIMARY KEY,
wallet TEXT,
title TEXT,
min_withdrawable {db.big_int} DEFAULT 1,
max_withdrawable {db.big_int} DEFAULT 1,
uses INTEGER DEFAULT 1,
wait_time INTEGER,
is_unique INTEGER DEFAULT 0,
unique_hash TEXT UNIQUE,
k1 TEXT,
open_time INTEGER,
used INTEGER DEFAULT 0,
usescsv TEXT
);
"""
)
for row in [
list(row) for row in await db.fetchall("SELECT * FROM withdraw.withdraw_links")
]:
usescsv = ""
for i in range(row[5]):
if row[7]:
usescsv += "," + str(i + 1)
else:
usescsv += "," + str(1)
usescsv = usescsv[1:]
await db.execute(
"""
INSERT INTO withdraw.withdraw_link (
id,
wallet,
title,
min_withdrawable,
max_withdrawable,
uses,
wait_time,
is_unique,
unique_hash,
k1,
open_time,
used,
usescsv
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
row[0],
row[1],
row[2],
row[3],
row[4],
row[5],
row[6],
row[7],
row[8],
row[9],
row[10],
row[11],
usescsv,
),
)
await db.execute("DROP TABLE withdraw.withdraw_links")
async def m003_make_hash_check(db):
"""
Creates a hash check table.
"""
await db.execute(
"""
CREATE TABLE withdraw.hash_check (
id TEXT PRIMARY KEY,
lnurl_id TEXT
);
"""
)
async def m004_webhook_url(db):
"""
Adds webhook_url
"""
await db.execute("ALTER TABLE withdraw.withdraw_link ADD COLUMN webhook_url TEXT;")
async def m005_add_custom_print_design(db):
"""
Adds custom print design
"""
await db.execute("ALTER TABLE withdraw.withdraw_link ADD COLUMN custom_url TEXT;")
async def m006_webhook_headers_and_body(db):
"""
Add headers and body to webhooks
"""
await db.execute(
"ALTER TABLE withdraw.withdraw_link ADD COLUMN webhook_headers TEXT;"
)
await db.execute("ALTER TABLE withdraw.withdraw_link ADD COLUMN webhook_body TEXT;")
async def m007_add_created_at_timestamp(db):
await db.execute(
"ALTER TABLE withdraw.withdraw_link "
f"ADD COLUMN created_at TIMESTAMP DEFAULT {db.timestamp_column_default}"
)