-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_tables.sql
49 lines (42 loc) · 1.44 KB
/
create_tables.sql
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
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS download_status (
address VARCHAR(42) PRIMARY KEY,
provider TEXT
);
CREATE UNIQUE INDEX IF NOT EXISTS download_status_unique ON download_status (address, provider);
CREATE TABLE IF NOT EXISTS appearances (
id INTEGER PRIMARY KEY,
address VARCHAR(42) NOT NULL,
block_number INT,
transaction_index INT,
provider TEXT
);
CREATE INDEX IF NOT EXISTS appearances_appearance ON appearances (address, block_number, transaction_index);
CREATE INDEX IF NOT EXISTS appearances_provider ON appearances (provider);
CREATE table if not EXISTS appearance_reasons (
appearance_id INTEGER NOT NULL,
provider TEXT,
reason TEXT,
comment TEXT,
foreign key(appearance_id) references appearances(id)
);
create index if not exists appearance_reasons_id ON appearance_reasons (appearance_id);
CREATE table if not EXISTS appearance_balance_changes (
appearance_id INTEGER NOT NULL,
balance_change BOOLEAN,
foreign key(appearance_id) references appearances(id)
);
create index if not exists appearance_balance_changes_id ON appearance_balance_changes (appearance_id);
CREATE TABLE IF NOT EXISTS incompatible_addresses (
address VARCHAR(42) NOT NULL,
appearances INT
);
CREATE VIEW IF NOT EXISTS view_appearances_with_providers AS SELECT
id,
address,
block_number,
transaction_index,
JSON_GROUP_ARRAY ( provider ) as providers
FROM (SELECT DISTINCT * FROM appearances)
GROUP BY address, block_number, transaction_index;
COMMIT;