@@ -14,6 +14,7 @@ struct migration {
1414};
1515
1616static void migration_remove_dupe_lease_fees (struct plugin * p , struct db * db );
17+ static void migration_maybe_add_chainevents_spliced (struct plugin * p , struct db * db );
1718
1819/* Do not reorder or remove elements from this array.
1920 * It is used to migrate existing databases from a prevoius state, based on
@@ -100,7 +101,8 @@ static struct migration db_migrations[] = {
100101 {SQL ("ALTER TABLE channel_events ADD ev_desc TEXT DEFAULT NULL;" ), NULL },
101102 {SQL ("ALTER TABLE channel_events ADD rebalance_id BIGINT DEFAULT NULL;" ), NULL },
102103 {SQL ("ALTER TABLE chain_events ADD spliced INTEGER DEFAULT 0;" ), NULL },
103- {NULL , migration_remove_dupe_lease_fees }
104+ {NULL , migration_remove_dupe_lease_fees },
105+ {NULL , migration_maybe_add_chainevents_spliced }
104106};
105107
106108static bool db_migrate (struct plugin * p , struct db * db )
@@ -184,6 +186,27 @@ static void migration_remove_dupe_lease_fees(struct plugin *p, struct db *db)
184186 tal_free (stmt );
185187}
186188
189+ /* OK, funny story. We added the "ALTER TABLE chain_events ADD spliced INTEGER DEFAULT 0;"
190+ * migration in the wrong place, NOT at the end. So if you are migrating from an old version,
191+ * "migration_remove_dupe_lease_fees" ran (again), which is harmless, but this migration
192+ * never got added. */
193+ static void migration_maybe_add_chainevents_spliced (struct plugin * p , struct db * db )
194+ {
195+ struct db_stmt * stmt ;
196+ bool col_exists ;
197+
198+ stmt = db_prepare_v2 (db , SQL ("SELECT spliced FROM chain_events" ));
199+ col_exists = db_query_prepared_canfail (stmt );
200+ tal_free (stmt );
201+ if (col_exists )
202+ return ;
203+
204+ plugin_log (p , LOG_INFORM ,
205+ "Database fixup: adding spliced column to chain_events table" );
206+ stmt = db_prepare_v2 (db , SQL ("ALTER TABLE chain_events ADD spliced INTEGER DEFAULT 0;" ));
207+ db_exec_prepared_v2 (take (stmt ));
208+ }
209+
187210static void db_error (struct plugin * plugin , bool fatal , const char * fmt , va_list ap )
188211{
189212 if (fatal )
0 commit comments