|
1 | 1 | CREATE TABLE channels
|
2 | 2 | (
|
3 |
| - channel_id VARCHAR(66) NOT NULL, |
| 3 | + id VARCHAR(66) NOT NULL, |
4 | 4 | creator VARCHAR(255) NOT NULL,
|
5 | 5 | deposit_asset VARCHAR(42) NOT NULL,
|
6 | 6 | deposit_amount VARCHAR(255) NOT NULL, -- @TODO change the deposit to BigNum compatible field
|
7 | 7 | valid_until TIMESTAMP WITH TIME ZONE NOT NULL,
|
8 | 8 | spec JSONB NOT NULL,
|
9 | 9 |
|
10 |
| - PRIMARY KEY (channel_id) |
| 10 | + PRIMARY KEY (id) |
11 | 11 | );
|
12 | 12 |
|
13 |
| -CREATE INDEX idx_valid_until ON channels(valid_until); |
14 |
| -CREATE INDEX idx_spec ON channels((spec->'validator'->>'id')); |
| 13 | +CREATE INDEX idx_valid_until ON channels (valid_until); |
| 14 | +CREATE INDEX idx_spec ON channels ((spec -> 'validator' ->> 'id')); |
15 | 15 |
|
16 | 16 | CREATE TABLE validator_messages
|
17 | 17 | (
|
18 |
| - channel_id VARCHAR(66) NOT NULL, |
19 |
| - "from" VARCHAR(255) NOT NULL, |
20 |
| - msg JSONB NOT NULL, |
21 |
| - received TIMESTAMP WITH TIME ZONE NOT NULL, |
| 18 | + channel_id VARCHAR(66) NOT NULL REFERENCES channels (id) ON DELETE RESTRICT, |
| 19 | + "from" VARCHAR(255) NOT NULL, |
| 20 | + msg JSONB NOT NULL, |
| 21 | + received TIMESTAMP WITH TIME ZONE NOT NULL, |
22 | 22 |
|
23 | 23 | PRIMARY KEY (channel_id)
|
24 | 24 | );
|
25 | 25 |
|
26 |
| -CREATE INDEX idx_received ON validator_messages(received); |
27 |
| -CREATE INDEX ON validator_messages((msg->>'type')); |
28 |
| -CREATE INDEX ON validator_messages((msg->>'stateRoot')); |
| 26 | +CREATE INDEX idx_received ON validator_messages (received); |
| 27 | +CREATE INDEX ON validator_messages ((msg ->> 'type')); |
| 28 | +CREATE INDEX ON validator_messages ((msg ->> 'stateRoot')); |
29 | 29 |
|
30 | 30 | CREATE TABLE event_aggregates
|
31 | 31 | (
|
32 |
| - channel_id VARCHAR(66) NOT NULL, |
33 |
| - created TIMESTAMP WITH TIME ZONE NOT NULL, |
34 |
| - events JSONB NOT NULL, |
| 32 | + channel_id VARCHAR(66) NOT NULL REFERENCES channels (id) ON DELETE RESTRICT, |
| 33 | + created TIMESTAMP WITH TIME ZONE NOT NULL, |
| 34 | + events JSONB NOT NULL, |
35 | 35 |
|
36 | 36 | PRIMARY KEY (channel_id)
|
37 | 37 | );
|
38 | 38 |
|
39 |
| -CREATE INDEX idx_created ON event_aggregates(created); |
| 39 | +CREATE INDEX idx_created ON event_aggregates (created); |
0 commit comments