-
Notifications
You must be signed in to change notification settings - Fork 14
/
migrations.py
189 lines (165 loc) · 4.61 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
from lnbits.db import Database
async def m001_initial(db: Database):
"""
Initial tposs table.
"""
await db.execute(
"""
CREATE TABLE tpos.tposs (
id TEXT PRIMARY KEY,
wallet TEXT NOT NULL,
name TEXT NOT NULL,
currency TEXT NOT NULL
);
"""
)
async def m002_addtip_wallet(db: Database):
"""
Add tips to tposs table
"""
await db.execute(
"""
ALTER TABLE tpos.tposs ADD tip_wallet TEXT NULL;
"""
)
async def m003_addtip_options(db: Database):
"""
Add tips to tposs table
"""
await db.execute(
"""
ALTER TABLE tpos.tposs ADD tip_options TEXT NULL;
"""
)
async def m004_addwithdrawlimit(db: Database):
await db.execute(
"""
CREATE TABLE tpos.pos (
id TEXT PRIMARY KEY,
wallet TEXT NOT NULL,
name TEXT NOT NULL,
currency TEXT NOT NULL,
tip_wallet TEXT NULL,
tip_options TEXT NULL,
withdrawlimit INTEGER DEFAULT 0,
withdrawpin INTEGER DEFAULT 878787,
withdrawamt INTEGER DEFAULT 0,
withdrawtime INTEGER NOT NULL DEFAULT 0,
withdrawbtwn INTEGER NOT NULL DEFAULT 10
);
"""
)
result = await db.execute("SELECT * FROM tpos.tposs")
rows = result.mappings().all()
for row in rows:
await db.execute(
"""
INSERT INTO tpos.pos (
id,
wallet,
name,
currency,
tip_wallet,
tip_options
)
VALUES (:id, :wallet, :name, :currency, :tip_wallet, :tip_options)
""",
{
"id": row["id"],
"wallet": row["wallet"],
"name": row["name"],
"currency": row["currency"],
"tip_wallet": row["tip_wallet"],
"tip_options": row["tip_options"],
},
)
await db.execute("DROP TABLE tpos.tposs")
async def m005_initial(db: Database):
"""
Initial withdraws table.
"""
await db.execute(
"""
CREATE TABLE tpos.withdraws (
id TEXT PRIMARY KEY,
tpos_id TEXT NOT NULL,
amount int,
claimed BOOLEAN DEFAULT false
);
"""
)
async def m006_items(db: Database):
"""
Add items to tpos table for storing various items (JSON format)
See `Item` class in models.
"""
await db.execute(
"""
ALTER TABLE tpos.pos ADD items TEXT DEFAULT '[]';
"""
)
async def m007_atm_premium(db: Database):
"""
Add a premium % to ATM withdraws
"""
await db.execute("ALTER TABLE tpos.pos ADD COLUMN withdrawpremium FLOAT;")
async def m008_atm_time_option_and_pin_toggle(db: Database):
"""
Add a time mins/sec and pin toggle
"""
await db.execute(
"ALTER TABLE tpos.pos " "ADD COLUMN withdrawtimeopt TEXT DEFAULT 'mins'"
)
await db.execute(
"ALTER TABLE tpos.pos "
"ADD COLUMN withdrawpindisabled BOOL NOT NULL DEFAULT false"
)
async def m009_tax_inclusive(db: Database):
"""
Add tax_inclusive column
"""
await db.execute(
"ALTER TABLE tpos.pos ADD COLUMN tax_inclusive BOOL NOT NULL DEFAULT true;"
)
await db.execute("ALTER TABLE tpos.pos ADD COLUMN tax_default FLOAT DEFAULT 0;")
async def m010_rename_tpos_withdraw_columns(db: Database):
"""
Add rename tpos withdraw columns
"""
await db.execute(
"""
CREATE TABLE tpos.pos_backup AS
SELECT
id, name, currency, items, wallet, tax_inclusive,
tax_default, tip_wallet, tip_options,
withdrawamt AS withdrawn_amount,
withdrawtime AS withdraw_time,
withdrawbtwn AS withdraw_between,
withdrawlimit AS withdraw_limit,
withdrawtimeopt AS withdraw_time_option,
withdrawpremium AS withdraw_premium,
withdrawpindisabled AS withdraw_pin_disabled,
withdrawpin AS withdraw_pin
FROM tpos.pos
"""
)
await db.execute("DROP TABLE tpos.pos")
await db.execute("ALTER TABLE tpos.pos_backup RENAME TO pos")
async def m011_lnaddress(db: Database):
"""
Add lnaddress to tpos table
"""
await db.execute(
"""
ALTER TABLE tpos.pos ADD lnaddress BOOLEAN DEFAULT false;
"""
)
async def m012_addlnaddress(db: Database):
"""
Add lnaddress_cut to tpos table
"""
await db.execute(
"""
ALTER TABLE tpos.pos ADD lnaddress_cut TEXT NULL;
"""
)