refactor: Update internal/db and oplog to use go-dbw package for database operations. (#1785)
* chore: Add new dbw dependency * refactor: Convert to use dbw.DB * refactor (db): Change GetTicket(...) signature * feature (db tests): Added TestDeleteWhere(...) Adding this allows us to eliminate a leak of the gorm library * refactor: Add ctx to ScanRows(...) signature This is required to refactor all the deprecated errors pkg calls. This refactor required adding a context to quite a few call chains and in particular the job scheduler bits * feature (db/tests): Add support for test opt: WithTestLogLevel(...) This test only option allows callers to specify a log level for the underlying db package (where supported/applicable) when calling TestSetup(...) * refactor (db): Simplify Db type Only store the underlying *DB and create the *RW on demand when needed. * refactor (oplog): Port to using dbw pkg for db operations * refactor (db): Remove gormDB(...) func * tests (db): Add unit tests for TestDeleteWhere(...) * chore: make fmt changes to formatting
This commit is contained in:
160 files changed
+4369
-3164
No files matched your search
@@ -115,7 +115,7 @@ type testModel struct {
|
||||
func (*testModel) TableName() string { return "test_table_dbasserts" }
|
||||
|
||||
// CreateTestModel is a helper that creates a testModel in the DB.
|
||||
func createTestModel(t dbassert.TestingT, db *db.DB, nullable *string, typeInt *int) *testModel {
|
||||
func createTestModel(t dbassert.TestingT, d *db.DB, nullable *string, typeInt *int) *testModel {
|
||||
publicId, err := base62.Random(12)
|
||||
assert.NoError(t, err)
|
||||
m := testModel{
|
||||
@@ -123,12 +123,12 @@ func createTestModel(t dbassert.TestingT, db *db.DB, nullable *string, typeInt *
|
||||
Nullable: nullable,
|
||||
TypeInt: typeInt,
|
||||
}
|
||||
err = db.Create(&m).Error
|
||||
assert.NoError(t, err)
|
||||
rw := db.New(d)
|
||||
require.NoError(t, rw.Create(context.Background(), &m))
|
||||
return &m
|
||||
}
|
||||
|
||||
func initStore(t *testing.T, db *db.DB) {
|
||||
func initStore(t *testing.T, d *db.DB) {
|
||||
t.Helper()
|
||||
const (
|
||||
createDomainType = `
|
||||
@@ -150,6 +150,11 @@ comment on table test_table_dbasserts is
|
||||
'dbasserts test table'
|
||||
`
|
||||
)
|
||||
require.NoError(t, db.Exec(createDomainType).Error)
|
||||
require.NoError(t, db.Exec(createTable).Error)
|
||||
rw := db.New(d)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := rw.Exec(ctx, createDomainType, nil)
|
||||
require.NoError(t, err)
|
||||
_, err = rw.Exec(ctx, createTable, nil)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
Reference in new issue
Block a user