@@ -15,7 +15,7 @@ use lightning::util::ser::Readable;
15
15
use lightning_block_sync:: http:: HttpEndpoint ;
16
16
use tokio_postgres:: Config ;
17
17
18
- pub ( crate ) const SCHEMA_VERSION : i32 = 12 ;
18
+ pub ( crate ) const SCHEMA_VERSION : i32 = 13 ;
19
19
pub ( crate ) const SYMLINK_GRANULARITY_INTERVAL : u32 = 3600 * 3 ; // three hours
20
20
pub ( crate ) const MAX_SNAPSHOT_SCOPE : u32 = 3600 * 24 * 21 ; // three weeks
21
21
// generate symlinks based on a 3-hour-granularity
@@ -143,7 +143,7 @@ pub(crate) fn db_index_creation_query() -> &'static str {
143
143
CREATE INDEX IF NOT EXISTS channel_updates_scid_dir_seen_desc_with_id ON channel_updates(short_channel_id ASC, direction ASC, seen DESC) INCLUDE (id);
144
144
CREATE UNIQUE INDEX IF NOT EXISTS channel_updates_key ON channel_updates (short_channel_id, direction, timestamp);
145
145
CREATE INDEX IF NOT EXISTS channel_updates_seen ON channel_updates(seen);
146
- CREATE INDEX IF NOT EXISTS channel_updates_timestamp_desc ON channel_updates(timestamp DESC);
146
+ CREATE INDEX IF NOT EXISTS channel_updates_scid_asc_timestamp_desc ON channel_updates(short_channel_id ASC, timestamp DESC);
147
147
"
148
148
}
149
149
@@ -282,6 +282,12 @@ pub(crate) async fn upgrade_db(schema: i32, client: &mut tokio_postgres::Client)
282
282
tx. execute ( "UPDATE config SET db_schema = 12 WHERE id = 1" , & [ ] ) . await . unwrap ( ) ;
283
283
tx. commit ( ) . await . unwrap ( ) ;
284
284
}
285
+ if schema >= 1 && schema <= 12 {
286
+ let tx = client. transaction ( ) . await . unwrap ( ) ;
287
+ tx. execute ( "DROP INDEX IF EXISTS channel_updates_timestamp_desc" , & [ ] ) . await . unwrap ( ) ;
288
+ tx. execute ( "UPDATE config SET db_schema = 13 WHERE id = 1" , & [ ] ) . await . unwrap ( ) ;
289
+ tx. commit ( ) . await . unwrap ( ) ;
290
+ }
285
291
if schema <= 1 || schema > SCHEMA_VERSION {
286
292
panic ! ( "Unknown schema in db: {}, we support up to {}" , schema, SCHEMA_VERSION ) ;
287
293
}
0 commit comments