From d27bcca3e9f66f3e9c195de5c612dd0505f8ec88 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 8 Nov 2022 13:37:47 +0000 Subject: [PATCH] Tweak migrations again --- userapi/storage/postgres/storage.go | 19 ++++++++++++------- userapi/storage/sqlite3/storage.go | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/userapi/storage/postgres/storage.go b/userapi/storage/postgres/storage.go index c7342616a..31c4f019c 100644 --- a/userapi/storage/postgres/storage.go +++ b/userapi/storage/postgres/storage.go @@ -45,13 +45,6 @@ func NewDatabase(base *base.BaseDendrite, dbProperties *config.DatabaseOptions, Up: deltas.UpRenameTables, Down: deltas.DownRenameTables, }) - m.AddMigrations(sqlutil.Migration{ - Version: "userapi: server names", - Up: func(ctx context.Context, txn *sql.Tx) error { - return deltas.UpServerNames(ctx, txn, serverName) - }, - Down: deltas.DownServerNames, - }) if err = m.Up(base.Context()); err != nil { return nil, err } @@ -105,6 +98,18 @@ func NewDatabase(base *base.BaseDendrite, dbProperties *config.DatabaseOptions, return nil, fmt.Errorf("NewPostgresStatsTable: %w", err) } + m = sqlutil.NewMigrator(db) + m.AddMigrations(sqlutil.Migration{ + Version: "userapi: server names", + Up: func(ctx context.Context, txn *sql.Tx) error { + return deltas.UpServerNames(ctx, txn, serverName) + }, + Down: deltas.DownServerNames, + }) + if err = m.Up(base.Context()); err != nil { + return nil, err + } + return &shared.Database{ AccountDatas: accountDataTable, Accounts: accountsTable, diff --git a/userapi/storage/sqlite3/storage.go b/userapi/storage/sqlite3/storage.go index 2c1c2cab2..b3b3231d2 100644 --- a/userapi/storage/sqlite3/storage.go +++ b/userapi/storage/sqlite3/storage.go @@ -43,13 +43,6 @@ func NewDatabase(base *base.BaseDendrite, dbProperties *config.DatabaseOptions, Up: deltas.UpRenameTables, Down: deltas.DownRenameTables, }) - m.AddMigrations(sqlutil.Migration{ - Version: "userapi: server names", - Up: func(ctx context.Context, txn *sql.Tx) error { - return deltas.UpServerNames(ctx, txn, serverName) - }, - Down: deltas.DownServerNames, - }) if err = m.Up(base.Context()); err != nil { return nil, err } @@ -103,6 +96,18 @@ func NewDatabase(base *base.BaseDendrite, dbProperties *config.DatabaseOptions, return nil, fmt.Errorf("NewSQLiteStatsTable: %w", err) } + m = sqlutil.NewMigrator(db) + m.AddMigrations(sqlutil.Migration{ + Version: "userapi: server names", + Up: func(ctx context.Context, txn *sql.Tx) error { + return deltas.UpServerNames(ctx, txn, serverName) + }, + Down: deltas.DownServerNames, + }) + if err = m.Up(base.Context()); err != nil { + return nil, err + } + return &shared.Database{ AccountDatas: accountDataTable, Accounts: accountsTable,