Fail to start if we get a non-uniqueconstraint error

This commit is contained in:
Till Faelligen 2022-09-11 09:32:26 +02:00
parent 240d00e2b6
commit d7171e1483
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E
4 changed files with 6 additions and 15 deletions

View file

@ -18,8 +18,7 @@ import (
"context" "context"
"database/sql" "database/sql"
"errors" "errors"
"fmt"
"github.com/sirupsen/logrus"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/dendrite/internal/sqlutil"
@ -81,8 +80,7 @@ func executeMigration(ctx context.Context, db *sql.DB) error {
if err != nil { if err != nil {
if errors.Is(err, sql.ErrNoRows) { // migration was already executed, as the column was removed if errors.Is(err, sql.ErrNoRows) { // migration was already executed, as the column was removed
if err = sqlutil.InsertMigration(ctx, db, migrationName); err != nil { if err = sqlutil.InsertMigration(ctx, db, migrationName); err != nil {
// not a fatal error, log and continue return fmt.Errorf("unable to manually insert migration '%s': %w", migrationName, err)
logrus.WithError(err).Warnf("unable to manually insert migration '%s'", migrationName)
} }
return nil return nil
} }

View file

@ -18,8 +18,7 @@ import (
"context" "context"
"database/sql" "database/sql"
"errors" "errors"
"fmt"
"github.com/sirupsen/logrus"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/dendrite/internal/sqlutil"
@ -80,8 +79,7 @@ func executeMigration(ctx context.Context, db *sql.DB) error {
if err != nil { if err != nil {
if errors.Is(err, sql.ErrNoRows) { // migration was already executed, as the column was removed if errors.Is(err, sql.ErrNoRows) { // migration was already executed, as the column was removed
if err = sqlutil.InsertMigration(ctx, db, migrationName); err != nil { if err = sqlutil.InsertMigration(ctx, db, migrationName); err != nil {
// not a fatal error, log and continue return fmt.Errorf("unable to manually insert migration '%s': %w", migrationName, err)
logrus.WithError(err).Warnf("unable to manually insert migration '%s'", migrationName)
} }
return nil return nil
} }

View file

@ -21,8 +21,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/sirupsen/logrus"
// Import the postgres database driver. // Import the postgres database driver.
_ "github.com/lib/pq" _ "github.com/lib/pq"
@ -79,8 +77,7 @@ func executeMigration(ctx context.Context, db *sql.DB) error {
if err != nil { if err != nil {
if errors.Is(err, sql.ErrNoRows) { // migration was already executed, as the column was removed if errors.Is(err, sql.ErrNoRows) { // migration was already executed, as the column was removed
if err = sqlutil.InsertMigration(ctx, db, migrationName); err != nil { if err = sqlutil.InsertMigration(ctx, db, migrationName); err != nil {
// not a fatal error, log and continue return fmt.Errorf("unable to manually insert migration '%s': %w", migrationName, err)
logrus.WithError(err).Warnf("unable to manually insert migration '%s'", migrationName)
} }
return nil return nil
} }

View file

@ -22,7 +22,6 @@ import (
"fmt" "fmt"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/sirupsen/logrus"
"github.com/matrix-org/dendrite/internal/caching" "github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/dendrite/internal/sqlutil"
@ -87,8 +86,7 @@ func executeMigration(ctx context.Context, db *sql.DB) error {
if err != nil { if err != nil {
if errors.Is(err, sql.ErrNoRows) { // migration was already executed, as the column was removed if errors.Is(err, sql.ErrNoRows) { // migration was already executed, as the column was removed
if err = sqlutil.InsertMigration(ctx, db, migrationName); err != nil { if err = sqlutil.InsertMigration(ctx, db, migrationName); err != nil {
// not a fatal error, log and continue return fmt.Errorf("unable to manually insert migration '%s': %w", migrationName, err)
logrus.WithError(err).Warnf("unable to manually insert migration '%s'", migrationName)
} }
return nil return nil
} }