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.
This commit is contained in:
Viktor Torstensson 2025-07-24 13:33:48 +02:00
parent 1f9c32df93
commit ee4a1e338b
No known key found for this signature in database
GPG key ID: 961CC8259AE675D4

31
db/sql_migrations.go Normal file
View file

@ -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}
)