Skip to content

Commit d204fa4

Browse files
committed
[bug]: don't warn user about existing bbolt DB if SQLite files exist
1 parent cb481df commit d204fa4

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

lncfg/db.go

+41-5
Original file line numberDiff line numberDiff line change
@@ -738,12 +738,48 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
738738
// warnExistingBoltDBs checks if there is an existing bbolt database in the
739739
// given location and logs a warning if so.
740740
func warnExistingBoltDBs(log btclog.Logger, dbType, dir, fileName string) {
741-
if lnrpc.FileExists(filepath.Join(dir, fileName)) {
742-
log.Warnf("Found existing bbolt database file in %s/%s while "+
743-
"using database type %s. Existing data will NOT be "+
744-
"migrated to %s automatically!", dir, fileName, dbType,
745-
dbType)
741+
// Check if the bbolt file exists
742+
bboltPath := filepath.Join(dir, fileName)
743+
if !lnrpc.FileExists(bboltPath) {
744+
// No bbolt file, no need for warning
745+
return
746746
}
747+
748+
// Determine the corresponding SQLite file name based on the bbolt file
749+
var sqliteFileName string
750+
switch fileName {
751+
case WalletDBName:
752+
sqliteFileName = SqliteChainDBName
753+
case ChannelDBName:
754+
sqliteFileName = SqliteChannelDBName
755+
case MacaroonDBName:
756+
sqliteFileName = SqliteChainDBName
757+
case DecayedLogDbName:
758+
sqliteFileName = SqliteChannelDBName
759+
case TowerClientDBName:
760+
sqliteFileName = SqliteChannelDBName
761+
case TowerServerDBName:
762+
sqliteFileName = SqliteTowerDBName
763+
default:
764+
// For any other file types, still show the warning
765+
log.Warnf("Found existing bbolt database file in %s/%s "+
766+
"while using database type %s. Existing data will "+
767+
"NOT be migrated to %s automatically!",
768+
dir, fileName, dbType, dbType)
769+
770+
return
771+
}
772+
773+
// Check if the corresponding SQLite file exists
774+
sqlitePath := filepath.Join(dir, sqliteFileName)
775+
if !lnrpc.FileExists(sqlitePath) {
776+
// SQLite file doesn't exist, show the warning
777+
log.Warnf("Found existing bbolt database file in %s/%s "+
778+
"while using database type %s. Existing data will "+
779+
"NOT be migrated to %s automatically!",
780+
dir, fileName, dbType, dbType)
781+
}
782+
// If SQLite file exists, don't show the warning
747783
}
748784

749785
// Compile-time constraint to ensure Workers implements the Validator interface.

0 commit comments

Comments
 (0)