Skip to content

Commit ee8b407

Browse files
authored
Merge pull request #835 from input-output-hk/jpraynaud/817-adapt-certificate-table
Create/Migrate `certificate`store
2 parents fb6ee10 + 4744084 commit ee8b407

File tree

7 files changed

+822
-11
lines changed

7 files changed

+822
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.2.40"
3+
version = "0.2.41"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/database/migration.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,68 @@ insert into signed_entity_type (signed_entity_type_id, name)
6666
values (0, 'Mithril Stake Distribution'),
6767
(1, 'Cardano Stake Distribution'),
6868
(2, 'Full Cardano Immutable Files');
69+
"#,
70+
),
71+
// Migration 4
72+
// Add the new `certificate` table and migrate data from its previous version.
73+
SqlMigration::new(
74+
4,
75+
r#"
76+
create table if not exists certificate (key_hash text primary key, key json not null, value json not null);
77+
alter table certificate rename to certificate_temp;
78+
create table certificate (
79+
certificate_id text not null,
80+
parent_certificate_id text,
81+
message text not null,
82+
signature text not null,
83+
aggregate_verification_key text not null,
84+
epoch integer not null,
85+
beacon json not null,
86+
protocol_version text not null,
87+
protocol_parameters json not null,
88+
protocol_message json not null,
89+
signers json not null,
90+
initiated_at text not null default current_timestamp,
91+
sealed_at text not null default current_timestamp,
92+
primary key (certificate_id),
93+
foreign key (parent_certificate_id) references certificate(certificate_id)
94+
);
95+
insert into certificate (certificate_id,
96+
parent_certificate_id,
97+
message,
98+
signature,
99+
aggregate_verification_key,
100+
epoch,
101+
beacon,
102+
protocol_version,
103+
protocol_parameters,
104+
protocol_message,
105+
signers,
106+
initiated_at,
107+
sealed_at)
108+
select
109+
json_extract(c.value, '$.hash') as certificate_id,
110+
case
111+
when json_extract(c.value, '$.multi_signature') <> '' then json_extract(c.value, '$.previous_hash')
112+
else NULL
113+
end as parent_certificate_id,
114+
json_extract(c.value, '$.signed_message') as message,
115+
case
116+
when json_extract(c.value, '$.multi_signature') <> '' then json_extract(c.value, '$.multi_signature')
117+
else json_extract(c.value, '$.genesis_signature')
118+
end as signature,
119+
json_extract(c.value, '$.aggregate_verification_key') as aggregate_verification_key,
120+
json_extract(c.value, '$.beacon.epoch') as epoch,
121+
json(json_extract(c.value, '$.beacon')) as beacon,
122+
json_extract(c.value, '$.metadata.version') as protocol_version,
123+
json(json_extract(c.value, '$.metadata.parameters')) as protocol_parameters,
124+
json(json_extract(c.value, '$.protocol_message')) as protocol_message,
125+
json(json_extract(c.value, '$.metadata.signers')) as signers,
126+
json_extract(c.value, '$.metadata.initiated_at') as initiated_at,
127+
json_extract(c.value, '$.metadata.sealed_at') as sealed_at
128+
from certificate_temp as c;
129+
create index epoch_index ON certificate(epoch);
130+
drop table certificate_temp;
69131
"#,
70132
),
71133
]

0 commit comments

Comments
 (0)