]> git.bitcoin.ninja Git - rapid-gossip-sync-server/commitdiff
Correct upgrade logic to ignore missing indexes 2023-07-further-opt
authorMatt Corallo <git@bluematt.me>
Sun, 16 Jul 2023 17:25:10 +0000 (17:25 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 16 Jul 2023 17:25:10 +0000 (17:25 +0000)
If we upgrade multiple versions in one go, the indexes we're trying
to drop may not exist, and that shouldn't cause us to fail to
upgrade.

src/config.rs

index 6249940138c758575484e0249869a3ababdd683a..b0e3a7ce7722dafb236001df3e6bb46a1f6a60f7 100644 (file)
@@ -213,31 +213,31 @@ pub(crate) async fn upgrade_db(schema: i32, client: &mut tokio_postgres::Client)
        }
        if schema >= 1 && schema <= 7 {
                let tx = client.transaction().await.unwrap();
-               tx.execute("DROP INDEX channels_seen", &[]).await.unwrap();
-               tx.execute("DROP INDEX channel_updates_scid", &[]).await.unwrap();
-               tx.execute("DROP INDEX channel_updates_direction", &[]).await.unwrap();
-               tx.execute("DROP INDEX channel_updates_seen", &[]).await.unwrap();
-               tx.execute("DROP INDEX channel_updates_scid_seen", &[]).await.unwrap();
-               tx.execute("DROP INDEX channel_updates_scid_dir_seen", &[]).await.unwrap();
+               tx.execute("DROP INDEX IF EXISTS channels_seen", &[]).await.unwrap();
+               tx.execute("DROP INDEX IF EXISTS channel_updates_scid", &[]).await.unwrap();
+               tx.execute("DROP INDEX IF EXISTS channel_updates_direction", &[]).await.unwrap();
+               tx.execute("DROP INDEX IF EXISTS channel_updates_seen", &[]).await.unwrap();
+               tx.execute("DROP INDEX IF EXISTS channel_updates_scid_seen", &[]).await.unwrap();
+               tx.execute("DROP INDEX IF EXISTS channel_updates_scid_dir_seen", &[]).await.unwrap();
                tx.execute("UPDATE config SET db_schema = 8 WHERE id = 1", &[]).await.unwrap();
                tx.commit().await.unwrap();
        }
        if schema >= 1 && schema <= 8 {
                let tx = client.transaction().await.unwrap();
-               tx.execute("DROP INDEX channel_updates_seen", &[]).await.unwrap();
-               tx.execute("DROP INDEX channel_updates_scid_seen", &[]).await.unwrap();
+               tx.execute("DROP INDEX IF EXISTS channel_updates_seen", &[]).await.unwrap();
+               tx.execute("DROP INDEX IF EXISTS channel_updates_scid_seen", &[]).await.unwrap();
                tx.execute("UPDATE config SET db_schema = 9 WHERE id = 1", &[]).await.unwrap();
                tx.commit().await.unwrap();
        }
        if schema >= 1 && schema <= 9 {
                let tx = client.transaction().await.unwrap();
-               tx.execute("DROP INDEX channel_updates_scid_dir_seen", &[]).await.unwrap();
+               tx.execute("DROP INDEX IF EXISTS channel_updates_scid_dir_seen", &[]).await.unwrap();
                tx.execute("UPDATE config SET db_schema = 10 WHERE id = 1", &[]).await.unwrap();
                tx.commit().await.unwrap();
        }
        if schema >= 1 && schema <= 10 {
                let tx = client.transaction().await.unwrap();
-               tx.execute("DROP INDEX channel_updates_id_with_scid_dir_blob", &[]).await.unwrap();
+               tx.execute("DROP INDEX IF EXISTS channel_updates_id_with_scid_dir_blob", &[]).await.unwrap();
                tx.execute("UPDATE config SET db_schema = 11 WHERE id = 1", &[]).await.unwrap();
                tx.commit().await.unwrap();
        }