db: make migrations a struct instead of a plain string
This commit is contained in:
@@ -50,13 +50,13 @@ func TestVerifyCorrectMigration(t *testing.T) {
|
||||
db1Schema := schema.SchemaFromDB(db1)
|
||||
|
||||
t.Run("migrate in 1 step", func(t *testing.T) {
|
||||
migration := `
|
||||
migration := db.Migration{ID: 1, SQL: `
|
||||
create table t2 (
|
||||
rowid integer primary key
|
||||
);
|
||||
alter table t1 add column data3 integer;
|
||||
`
|
||||
db2Config := db.Init(&baseSchema, &[]string{migration})
|
||||
`}
|
||||
db2Config := db.Init(&baseSchema, &[]db.Migration{migration})
|
||||
db2 := must.Get(db2Config.Create(":memory:"))
|
||||
require.NoError(t, db2Config.CheckAndUpdateVersion(db2))
|
||||
db2Schema := schema.SchemaFromDB(db2)
|
||||
@@ -67,16 +67,16 @@ func TestVerifyCorrectMigration(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("migrate in 2 steps", func(t *testing.T) {
|
||||
migration1 := `
|
||||
migration1 := db.Migration{ID: 1, SQL: `
|
||||
create table t2 (
|
||||
rowid integer primary key
|
||||
);
|
||||
`
|
||||
migration2 := `
|
||||
`}
|
||||
migration2 := db.Migration{ID: 2, SQL: `
|
||||
alter table t1 add column data3 integer;
|
||||
`
|
||||
`}
|
||||
|
||||
db2Config := db.Init(&baseSchema, &[]string{migration1, migration2})
|
||||
db2Config := db.Init(&baseSchema, &[]db.Migration{migration1, migration2})
|
||||
db2 := must.Get(db2Config.Create(":memory:"))
|
||||
require.NoError(t, db2Config.CheckAndUpdateVersion(db2))
|
||||
db2Schema := schema.SchemaFromDB(db2)
|
||||
@@ -92,7 +92,7 @@ func TestIncorrectMigrations(t *testing.T) {
|
||||
db1Schema := schema.SchemaFromDB(db1)
|
||||
|
||||
t.Run("missing migration", func(t *testing.T) {
|
||||
db2Config := db.Init(&baseSchema, &[]string{})
|
||||
db2Config := db.Init(&baseSchema, &[]db.Migration{})
|
||||
db2 := must.Get(db2Config.Create(":memory:"))
|
||||
require.NoError(t, db2Config.CheckAndUpdateVersion(db2))
|
||||
db2Schema := schema.SchemaFromDB(db2)
|
||||
@@ -109,11 +109,13 @@ func TestIncorrectMigrations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("incomplete migration", func(t *testing.T) {
|
||||
db2Config := db.Init(&baseSchema, &[]string{`
|
||||
db2Config := db.Init(&baseSchema, &[]db.Migration{
|
||||
{ID: 1, SQL: `
|
||||
create table t2 (
|
||||
rowid integer primary key
|
||||
);
|
||||
`})
|
||||
`},
|
||||
})
|
||||
db2 := must.Get(db2Config.Create(":memory:"))
|
||||
require.NoError(t, db2Config.CheckAndUpdateVersion(db2))
|
||||
db2Schema := schema.SchemaFromDB(db2)
|
||||
@@ -130,12 +132,14 @@ func TestIncorrectMigrations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("incorrect migration (wrong data type)", func(t *testing.T) {
|
||||
db2Config := db.Init(&baseSchema, &[]string{`
|
||||
create table t2 (
|
||||
rowid integer primary key
|
||||
);
|
||||
alter table t1 add column data3 text;
|
||||
`})
|
||||
db2Config := db.Init(&baseSchema, &[]db.Migration{
|
||||
{ID: 1, SQL: `
|
||||
create table t2 (
|
||||
rowid integer primary key
|
||||
);
|
||||
alter table t1 add column data3 text;
|
||||
`},
|
||||
})
|
||||
db2 := must.Get(db2Config.Create(":memory:"))
|
||||
require.NoError(t, db2Config.CheckAndUpdateVersion(db2))
|
||||
db2Schema := schema.SchemaFromDB(db2)
|
||||
|
||||
Reference in New Issue
Block a user