-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmigrations.py
104 lines (91 loc) · 2.26 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
import secp256k1
async def m001_initial(db):
"""
Initial tables
"""
await db.execute(
"""
CREATE TABLE nwcprovider.keys (
pubkey TEXT PRIMARY KEY,
wallet TEXT NOT NULL,
description TEXT NOT NULL,
expires_at INTEGER NOT NULL,
permissions TEXT NOT NULL,
created_at INTEGER NOT NULL
);
"""
)
await db.execute(
f"""
CREATE TABLE nwcprovider.spent (
id {db.serial_primary_key},
pubkey TEXT NOT NULL,
amount_msats INTEGER NOT NULL,
created_at INTEGER NOT NULL,
FOREIGN KEY(pubkey)
REFERENCES {db.references_schema}keys(pubkey)
ON DELETE CASCADE
);
"""
)
await db.execute(
f"""
CREATE TABLE nwcprovider.budgets (
id {db.serial_primary_key},
pubkey TEXT NOT NULL,
budget_msats INTEGER NOT NULL,
refresh_window INTEGER NOT NULL,
created_at INTEGER NOT NULL,
FOREIGN KEY(pubkey)
REFERENCES {db.references_schema}keys(pubkey)
ON DELETE CASCADE
);
"""
)
async def m002_config(db):
"""
Config table
"""
await db.execute(
"""
CREATE TABLE nwcprovider.config (
key TEXT PRIMARY KEY,
value TEXT NOT NULL
);
"""
)
async def m003_default_config(db):
"""
Default config
"""
await db.execute(
"""
INSERT INTO nwcprovider.config (key, value) VALUES ('relay', 'nostrclient');
"""
)
new_private_key = bytes.hex(secp256k1._gen_private_key())
await db.execute(
"""
INSERT INTO nwcprovider.config (key, value) VALUES ('provider_key', ?);
""",
(new_private_key,),
)
async def m004_default_config2(db):
"""
Default config
"""
await db.execute(
"""
INSERT INTO nwcprovider.config (key, value) VALUES ('relay_alias', ?);
""",
("",),
)
async def m005_key_last_used(db):
"""
Add last_used to keys
"""
await db.execute(
"""
ALTER TABLE nwcprovider.keys ADD COLUMN last_used INTEGER;
"""
)