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