Skip to content

Commit 1419d03

Browse files
committed
Migrate 'signed_entity' table
1 parent d1c6af7 commit 1419d03

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

mithril-aggregator/src/database/migration.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,37 @@ insert into signer_registration (signer_id,
187187
left join stake_pool on stake_pool.stake_pool_id = verification_key_signer.key and stake_pool.epoch = verification_key.key
188188
order by verification_key.key, verification_key_signer.key asc;
189189
drop table verification_key;
190+
"#,
191+
),
192+
// Migration 7
193+
// Add the `signed_entity` table and migration data from the previous
194+
// `snapshot` JSON format.
195+
SqlMigration::new(
196+
7,
197+
r#"
198+
create table signed_entity (
199+
signed_entity_id text not null,
200+
signed_entity_type_id integer not null,
201+
certificate_id text not null,
202+
entity json not null,
203+
created_at text not null default current_timestamp,
204+
primary key (signed_entity_id)
205+
foreign key (signed_entity_type_id) references signed_entity_type(signed_entity_type_id)
206+
foreign key (certificate_id) references certificate(certificate_id)
207+
);
208+
create table if not exists snapshot (key_hash text primary key, key json not null, value json not null);
209+
insert into signed_entity (signed_entity_id,
210+
signed_entity_type_id,
211+
certificate_id,
212+
entity)
213+
select
214+
json_extract(snapshot.value, '$.digest') as signed_entity_id,
215+
2 as signed_entity_type_id,
216+
json_extract(snapshot.value, '$.certificate_hash') as certificate_id,
217+
snapshot.value as entity
218+
from snapshot
219+
order by ROWID asc;
220+
drop table snapshot;
190221
"#,
191222
),
192223
]

0 commit comments

Comments
 (0)