From ee4a1e338bbad1da37dfeb5d61b6c4c3ebc6f0d7 Mon Sep 17 00:00:00 2001 From: Viktor Torstensson Date: Thu, 24 Jul 2025 13:33:48 +0200 Subject: [PATCH] db: add `LitdMigrationStream` A core component of `sqldb/v2` useage, is that the package allows and requires that the callsite defines a `sqldb.MigrationStream` that will be run during the initialization of the `sqldb/v2 database instance. The `sqldb.MigrationStream` defines the exact sql migrations to run, as well as additional code migrations will be run after each individual migration version. This commit introduces the core definition of the migration stream for `litd`, and will be further exteded in upcoming commits that will introduce kvdb to sql code migration. Note that as of this commit, as no part of the `litd` codebase uses the `sqldb/v2` database instances, this migration stream is not yet used. --- db/sql_migrations.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 db/sql_migrations.go diff --git a/db/sql_migrations.go b/db/sql_migrations.go new file mode 100644 index 00000000..34f0959b --- /dev/null +++ b/db/sql_migrations.go @@ -0,0 +1,31 @@ +package db + +import ( + "github.com/golang-migrate/migrate/v4" + "github.com/golang-migrate/migrate/v4/database/pgx/v5" + "github.com/lightningnetwork/lnd/sqldb/v2" +) + +var ( + // LitdMigrationStream defines the SQL migration stream used to create + // and upgrade LiT's SQL schema. + LitdMigrationStream = sqldb.MigrationStream{ + TrackingTableName: pgx.DefaultMigrationsTable, + SQLFileDirectory: "sqlc/migrations", + SQLFiles: sqlSchemas, + + // LatestMigrationVersion is the latest migration version of the + // database. This is used to implement downgrade protection for + // the daemon. + // + // NOTE: This MUST be updated when a new migration is added. + LatestMigrationVersion: LatestMigrationVersion, + + MakeProgrammaticMigrations: func(db *sqldb.BaseDB) ( + map[uint]migrate.ProgrammaticMigrEntry, error) { + + return make(map[uint]migrate.ProgrammaticMigrEntry), nil + }, + } + LitdMigrationStreams = []sqldb.MigrationStream{LitdMigrationStream} +)