Skip to content

Commit 1dd289b

Browse files
authored
Merge pull request #826 from input-output-hk/jpraynaud/813-adapt-epoch-settings-table
Create/Migrate `epoch settings` store
2 parents 04693e2 + 43a418c commit 1dd289b

File tree

6 files changed

+653
-32
lines changed

6 files changed

+653
-32
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.39"
3+
version = "0.2.40"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/database/migration.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ use mithril_common::database::SqlMigration;
66
/// There shall be one migration per database version. There could be several
77
/// statements per migration.
88
pub fn get_migrations() -> Vec<SqlMigration> {
9-
vec![SqlMigration::new(
10-
1,
11-
r#"
9+
vec![
10+
// Migration 1
11+
// Add the `stake_pool` table and migration data from the previous
12+
// `stake_store` JSON format.
13+
SqlMigration::new(
14+
1,
15+
r#"
1216
create table stake_pool (
1317
stake_pool_id text not null,
1418
epoch integer not null,
15-
stake integer not null,
19+
stake integer not null,
1620
created_at text not null default current_timestamp,
1721
primary key (epoch, stake_pool_id)
1822
);
@@ -26,5 +30,27 @@ insert into stake_pool (epoch, stake_pool_id, stake)
2630
order by epoch asc;
2731
drop table stake;
2832
"#,
29-
)]
33+
),
34+
// Migration 2
35+
// Add the `epoch_setting` table and migration data from the previous
36+
// `protocol_parameters` JSON format.
37+
SqlMigration::new(
38+
2,
39+
r#"
40+
create table epoch_setting (
41+
epoch_setting_id integer not null,
42+
protocol_parameters json not null,
43+
primary key (epoch_setting_id)
44+
);
45+
create table if not exists protocol_parameters (key_hash text primary key, key json not null, value json not null);
46+
insert into epoch_setting (epoch_setting_id, protocol_parameters)
47+
select
48+
protocol_parameters.key as epoch_setting_id,
49+
protocol_parameters.value as protocol_parameters
50+
from protocol_parameters
51+
order by key asc;
52+
drop table protocol_parameters;
53+
"#,
54+
),
55+
]
3056
}

0 commit comments

Comments
 (0)