Skip to content

Commit fbee82e

Browse files
committed
Fix gochan-migrate not running if DBprefix is empty
1 parent 82825c6 commit fbee82e

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

cmd/gochan-migration/internal/common/sqlutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
var (
1919
CommentRemover = regexp.MustCompile("--.*\n?")
20-
ErrNotInstalled = errors.New("database is empty, run gochan to install and initialize it")
20+
ErrNotInstalled = errors.New("database is empty or corrupted (missing tables), run gochan to install and initialize it")
2121
)
2222

2323
// ColumnType returns a string representation of the column's data type. It does not return an error

cmd/gochan-migration/internal/gcupdate/gcupdate.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ func (dbu *GCDatabaseUpdater) MigrateDB() (migrated bool, err error) {
5656
gcsql.SetDB(dbu.db)
5757

5858
sqlConfig := config.GetSQLConfig()
59-
prefixedTablesExist, err := gcsql.DoesGochanPrefixTableExist()
59+
var gochanTablesExist bool
60+
if sqlConfig.DBprefix == "" {
61+
gochanTablesExist, err = common.TableExists(context.Background(), dbu.db, nil, "database_version", &sqlConfig)
62+
} else {
63+
gochanTablesExist, err = gcsql.DoesGochanPrefixTableExist()
64+
}
6065
if err != nil {
6166
return false, err
6267
}
63-
if !prefixedTablesExist {
68+
if !gochanTablesExist {
6469
return false, common.ErrNotInstalled
6570
}
6671

0 commit comments

Comments
 (0)