mithril_persistence/database/
cardano_transaction_migration.rs1use crate::database::SqlMigration;
4
5pub fn get_migrations() -> Vec<SqlMigration> {
9 vec![
10 SqlMigration::new(
13 1,
14 r#"
15create table cardano_tx (
16 transaction_hash text not null,
17 block_number integer not null,
18 immutable_file_number integer not null,
19 primary key (transaction_hash)
20);
21
22create unique index cardano_tx_immutable_file_number_index on cardano_tx(immutable_file_number);
23"#,
24 ),
25 SqlMigration::new(
28 2,
29 r#"
30-- remove all data from the cardano tx table since a lot of transactions where missing for each
31-- block and we rely on their insert order.
32delete from cardano_tx;
33
34drop index cardano_tx_immutable_file_number_index;
35create index cardano_tx_immutable_file_number_index on cardano_tx(immutable_file_number);
36
37vacuum;
38"#,
39 ),
40 SqlMigration::new(
43 3,
44 r#"
45-- remove all data from the cardano tx table since the new columns are mandatory
46delete from cardano_tx;
47
48alter table cardano_tx add column slot_number integer not null;
49alter table cardano_tx add column block_hash text not null;
50
51vacuum;
52 "#,
53 ),
54 SqlMigration::new(
57 4,
58 r#"
59create index block_number_index on cardano_tx(block_number);
60"#,
61 ),
62 SqlMigration::new(
65 5,
66 r#"
67create table block_range_root (
68 start integer not null,
69 end integer not null,
70 merkle_root text not null,
71 primary key (start, end)
72);
73"#,
74 ),
75 SqlMigration::new(
79 6,
80 r#"
81create index block_number_transaction_hash_index on cardano_tx(block_number, transaction_hash);
82
83-- remove all data from the block_range_root table since the order used to create them has changed
84delete from block_range_root;
85
86vacuum;
87"#,
88 ),
89 SqlMigration::new(
94 7,
95 r#"
96-- 'pragma auto_vacuum = full' can't be applied to an existing database, so we need to recreate
97-- the database by using 'vacuum'.
98pragma auto_vacuum = full;
99vacuum;
100"#,
101 ),
102 SqlMigration::new(
105 8,
106 r#"
107drop index cardano_tx_immutable_file_number_index;
108alter table cardano_tx drop column immutable_file_number;
109 "#,
110 ),
111 SqlMigration::new(
115 9,
116 r#"
117delete from cardano_tx;
118delete from block_range_root;
119vacuum;
120 "#,
121 ),
122 ]
123}