fix exported field

move-migrations-to-option v0.1.1
Mason Payne 2024-08-22 00:47:04 -06:00
parent e5725dc249
commit c70325c8c9
3 changed files with 8 additions and 8 deletions

10
db.go
View File

@ -58,10 +58,10 @@ func (t *LibSqlDB) Migrate() error {
// check if migration table exists
var migrationsCheck string
//goland:noinspection SqlResolve
err := t.db.QueryRow("SELECT name FROM sqlite_master WHERE type='table' AND name='migrations'").Scan(&migrationsCheck)
err := t.DB.QueryRow("SELECT name FROM sqlite_master WHERE type='table' AND name='migrations'").Scan(&migrationsCheck)
if err != nil {
if err == sql.ErrNoRows {
_, err := t.db.Exec("CREATE TABLE migrations (name TEXT NOT NULL)")
_, err := t.DB.Exec("CREATE TABLE migrations (name TEXT NOT NULL)")
if err != nil {
return fmt.Errorf("error creating migrations table | %w", err)
}
@ -72,14 +72,14 @@ func (t *LibSqlDB) Migrate() error {
for _, migration := range migrations {
var migrationInHistory string
err = t.db.QueryRow("SELECT name FROM migrations WHERE name = ?", migration.name).Scan(&migrationInHistory)
err = t.DB.QueryRow("SELECT name FROM migrations WHERE name = ?", migration.name).Scan(&migrationInHistory)
if err != nil {
if err == sql.ErrNoRows {
_, err := t.db.Exec(migration.query)
_, err := t.DB.Exec(migration.query)
if err != nil {
return fmt.Errorf("error running migration: %s | %w", migration.name, err)
}
_, err = t.db.Exec("INSERT INTO migrations (name) VALUES (?)", migration.name)
_, err = t.DB.Exec("INSERT INTO migrations (name) VALUES (?)", migration.name)
if err != nil {
return fmt.Errorf("error inserting migration: %s into migrations table | %w", migration.name, err)
}

View File

@ -76,7 +76,7 @@ func NewLibSqlDB(primaryUrl string, migrationFiles embed.FS, opts ...Options) (*
return nil, fmt.Errorf("error setting up migrations | %w", err)
}
l.db = db
l.DB = db
l.connector = connector
l.dir = dir

View File

@ -51,14 +51,14 @@ func NewLibSqlDB(primaryUrl string, migrationFiles embed.FS, opts ...Options) (*
}
return &LibSqlDB{
db: db,
DB: db,
}, nil
}
func (t *LibSqlDB) Close() error {
var resultError *multierror.Error
if err := t.db.Close(); err != nil {
if err := t.DB.Close(); err != nil {
resultError = multierror.Append(resultError, fmt.Errorf("failed to close database: %w", err))
}