migration/
lib.rs

1pub use sea_orm_migration::prelude::*;
2
3mod m20240226_000001_index_create_channel;
4mod m20240226_000002_index_create_account;
5mod m20240226_000003_index_create_network_registry;
6mod m20240226_000004_index_create_node_info;
7mod m20240226_000005_index_create_chain_info;
8mod m20240226_000006_index_create_network_eligibility;
9mod m20240226_000007_index_initial_seed;
10mod m20240226_000008_node_create_settings;
11mod m20240226_000009_peers_create_peer_store;
12mod m20240301_000010_tickets_create_ticket;
13mod m20240301_000011_tickets_create_ticket_stats;
14mod m20240301_000012_tickets_create_outgoing_ticket_index;
15mod m20240404_000013_tickets_recreate_ticket;
16mod m20240810_000014_index_extend_chain_info_with_pre_checksum_block;
17mod m20240917_000015_add_minimum_incoming_ticket_win_prob_column;
18mod m20240926_000016_peers_create_peer_store_with_new_sea_orm;
19mod m20240930_000017_logs_create_log;
20mod m20241112_000018_logs_add_index;
21mod m20250107_000019_logs_meta_table;
22mod m20250219_000020_logs_add_index;
23mod m20250219_000021_channels_add_index;
24mod m20250419_000022_account_add_published_block;
25mod m20250528_000023_peers_reset;
26mod m20250603_000024_index_reset;
27mod m20250603_000025_peers_reset;
28mod m20250603_000026_logs_reset;
29mod m20250604_000027_index_initial_seed;
30mod m20250701_000028_peers_deprecate_fields;
31mod m20250709_000029_channels_add_corrupted_state;
32mod m20250808_000030_index_create_corrupted_channel;
33mod m20250909_000031_peer_store_add_indices;
34
35#[derive(PartialEq)]
36pub enum BackendType {
37    SQLite,
38    Postgres,
39}
40
41pub struct Migrator;
42
43/// Used to instantiate all tables to generate the corresponding entities in
44/// a non-SQLite database (such as Postgres).
45#[async_trait::async_trait]
46impl MigratorTrait for Migrator {
47    fn migrations() -> Vec<Box<dyn MigrationTrait>> {
48        vec![
49            Box::new(m20240226_000001_index_create_channel::Migration),
50            Box::new(m20240226_000002_index_create_account::Migration),
51            Box::new(m20240226_000003_index_create_network_registry::Migration),
52            Box::new(m20240226_000004_index_create_node_info::Migration),
53            Box::new(m20240226_000005_index_create_chain_info::Migration),
54            Box::new(m20240226_000006_index_create_network_eligibility::Migration),
55            Box::new(m20240226_000007_index_initial_seed::Migration),
56            Box::new(m20240226_000008_node_create_settings::Migration),
57            Box::new(m20240226_000009_peers_create_peer_store::Migration),
58            Box::new(m20240301_000010_tickets_create_ticket::Migration(BackendType::Postgres)),
59            Box::new(m20240301_000011_tickets_create_ticket_stats::Migration(
60                BackendType::Postgres,
61            )),
62            Box::new(m20240301_000012_tickets_create_outgoing_ticket_index::Migration(
63                BackendType::Postgres,
64            )),
65            Box::new(m20240404_000013_tickets_recreate_ticket::Migration(
66                BackendType::Postgres,
67            )),
68            Box::new(m20240810_000014_index_extend_chain_info_with_pre_checksum_block::Migration),
69            Box::new(m20240917_000015_add_minimum_incoming_ticket_win_prob_column::Migration),
70            Box::new(m20240926_000016_peers_create_peer_store_with_new_sea_orm::Migration(
71                BackendType::Postgres,
72            )),
73            Box::new(m20240930_000017_logs_create_log::Migration),
74            Box::new(m20241112_000018_logs_add_index::Migration),
75            Box::new(m20250107_000019_logs_meta_table::Migration),
76            Box::new(m20250219_000020_logs_add_index::Migration),
77            Box::new(m20250219_000021_channels_add_index::Migration),
78            Box::new(m20250419_000022_account_add_published_block::Migration),
79            Box::new(m20250528_000023_peers_reset::Migration),
80            Box::new(m20250603_000024_index_reset::Migration),
81            Box::new(m20250603_000025_peers_reset::Migration),
82            Box::new(m20250603_000026_logs_reset::Migration),
83            Box::new(m20250604_000027_index_initial_seed::Migration),
84            Box::new(m20250709_000029_channels_add_corrupted_state::Migration),
85            Box::new(m20250808_000030_index_create_corrupted_channel::Migration),
86            Box::new(m20250909_000031_peer_store_add_indices::Migration),
87        ]
88    }
89}
90
91/// SQLite does not allow writing lock tables only, and the write lock
92/// will apply to the entire database file. It is therefore beneficial
93/// to separate the exclusive concurrently accessing components into
94/// separate database files to benefit from multiple write locks over
95/// different parts of the database.
96pub struct MigratorIndex;
97
98#[async_trait::async_trait]
99impl MigratorTrait for MigratorIndex {
100    fn migrations() -> Vec<Box<dyn MigrationTrait>> {
101        vec![
102            Box::new(m20240226_000001_index_create_channel::Migration),
103            Box::new(m20240226_000002_index_create_account::Migration),
104            Box::new(m20240226_000003_index_create_network_registry::Migration),
105            Box::new(m20240226_000004_index_create_node_info::Migration),
106            Box::new(m20240226_000005_index_create_chain_info::Migration),
107            Box::new(m20240226_000006_index_create_network_eligibility::Migration),
108            Box::new(m20240226_000008_node_create_settings::Migration),
109            Box::new(m20240226_000007_index_initial_seed::Migration),
110            Box::new(m20240810_000014_index_extend_chain_info_with_pre_checksum_block::Migration),
111            Box::new(m20240917_000015_add_minimum_incoming_ticket_win_prob_column::Migration),
112            Box::new(m20250219_000021_channels_add_index::Migration),
113            Box::new(m20250419_000022_account_add_published_block::Migration),
114            Box::new(m20250603_000024_index_reset::Migration),
115            Box::new(m20250604_000027_index_initial_seed::Migration),
116            Box::new(m20250709_000029_channels_add_corrupted_state::Migration),
117            Box::new(m20250808_000030_index_create_corrupted_channel::Migration),
118        ]
119    }
120}
121
122pub struct MigratorPeers;
123
124#[async_trait::async_trait]
125impl MigratorTrait for MigratorPeers {
126    fn migrations() -> Vec<Box<dyn MigrationTrait>> {
127        vec![
128            Box::new(m20240226_000009_peers_create_peer_store::Migration),
129            Box::new(m20240926_000016_peers_create_peer_store_with_new_sea_orm::Migration(
130                BackendType::SQLite,
131            )),
132            Box::new(m20250528_000023_peers_reset::Migration),
133            Box::new(m20250603_000025_peers_reset::Migration),
134            Box::new(m20250701_000028_peers_deprecate_fields::Migration(BackendType::SQLite)),
135            Box::new(m20250909_000031_peer_store_add_indices::Migration),
136        ]
137    }
138}
139
140pub struct MigratorTickets;
141
142#[async_trait::async_trait]
143impl MigratorTrait for MigratorTickets {
144    fn migrations() -> Vec<Box<dyn MigrationTrait>> {
145        vec![
146            Box::new(m20240301_000010_tickets_create_ticket::Migration(BackendType::SQLite)),
147            Box::new(m20240301_000011_tickets_create_ticket_stats::Migration(
148                BackendType::SQLite,
149            )),
150            Box::new(m20240301_000012_tickets_create_outgoing_ticket_index::Migration(
151                BackendType::SQLite,
152            )),
153            Box::new(m20240404_000013_tickets_recreate_ticket::Migration(BackendType::SQLite)),
154        ]
155    }
156}
157
158/// The logs are kept separate from the rest of the database to allow for
159/// easier export of the logs themselves and also to not block any other database operations
160/// made by the node at runtime.
161pub struct MigratorChainLogs;
162
163#[async_trait::async_trait]
164impl MigratorTrait for MigratorChainLogs {
165    fn migrations() -> Vec<Box<dyn MigrationTrait>> {
166        vec![
167            Box::new(m20240930_000017_logs_create_log::Migration),
168            Box::new(m20241112_000018_logs_add_index::Migration),
169            Box::new(m20250107_000019_logs_meta_table::Migration),
170            Box::new(m20250219_000020_logs_add_index::Migration),
171            Box::new(m20250603_000026_logs_reset::Migration),
172        ]
173    }
174}