Skip to content

Commit 6fb4fe2

Browse files
committed
fix: migrations to respect sqlite
1 parent 5971679 commit 6fb4fe2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

storage/sql.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ func (s *SQLAdapter) CreateSchema() error {
124124
}
125125
return nil
126126
}
127+
127128
func (s *SQLAdapter) CreateMigrationTable() error {
128129
var statement string
129130
switch s.GetProvider() {
@@ -139,6 +140,7 @@ func (s *SQLAdapter) CreateMigrationTable() error {
139140
return s.Execute(statement)
140141

141142
}
143+
142144
func (s *SQLAdapter) UpdateMigrationTable(id int, name string, desc string) error {
143145
var statement string
144146
switch s.GetProvider() {
@@ -150,15 +152,25 @@ func (s *SQLAdapter) UpdateMigrationTable(id int, name string, desc string) erro
150152
return s.Execute(statement)
151153

152154
}
155+
153156
func (s *SQLAdapter) GetLatestMigration() (int, error) {
154157
var statement string
155158
var latestMigration int
156-
statement = fmt.Sprintf("SELECT max(id) from %s.migrations", s.GetSchemaName())
159+
var fromSource string
160+
switch s.GetProvider() {
161+
case SQLITE:
162+
fromSource = "migrations"
163+
default:
164+
fromSource = fmt.Sprintf("%s.migrations", s.GetSchemaName())
165+
166+
}
167+
168+
statement = fmt.Sprintf("SELECT max(id) from %s", fromSource)
157169
result := s.DB.Raw(statement).Scan(&latestMigration)
158170
if result.Error != nil {
159171
//either a real issue or there are no migrations yet check if we can query the migration table
160172
var count int
161-
statement = fmt.Sprintf("SELECT count(*) from %s.migrations", s.GetSchemaName())
173+
statement = fmt.Sprintf("SELECT count(*) from %s", fromSource)
162174
countResult := s.DB.Raw(statement).Scan(&count)
163175
if countResult.Error != nil {
164176
return latestMigration, result.Error

0 commit comments

Comments
 (0)