aboutsummaryrefslogtreecommitdiff
path: root/roomserver
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2022-08-08 10:18:57 +0200
committerGitHub <noreply@github.com>2022-08-08 10:18:57 +0200
commit03ddd98f5e6582f5aacaee643ddd53506ccfec50 (patch)
tree723a0c4fca6e9fd71c408a378a14d54b7ebc6884 /roomserver
parent10a151cb55ba925c3ece2026c65cb8e57207bf46 (diff)
Fix issues with migrations not getting executed (#2628)
* Fix issues with migrations not getting executed * Check actual postgres error * Return error if it's not "column does not exist"
Diffstat (limited to 'roomserver')
-rw-r--r--roomserver/storage/postgres/storage.go19
-rw-r--r--roomserver/storage/sqlite3/storage.go10
2 files changed, 22 insertions, 7 deletions
diff --git a/roomserver/storage/postgres/storage.go b/roomserver/storage/postgres/storage.go
index 4c271ea9..f47a64c8 100644
--- a/roomserver/storage/postgres/storage.go
+++ b/roomserver/storage/postgres/storage.go
@@ -19,8 +19,10 @@ import (
"database/sql"
"fmt"
+ "github.com/lib/pq"
// Import the postgres database driver.
_ "github.com/lib/pq"
+
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/roomserver/storage/postgres/deltas"
@@ -53,21 +55,32 @@ func Open(base *base.BaseDendrite, dbProperties *config.DatabaseOptions, cache c
// TODO: Remove when we are sure we are not having goose artefacts in the db
// This forces an error, which indicates the migration is already applied, since the
// column event_nid was removed from the table
- err = db.QueryRow("SELECT event_nid FROM roomserver_state_block LIMIT 1;").Scan()
+ var eventNID int
+ err = db.QueryRow("SELECT event_nid FROM roomserver_state_block LIMIT 1;").Scan(&eventNID)
if err == nil {
m := sqlutil.NewMigrator(db)
m.AddMigrations(sqlutil.Migration{
Version: "roomserver: state blocks refactor",
Up: deltas.UpStateBlocksRefactor,
})
- if err := m.Up(base.Context()); err != nil {
+ if err = m.Up(base.Context()); err != nil {
+ return nil, err
+ }
+ } else {
+ switch e := err.(type) {
+ case *pq.Error:
+ // ignore undefined_column (42703) errors, as this is expected at this point
+ if e.Code != "42703" {
+ return nil, err
+ }
+ default:
return nil, err
}
}
// Then prepare the statements. Now that the migrations have run, any columns referred
// to in the database code should now exist.
- if err := d.prepare(db, writer, cache); err != nil {
+ if err = d.prepare(db, writer, cache); err != nil {
return nil, err
}
diff --git a/roomserver/storage/sqlite3/storage.go b/roomserver/storage/sqlite3/storage.go
index bb9c15b5..9f8a1b11 100644
--- a/roomserver/storage/sqlite3/storage.go
+++ b/roomserver/storage/sqlite3/storage.go
@@ -20,6 +20,8 @@ import (
"database/sql"
"fmt"
+ "github.com/matrix-org/gomatrixserverlib"
+
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/roomserver/storage/shared"
@@ -27,7 +29,6 @@ import (
"github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/dendrite/setup/base"
"github.com/matrix-org/dendrite/setup/config"
- "github.com/matrix-org/gomatrixserverlib"
)
// A Database is used to store room events and stream offsets.
@@ -63,21 +64,22 @@ func Open(base *base.BaseDendrite, dbProperties *config.DatabaseOptions, cache c
// TODO: Remove when we are sure we are not having goose artefacts in the db
// This forces an error, which indicates the migration is already applied, since the
// column event_nid was removed from the table
- err = db.QueryRow("SELECT event_nid FROM roomserver_state_block LIMIT 1;").Scan()
+ var eventNID int
+ err = db.QueryRow("SELECT event_nid FROM roomserver_state_block LIMIT 1;").Scan(&eventNID)
if err == nil {
m := sqlutil.NewMigrator(db)
m.AddMigrations(sqlutil.Migration{
Version: "roomserver: state blocks refactor",
Up: deltas.UpStateBlocksRefactor,
})
- if err := m.Up(base.Context()); err != nil {
+ if err = m.Up(base.Context()); err != nil {
return nil, err
}
}
// Then prepare the statements. Now that the migrations have run, any columns referred
// to in the database code should now exist.
- if err := d.prepare(db, writer, cache); err != nil {
+ if err = d.prepare(db, writer, cache); err != nil {
return nil, err
}