@@ -3,6 +3,7 @@ package lncfg
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "os"
6
7
"path"
7
8
"path/filepath"
8
9
"time"
@@ -68,6 +69,10 @@ const (
68
69
69
70
// NSNeutrinoDB is the namespace name that we use for the neutrino DB.
70
71
NSNeutrinoDB = "neutrinodb"
72
+
73
+ // MigrationMarkerFile is a marker file created by lndinit migrate-db
74
+ // that indicates successful database migration.
75
+ MigrationMarkerFile = ".migration-complete"
71
76
)
72
77
73
78
// DB holds database configuration for LND.
@@ -484,6 +489,13 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
484
489
warnExistingBoltDBs (
485
490
logger , "postgres" , chanDBPath , ChannelDBName ,
486
491
)
492
+ // Also check for macaroons.db and sphinxreplay.db bbolt files
493
+ warnExistingBoltDBs (
494
+ logger , "postgres" , walletDBPath , MacaroonDBName ,
495
+ )
496
+ warnExistingBoltDBs (
497
+ logger , "postgres" , chanDBPath , DecayedLogDbName ,
498
+ )
487
499
488
500
returnEarly = false
489
501
@@ -599,14 +611,29 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
599
611
closeFuncs [SqliteBackend ] = nativeSQLiteStore .Close
600
612
}
601
613
602
- // Warn if the user is trying to switch over to a sqlite DB
603
- // while there is a wallet or channel bbolt DB still present.
604
- warnExistingBoltDBs (
605
- logger , "sqlite" , walletDBPath , WalletDBName ,
606
- )
607
- warnExistingBoltDBs (
608
- logger , "sqlite" , chanDBPath , ChannelDBName ,
609
- )
614
+ // Check if migration has been completed before warning about
615
+ // existing bbolt databases
616
+ migrationComplete := hasMigrationCompleted (walletDBPath ) ||
617
+ hasMigrationCompleted (chanDBPath )
618
+
619
+ // Only show warnings if migration hasn't been completed
620
+ if ! migrationComplete {
621
+ // Warn if the user is trying to switch over to a sqlite DB
622
+ // while there is a wallet or channel bbolt DB still present.
623
+ warnExistingBoltDBs (
624
+ logger , "sqlite" , walletDBPath , WalletDBName ,
625
+ )
626
+ warnExistingBoltDBs (
627
+ logger , "sqlite" , chanDBPath , ChannelDBName ,
628
+ )
629
+ // Also check for macaroons.db and sphinxreplay.db bbolt files
630
+ warnExistingBoltDBs (
631
+ logger , "sqlite" , walletDBPath , MacaroonDBName ,
632
+ )
633
+ warnExistingBoltDBs (
634
+ logger , "sqlite" , chanDBPath , DecayedLogDbName ,
635
+ )
636
+ }
610
637
611
638
returnEarly = false
612
639
@@ -735,51 +762,39 @@ func (db *DB) GetBackends(ctx context.Context, chanDBPath,
735
762
}, nil
736
763
}
737
764
738
- // warnExistingBoltDBs checks if there is an existing bbolt database in the
739
- // given location and logs a warning if so.
740
- func warnExistingBoltDBs (log btclog.Logger , dbType , dir , fileName string ) {
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
765
+ // hasMigrationCompleted checks if migration has been completed by looking for
766
+ // SQLite files with substantial size or a migration marker file.
767
+ func hasMigrationCompleted (dbPath string ) bool {
768
+ // Check for marker file (which lndinit could create after migration)
769
+ markerPath := filepath .Join (dbPath , MigrationMarkerFile )
770
+ if _ , err := os .Stat (markerPath ); err == nil {
771
+ return true
746
772
}
747
773
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
774
+ // Check for non-empty SQLite files
775
+ sqliteFiles := []string {SqliteChainDBName , SqliteChannelDBName }
776
+ for _ , fileName := range sqliteFiles {
777
+ filePath := filepath .Join (dbPath , fileName )
778
+ fileInfo , err := os .Stat (filePath )
779
+
780
+ // If file exists and has substantial size (not just created empty)
781
+ if err == nil && fileInfo .Size () > 1024 {
782
+ return true
783
+ }
771
784
}
785
+
786
+ return false
787
+ }
772
788
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 )
789
+ // warnExistingBoltDBs checks if there is an existing bbolt database in the
790
+ // given location and logs a warning if so.
791
+ func warnExistingBoltDBs ( log btclog. Logger , dbType , dir , fileName string ) {
792
+ if lnrpc . FileExists ( filepath . Join ( dir , fileName )) {
793
+ log .Warnf ("Found existing bbolt database file in %s/%s while " +
794
+ "using database type %s. Existing data will NOT be " +
795
+ "migrated to %s automatically!" , dir , fileName , dbType ,
796
+ dbType )
781
797
}
782
- // If SQLite file exists, don't show the warning
783
798
}
784
799
785
800
// Compile-time constraint to ensure Workers implements the Validator interface.
0 commit comments