update db-move to support migration version 14
This commit is contained in:
parent
e50f392288
commit
8458f63316
2 changed files with 40 additions and 36 deletions
|
@ -17,6 +17,8 @@ import (
|
|||
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||
)
|
||||
|
||||
const expectedMigrationVersion = "14"
|
||||
|
||||
var (
|
||||
sqlitePath string
|
||||
postgresURL string
|
||||
|
@ -166,7 +168,7 @@ var (
|
|||
|
||||
func verifyMigration(source *sql.DB) error {
|
||||
// Lower bound of the database state.
|
||||
rows, err := source.Query("SELECT * FROM flyway_schema_history WHERE version = 12")
|
||||
rows, err := source.Query("SELECT version FROM flyway_schema_history ORDER BY installed_rank DESC LIMIT 1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -176,16 +178,16 @@ func verifyMigration(source *sql.DB) error {
|
|||
return errors.New("source database is not up to date! Please update signald and start it to move the sqlite database to an acceptable format")
|
||||
}
|
||||
|
||||
// Upper bound of the database state
|
||||
rows, err = source.Query("SELECT * FROM flyway_schema_history WHERE version = 13")
|
||||
var version string
|
||||
err = rows.Scan(&version)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
if rows.Next() {
|
||||
return errors.New("source database is too new! Please update signaldctl to the latest version")
|
||||
if version != expectedMigrationVersion {
|
||||
return fmt.Errorf("source database must be on migration %s (found %s instead)", expectedMigrationVersion, version)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -235,7 +237,7 @@ func moveAccounts(source *sql.DB, dest *sql.DB) error {
|
|||
}
|
||||
|
||||
func moveRecipients(source *sql.DB, dest *sql.DB) error {
|
||||
rows, err := source.Query("SELECT rowid, account_uuid, uuid, e164 FROM recipients")
|
||||
rows, err := source.Query("SELECT rowid, account_uuid, uuid, e164, registered FROM recipients")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -247,8 +249,9 @@ func moveRecipients(source *sql.DB, dest *sql.DB) error {
|
|||
accountUUID uuid.UUID
|
||||
recipientUUID uuid.NullUUID
|
||||
e164 sql.NullString
|
||||
registered bool
|
||||
)
|
||||
err = rows.Scan(&rowID, &accountUUID, &recipientUUID, &e164)
|
||||
err = rows.Scan(&rowID, &accountUUID, &recipientUUID, &e164, ®istered)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -259,7 +262,7 @@ func moveRecipients(source *sql.DB, dest *sql.DB) error {
|
|||
e164.String = ""
|
||||
}
|
||||
|
||||
_, err = dest.Exec("INSERT INTO signald_recipients (rowid, account_uuid, uuid, e164) VALUES ($1, $2, $3, $4)", rowID, accountUUID, recipientUUID, e164)
|
||||
_, err = dest.Exec("INSERT INTO signald_recipients (rowid, account_uuid, uuid, e164, registered) VALUES ($1, $2, $3, $4, $5)", rowID, accountUUID, recipientUUID, e164, registered)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -107,6 +107,7 @@ var (
|
|||
account_uuid UUID NOT NULL REFERENCES signald_accounts(uuid) ON DELETE CASCADE,
|
||||
uuid UUID,
|
||||
e164 TEXT,
|
||||
registered BOOLEAN DEFAULT true,
|
||||
|
||||
UNIQUE (account_uuid, e164, uuid)
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue