-
Notifications
You must be signed in to change notification settings - Fork 2
/
migrations.py
109 lines (91 loc) · 2.67 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
async def m001_initial(db):
"""
Initial wallet table.
"""
await db.execute(
f"""
CREATE TABLE watchonly.wallets (
id TEXT NOT NULL PRIMARY KEY,
"user" TEXT,
masterpub TEXT NOT NULL,
title TEXT NOT NULL,
address_no INTEGER NOT NULL DEFAULT 0,
balance {db.big_int} NOT NULL
);
"""
)
await db.execute(
f"""
CREATE TABLE watchonly.addresses (
id TEXT NOT NULL PRIMARY KEY,
address TEXT NOT NULL,
wallet TEXT NOT NULL,
amount {db.big_int} NOT NULL
);
"""
)
await db.execute(
"""
CREATE TABLE watchonly.mempool (
"user" TEXT NOT NULL,
endpoint TEXT NOT NULL
);
"""
)
async def m002_add_columns_to_adresses(db):
"""
Add 'branch_index', 'address_index', 'has_activity' and
'note' columns to the 'addresses' table
"""
await db.execute(
"""
ALTER TABLE watchonly.addresses
ADD COLUMN branch_index INTEGER NOT NULL DEFAULT 0
"""
)
await db.execute(
"""
ALTER TABLE watchonly.addresses
ADD COLUMN address_index INTEGER NOT NULL DEFAULT 0
"""
)
await db.execute(
"ALTER TABLE watchonly.addresses ADD COLUMN has_activity BOOLEAN DEFAULT false"
)
await db.execute("ALTER TABLE watchonly.addresses ADD COLUMN note TEXT")
async def m003_add_columns_to_wallets(db):
"""
Add 'type' and 'fingerprint' columns to the 'wallets' table
"""
await db.execute("ALTER TABLE watchonly.wallets ADD COLUMN type TEXT")
await db.execute(
"ALTER TABLE watchonly.wallets ADD COLUMN fingerprint TEXT NOT NULL DEFAULT ''"
)
async def m004_create_config_table(db):
"""
Allow the extension to persist and retrieve any number of config values.
Each user has its configurations saved as a JSON string
"""
await db.execute(
"""CREATE TABLE watchonly.config (
"user" TEXT NOT NULL,
json_data TEXT NOT NULL
);"""
)
async def m005_add_network_column_to_wallets(db):
"""
Add network' column to the 'wallets' table
"""
await db.execute(
"ALTER TABLE watchonly.wallets ADD COLUMN network TEXT DEFAULT 'Mainnet';"
)
async def m006_drop_mempool_table(db):
"""
Mempool data is now part of `config`
"""
await db.execute("DROP TABLE watchonly.mempool;")
async def m007_add_wallet_meta_data(db):
"""
Add 'meta' for storing various metadata about the wallet
"""
await db.execute("ALTER TABLE watchonly.wallets ADD COLUMN meta TEXT DEFAULT '{}';")