Skip to content

Commit 6ac2e39

Browse files
committed
migration
1 parent 0d048da commit 6ac2e39

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
CREATE TABLE channels
22
(
3-
channel_id VARCHAR(66) NOT NULL,
3+
id VARCHAR(66) NOT NULL,
44
creator VARCHAR(255) NOT NULL,
55
deposit_asset VARCHAR(42) NOT NULL,
66
deposit_amount VARCHAR(255) NOT NULL, -- @TODO change the deposit to BigNum compatible field
77
valid_until TIMESTAMP WITH TIME ZONE NOT NULL,
88
spec JSONB NOT NULL,
99

10-
PRIMARY KEY (channel_id)
10+
PRIMARY KEY (id)
1111
);
1212

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'));
1515

1616
CREATE TABLE validator_messages
1717
(
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,
2222

2323
PRIMARY KEY (channel_id)
2424
);
2525

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'));
2929

3030
CREATE TABLE event_aggregates
3131
(
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,
3535

3636
PRIMARY KEY (channel_id)
3737
);
3838

39-
CREATE INDEX idx_created ON event_aggregates(created);
39+
CREATE INDEX idx_created ON event_aggregates (created);

sentry/src/middleware/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub async fn get_channel(
2525
pool
2626
.run(move |connection| {
2727
async move {
28-
match connection.prepare("SELECT channel_id, creator, deposit_asset, deposit_amount, valid_until, spec FROM channels WHERE channel_id = $1 LIMIT 1").await {
28+
match connection.prepare("SELECT id, creator, deposit_asset, deposit_amount, valid_until, spec FROM channels WHERE id = $1 LIMIT 1").await {
2929
Ok(select) => match connection.query(&select, &[&id]).await {
3030
Ok(results) => Ok(( results.get(0).map(Channel::from) , connection)),
3131
Err(e) => Err((e, connection)),

0 commit comments

Comments
 (0)