Skip to content

Commit 516476c

Browse files
committed
fix hardcoded pgschema
1 parent b4f79b8 commit 516476c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

migo.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (o Options) WithPgSchema(pgschema string) *Options {
4141
}
4242

4343
var dbClient *gorm.DB
44-
var schemaname string
44+
var schemaname string
4545

4646
var (
4747
errNoGormGooseMigrationTable error = errors.New("no gorm goose table found")
@@ -105,7 +105,6 @@ func NewID() string {
105105
return time.Now().Format("20060102150405")
106106
}
107107

108-
109108
func getGormGooseData() (gormGooseData, error) {
110109
ggd := gormGooseData{}
111110
var err error
@@ -135,7 +134,7 @@ func gormGooseMigrationTableExist() bool {
135134
func getLastGormGooseAppliedMigration() (string, error) {
136135
gm := gormMigration{}
137136

138-
result := dbClient.Raw("SELECT * FROM etainvoicing.migration_records WHERE id IN (SELECT MAX(id) FROM etainvoicing.migration_records GROUP BY version_id) AND is_applied = TRUE ORDER BY version_id DESC LIMIT 1;").Scan(&gm)
137+
result := dbClient.Raw(fmt.Sprintf("SELECT * FROM %s.migration_records WHERE id IN (SELECT MAX(id) FROM %s.migration_records GROUP BY version_id) AND is_applied = TRUE ORDER BY version_id DESC LIMIT 1;", schemaname, schemaname)).Scan(&gm)
139138
if errors.Is(result.Error, gorm.ErrRecordNotFound) || result.RowsAffected == 0 {
140139
return "", errNoAppliedMigrations
141140
}
@@ -148,7 +147,7 @@ func getLastGormGooseAppliedMigration() (string, error) {
148147
func getFirstGormGooseUnAppliedMigration() (string, error) {
149148
gm := gormMigration{}
150149

151-
result := dbClient.Raw("SELECT * FROM etainvoicing.migration_records WHERE id IN (SELECT MAX(id) FROM etainvoicing.migration_records GROUP BY version_id) AND is_applied = FALSE ORDER BY version_id LIMIT 1;").Scan(&gm)
150+
result := dbClient.Raw(fmt.Sprintf("SELECT * FROM %s.migration_records WHERE id IN (SELECT MAX(id) FROM %s.migration_records GROUP BY version_id) AND is_applied = FALSE ORDER BY version_id LIMIT 1;", schemaname, schemaname)).Scan(&gm)
152151
if errors.Is(result.Error, gorm.ErrRecordNotFound) || result.RowsAffected == 0 {
153152
return "", errNoUnAppliedMigrations
154153
}

0 commit comments

Comments
 (0)