sqldb: add new gossip v2 columns to graph tables
Add a new migration that updates the graph tables (nodes, channels and policies) in preparation for the new columns required for V2 announcements. This migration has to be added to the set of "live" migrations instead of "dev only" since it edits the columns of existing tables and so changes the existing sql models. We are going to prep the SQLStore code to handle the V2 types in the coming commits, so we need this migration to be in place. In this commit we also remove the TestSchemaMigrationIdempotency test since this test fails with the new "ALTER TABLE" migrations which dont have "IF NOT EXISTS" options like tables and indexes do. Migrations should be idempotent anyways due to the migration tracker file and/or the sqlc migration tracker.
This commit is contained in:
6 files changed
+140
-158
No files matched your search
@@ -452,132 +452,6 @@ func TestCustomMigration(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestSchemaMigrationIdempotency tests that the our schema migrations are
|
||||
// idempotent. This means that we can apply the migrations multiple times and
|
||||
// the schema version will always be the same.
|
||||
func TestSchemaMigrationIdempotency(t *testing.T) {
|
||||
dropMigrationTrackerEntries := func(t *testing.T, db *BaseDB) {
|
||||
_, err := db.Exec("DELETE FROM migration_tracker;")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
lastMigration := migrationConfig[len(migrationConfig)-1]
|
||||
|
||||
t.Run("SQLite", func(t *testing.T) {
|
||||
// First instantiate the database and run the migrations
|
||||
// including the custom migrations.
|
||||
t.Logf("Creating new SQLite DB for testing migrations")
|
||||
|
||||
dbFileName := filepath.Join(t.TempDir(), "tmp.db")
|
||||
var (
|
||||
db *SqliteStore
|
||||
err error
|
||||
)
|
||||
|
||||
// Run the migration 3 times to test that the migrations
|
||||
// are idempotent.
|
||||
for i := 0; i < 3; i++ {
|
||||
db, err = NewSqliteStore(&SqliteConfig{
|
||||
SkipMigrations: false,
|
||||
}, dbFileName)
|
||||
require.NoError(t, err)
|
||||
|
||||
dbToCleanup := db.DB
|
||||
t.Cleanup(func() {
|
||||
require.NoError(
|
||||
t, dbToCleanup.Close(),
|
||||
)
|
||||
})
|
||||
|
||||
ctxb := t.Context()
|
||||
require.NoError(
|
||||
t, db.ApplyAllMigrations(ctxb, GetMigrations()),
|
||||
)
|
||||
|
||||
version, dirty, err := db.GetSchemaVersion()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Now reset the schema version to 0 and make sure that
|
||||
// we can apply the migrations again.
|
||||
require.Equal(t, lastMigration.SchemaVersion, version)
|
||||
require.False(t, dirty)
|
||||
|
||||
require.NoError(
|
||||
t, db.SetSchemaVersion(
|
||||
database.NilVersion, false,
|
||||
),
|
||||
)
|
||||
dropMigrationTrackerEntries(t, db.BaseDB)
|
||||
|
||||
// Make sure that we reset the schema version.
|
||||
version, dirty, err = db.GetSchemaVersion()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, -1, version)
|
||||
require.False(t, dirty)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Postgres", func(t *testing.T) {
|
||||
// First create a temporary Postgres database to run
|
||||
// the migrations on.
|
||||
fixture := NewTestPgFixture(
|
||||
t, DefaultPostgresFixtureLifetime,
|
||||
)
|
||||
t.Cleanup(func() {
|
||||
fixture.TearDown(t)
|
||||
})
|
||||
|
||||
dbName := randomDBName(t)
|
||||
|
||||
// Next instantiate the database and run the migrations
|
||||
// including the custom migrations.
|
||||
t.Logf("Creating new Postgres DB '%s' for testing "+
|
||||
"migrations", dbName)
|
||||
|
||||
_, err := fixture.db.ExecContext(
|
||||
t.Context(), "CREATE DATABASE "+dbName,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg := fixture.GetConfig(dbName)
|
||||
var db *PostgresStore
|
||||
|
||||
// Run the migration 3 times to test that the migrations
|
||||
// are idempotent.
|
||||
for i := 0; i < 3; i++ {
|
||||
cfg.SkipMigrations = false
|
||||
db, err = NewPostgresStore(cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctxb := t.Context()
|
||||
require.NoError(
|
||||
t, db.ApplyAllMigrations(ctxb, GetMigrations()),
|
||||
)
|
||||
|
||||
version, dirty, err := db.GetSchemaVersion()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Now reset the schema version to 0 and make sure that
|
||||
// we can apply the migrations again.
|
||||
require.Equal(t, lastMigration.SchemaVersion, version)
|
||||
require.False(t, dirty)
|
||||
|
||||
require.NoError(
|
||||
t, db.SetSchemaVersion(
|
||||
database.NilVersion, false,
|
||||
),
|
||||
)
|
||||
dropMigrationTrackerEntries(t, db.BaseDB)
|
||||
|
||||
// Make sure that we reset the schema version.
|
||||
version, dirty, err = db.GetSchemaVersion()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, -1, version)
|
||||
require.False(t, dirty)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestMigrationBug19RC1 tests a bug that was present in the migration code
|
||||
// at the v0.19.0-rc1 release.
|
||||
// The bug was fixed in: https://github.com/lightningnetwork/lnd/pull/9647
|
||||
|
||||
Reference in new issue
Block a user