]> git.bitcoin.ninja Git - rapid-gossip-sync-server/commitdiff
Add upgrade query support
authorMatt Corallo <git@bluematt.me>
Sun, 11 Sep 2022 16:41:12 +0000 (16:41 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 13 Sep 2022 16:17:40 +0000 (16:17 +0000)
src/config.rs
src/persistence.rs

index afc9871b5e8b0bc9d5c04582f9fc4c041992a2d9..e7ba89c329c605ab9a8b333307a9e58d7285080f 100644 (file)
@@ -84,6 +84,13 @@ pub(crate) fn db_index_creation_query() -> &'static str {
        "
 }
 
+pub(crate) async fn upgrade_db(schema: i32, client: &mut tokio_postgres::Client) {
+       match schema {
+               SCHEMA_VERSION => {},
+               _ => panic!("Unknown schema in db: {}, we support up to {}", schema, SCHEMA_VERSION),
+       }
+}
+
 /// EDIT ME
 pub(crate) fn ln_peers() -> Vec<(PublicKey, SocketAddr)> {
        vec![
index 00ca70d892aab814a32099870767f976276e74e5..d961b30ea19b19f7d0d7e7bdb1489419f4b5ee30 100644 (file)
@@ -27,7 +27,7 @@ impl GossipPersister {
 
        pub(crate) async fn persist_gossip(&mut self) {
                let connection_config = config::db_connection_config();
-               let (client, connection) =
+               let (mut client, connection) =
                        connection_config.connect(NoTls).await.unwrap();
 
                tokio::spawn(async move {
@@ -45,6 +45,11 @@ impl GossipPersister {
                                panic!("db init error: {}", initialization_error);
                        }
 
+                       let cur_schema = client.query("SELECT db_schema FROM config WHERE id = $1", &[&1]).await.unwrap();
+                       if !cur_schema.is_empty() {
+                               config::upgrade_db(cur_schema[0].get(0), &mut client).await;
+                       }
+
                        let initialization = client
                                .execute(
                                        // TODO: figure out a way to fix the id value without Postgres complaining about