-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmigrations.py
More file actions
262 lines (219 loc) · 6.79 KB
/
migrations.py
File metadata and controls
262 lines (219 loc) · 6.79 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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
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 INTEGER NULL;
""")
async def m013_add_receipt_print(db: Database):
"""
Add enable_receipt_print to tpos table
"""
await db.execute("""
ALTER TABLE tpos.pos ADD enable_receipt_print BOOLEAN DEFAULT false;
""")
await db.execute("ALTER TABLE tpos.pos ADD business_name TEXT;")
await db.execute("ALTER TABLE tpos.pos ADD business_address TEXT;")
await db.execute("ALTER TABLE tpos.pos ADD business_vat_id TEXT;")
async def m014_addfiat(db: Database):
"""
Add fiat invoicing to tpos table
"""
await db.execute("""
ALTER TABLE tpos.pos ADD fiat_provider TEXT NULL;
""")
async def m015_addfiat(db: Database):
"""
Add fiat stripe_card_payments to tpos table
"""
await db.execute("""
ALTER TABLE tpos.pos ADD stripe_card_payments BOOLEAN DEFAULT false;
""")
async def m016_add_inventory_settings(db: Database):
"""
Add inventory integration columns
"""
await db.execute("""
ALTER TABLE tpos.pos ADD use_inventory BOOLEAN DEFAULT false;
""")
await db.execute("""
ALTER TABLE tpos.pos ADD inventory_id TEXT NULL;
""")
await db.execute("""
ALTER TABLE tpos.pos ADD inventory_tags TEXT NULL;
""")
async def m017_add_inventory_omit_tags(db: Database):
"""
Add inventory omit tags column
"""
await db.execute("""
ALTER TABLE tpos.pos ADD inventory_omit_tags TEXT NULL;
""")
async def m018_add_stripe_reader_id(db: Database):
"""
Add Stripe reader id column
"""
await db.execute("""
ALTER TABLE tpos.pos ADD stripe_reader_id TEXT NULL;
""")
async def m019_add_receipt_sats_only(db: Database):
"""
Add receipt option to only show sats on bitcoin transactions
"""
await db.execute("""
ALTER TABLE tpos.pos ADD only_show_sats_on_bitcoin BOOLEAN DEFAULT true;
""")
async def m020_add_remote_mode_toggle(db: Database):
"""
Add enable_remote option for cross-device invoice triggering.
"""
await db.execute("""
ALTER TABLE tpos.pos ADD enable_remote BOOLEAN DEFAULT false;
""")
async def m021_add_cash_settlement(db: Database):
"""
Add allow_cash_settlement toggle for fiat cash settlements.
"""
await db.execute("""
ALTER TABLE tpos.pos ADD allow_cash_settlement BOOLEAN DEFAULT false;
""")