@@ -66,6 +66,68 @@ insert into signed_entity_type (signed_entity_type_id, name)
66
66
values (0, 'Mithril Stake Distribution'),
67
67
(1, 'Cardano Stake Distribution'),
68
68
(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;
69
131
"# ,
70
132
) ,
71
133
]
0 commit comments