mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-12-11 21:32:06 +01:00
lnd: plug in graph SQL migration into dev build
This commit plugs in the graph kvdb-to-sql migration for builds containing the `test_native_sql` tag. This will allow us to perform local tests and write itests for the migration without exposing it to the production release build.
This commit is contained in:
@@ -3,11 +3,15 @@
|
||||
package lnd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
"github.com/lightningnetwork/lnd/sqldb"
|
||||
"github.com/lightningnetwork/lnd/sqldb/sqlc"
|
||||
)
|
||||
|
||||
// getGraphStore returns a graphdb.V1Store backed by a graphdb.SQLStore
|
||||
@@ -29,3 +33,32 @@ func (d *DefaultDatabaseBuilder) getGraphStore(baseDB *sqldb.BaseDB,
|
||||
graphExecutor, opts...,
|
||||
)
|
||||
}
|
||||
|
||||
// graphSQLMigration is the version number for the graph migration
|
||||
// that migrates the KV graph to the native SQL schema.
|
||||
const graphSQLMigration = 9
|
||||
|
||||
// getSQLMigration returns a migration function for the given version.
|
||||
func getSQLMigration(ctx context.Context, version int,
|
||||
kvBackend kvdb.Backend,
|
||||
chain chainhash.Hash) (func(tx *sqlc.Queries) error, bool) {
|
||||
|
||||
switch version {
|
||||
case graphSQLMigration:
|
||||
return func(tx *sqlc.Queries) error {
|
||||
err := graphdb.MigrateGraphToSQL(
|
||||
ctx, kvBackend, tx, chain,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to migrate graph "+
|
||||
"to SQL: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}, true
|
||||
}
|
||||
|
||||
// No version was matched, so we return false to indicate that no
|
||||
// migration is known for the given version.
|
||||
return nil, false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user