From 92005c50904660ab392c0ee6d374248fba601deb Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Mon, 4 Apr 2022 16:13:37 +0200 Subject: [PATCH] Fix linter issues --- internal/sqlutil/migrate.go | 2 +- internal/sqlutil/migrate_test.go | 6 +++--- keyserver/storage/postgres/key_changes_table.go | 2 +- keyserver/storage/sqlite3/key_changes_table.go | 2 +- roomserver/storage/postgres/storage.go | 4 ++-- roomserver/storage/sqlite3/storage.go | 4 ++-- syncapi/storage/sqlite3/syncserver.go | 4 ++-- userapi/storage/sqlite3/devices_table.go | 5 ++++- 8 files changed, 16 insertions(+), 13 deletions(-) diff --git a/internal/sqlutil/migrate.go b/internal/sqlutil/migrate.go index d2e23155d..91dbb057e 100644 --- a/internal/sqlutil/migrate.go +++ b/internal/sqlutil/migrate.go @@ -130,7 +130,7 @@ func (m *Migrator) ExecutedMigrations(ctx context.Context) (map[string]bool, err defer rows.Close() // nolint: errcheck var version string for rows.Next() { - if err := rows.Scan(&version); err != nil { + if err = rows.Scan(&version); err != nil { return nil, fmt.Errorf("unable to scan version: %w", err) } result[version] = true diff --git a/internal/sqlutil/migrate_test.go b/internal/sqlutil/migrate_test.go index ac54687a4..3b00e9e6c 100644 --- a/internal/sqlutil/migrate_test.go +++ b/internal/sqlutil/migrate_test.go @@ -91,16 +91,16 @@ func Test_migrations_Up(t *testing.T) { t.Run(tt.name, func(t *testing.T) { db, err := sql.Open("sqlite3", tt.connectionString) if err != nil { - t.Errorf("unable to open database: %w", err) + t.Errorf("unable to open database: %v", err) } m := sqlutil.NewMigrator(db) m.AddMigrations(tt.migrations...) - if err := m.Up(tt.ctx); (err != nil) != tt.wantErr { + if err = m.Up(tt.ctx); (err != nil) != tt.wantErr { t.Errorf("Up() error = %v, wantErr %v", err, tt.wantErr) } result, err := m.ExecutedMigrations(tt.ctx) if err != nil { - t.Errorf("unable to get executed migrations: %w", err) + t.Errorf("unable to get executed migrations: %v", err) } if !tt.wantErr && !reflect.DeepEqual(result, tt.wantResult) { t.Errorf("expected: %+v, got %v", tt.wantResult, result) diff --git a/keyserver/storage/postgres/key_changes_table.go b/keyserver/storage/postgres/key_changes_table.go index b0eedf5a5..59946c663 100644 --- a/keyserver/storage/postgres/key_changes_table.go +++ b/keyserver/storage/postgres/key_changes_table.go @@ -61,7 +61,7 @@ func NewPostgresKeyChangesTable(db *sql.DB) (tables.KeyChanges, error) { return s, err } - // TODO: Remove when we are sure we are not having goose artifacts in the db + // 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 partition was removed from the table var count int diff --git a/keyserver/storage/sqlite3/key_changes_table.go b/keyserver/storage/sqlite3/key_changes_table.go index b783414f9..0e89174fa 100644 --- a/keyserver/storage/sqlite3/key_changes_table.go +++ b/keyserver/storage/sqlite3/key_changes_table.go @@ -58,7 +58,7 @@ func NewSqliteKeyChangesTable(db *sql.DB) (tables.KeyChanges, error) { if err != nil { return s, err } - // TODO: Remove when we are sure we are not having goose artifacts in the db + // 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 partition was removed from the table var count int diff --git a/roomserver/storage/postgres/storage.go b/roomserver/storage/postgres/storage.go index 703debbd4..5a113c229 100644 --- a/roomserver/storage/postgres/storage.go +++ b/roomserver/storage/postgres/storage.go @@ -44,13 +44,13 @@ func Open(dbProperties *config.DatabaseOptions, cache caching.RoomServerCaches) } // Create the tables. - if err := d.create(db); err != nil { + if err = d.create(db); err != nil { return nil, err } // Special case, since this migration uses several tables, so it needs to // be sure that all tables are created first. - // TODO: Remove when we are sure we are not having goose artifacts in the db + // 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 var count int diff --git a/roomserver/storage/sqlite3/storage.go b/roomserver/storage/sqlite3/storage.go index dbf402af9..c60577df6 100644 --- a/roomserver/storage/sqlite3/storage.go +++ b/roomserver/storage/sqlite3/storage.go @@ -52,13 +52,13 @@ func Open(dbProperties *config.DatabaseOptions, cache caching.RoomServerCaches) db.SetMaxOpenConns(20) // Create the tables. - if err := d.create(db); err != nil { + if err = d.create(db); err != nil { return nil, err } // Special case, since this migration uses several tables, so it needs to // be sure that all tables are created first. - // TODO: Remove when we are sure we are not having goose artifacts in the db + // 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 var count int diff --git a/syncapi/storage/sqlite3/syncserver.go b/syncapi/storage/sqlite3/syncserver.go index 15b99bc80..a362e14c7 100644 --- a/syncapi/storage/sqlite3/syncserver.go +++ b/syncapi/storage/sqlite3/syncserver.go @@ -41,13 +41,13 @@ func NewDatabase(dbProperties *config.DatabaseOptions) (*SyncServerDatasource, e return nil, err } d.writer = sqlutil.NewExclusiveWriter() - if err = d.prepare(dbProperties); err != nil { + if err = d.prepare(); err != nil { return nil, err } return &d, nil } -func (d *SyncServerDatasource) prepare(dbProperties *config.DatabaseOptions) (err error) { +func (d *SyncServerDatasource) prepare() (err error) { if err = d.streamID.prepare(d.db); err != nil { return err } diff --git a/userapi/storage/sqlite3/devices_table.go b/userapi/storage/sqlite3/devices_table.go index f214d5161..a12087959 100644 --- a/userapi/storage/sqlite3/devices_table.go +++ b/userapi/storage/sqlite3/devices_table.go @@ -113,7 +113,10 @@ func NewSQLiteDevicesTable(db *sql.DB, serverName gomatrixserverlib.ServerName) Version: "add last_seen_ts", Up: deltas.UpLastSeenTSIP, }) - err = m.Up(context.Background()) + if err = m.Up(context.Background()); err != nil { + return nil, err + } + return s, sqlutil.StatementList{ {&s.insertDeviceStmt, insertDeviceSQL}, {&s.selectDevicesCountStmt, selectDevicesCountSQL},