-
Notifications
You must be signed in to change notification settings - Fork 3
/
migrations.py
102 lines (74 loc) · 2.5 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
from lnbits.db import Database
async def m001_initial_invoices(db: Database):
await db.execute(
f"""
CREATE TABLE nostrnip5.domains (
id TEXT PRIMARY KEY,
wallet TEXT NOT NULL,
currency TEXT NOT NULL,
amount INTEGER NOT NULL,
domain TEXT NOT NULL,
time TIMESTAMP NOT NULL DEFAULT {db.timestamp_now}
);
"""
)
await db.execute(
f"""
CREATE TABLE nostrnip5.addresses (
id TEXT PRIMARY KEY,
domain_id TEXT NOT NULL,
local_part TEXT NOT NULL,
pubkey TEXT NOT NULL,
active BOOLEAN NOT NULL DEFAULT false,
time TIMESTAMP NOT NULL DEFAULT {db.timestamp_now},
FOREIGN KEY(domain_id) REFERENCES {db.references_schema}domains(id)
);
"""
)
async def m002_add_owner_id_to_addresess(db: Database):
"""
Adds owner_id column to addresses.
"""
await db.execute("ALTER TABLE nostrnip5.addresses ADD COLUMN owner_id TEXT")
async def m003_add_cost_extra_column_to_domains(db: Database):
"""
Adds cost_extra column to domains.
"""
await db.execute("ALTER TABLE nostrnip5.domains ADD COLUMN cost_extra TEXT")
async def m004_add_domain_rankings_table(db: Database):
await db.execute(
"""
CREATE TABLE nostrnip5.identifiers_rankings (
name TEXT PRIMARY KEY,
rank INTEGER NOT NULL
);
"""
)
async def m005_add_domain_rankings_table(db: Database):
await db.execute(
"""
CREATE TABLE nostrnip5.settings (
owner_id TEXT PRIMARY KEY,
settings text
);
"""
)
async def m006_make_amount_type_real(db: Database):
"""
Domain amount was INT which is not well suited for fiat currencies. Not it is REAL.
"""
await db.execute(
"ALTER TABLE nostrnip5.domains ADD COLUMN cost REAL NOT NULL DEFAULT 0"
)
await db.execute("UPDATE nostrnip5.domains SET cost = amount")
await db.execute("ALTER TABLE nostrnip5.domains DROP COLUMN amount")
async def m007_add_cost_extra_column_to_addresses(db: Database):
"""
Adds extra, expires_at and reimburse_amount columns to addresses.
"""
await db.execute("ALTER TABLE nostrnip5.addresses ADD COLUMN extra TEXT")
await db.execute("ALTER TABLE nostrnip5.addresses ADD COLUMN expires_at TIMESTAMP")
await db.execute(
"ALTER TABLE nostrnip5.addresses ADD COLUMN "
"reimburse_amount REAL NOT NULL DEFAULT 0"
)