Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

fix: migration always in mysql (#2353)

Athurg Goothb2aa66b4fd48
diff --git a/store/db/mysql/migrator.go b/store/db/mysql/migrator.go
index f947ea981..6b5c049b6 100644
--- a/store/db/mysql/migrator.go
+++ b/store/db/mysql/migrator.go
@@ -30,6 +30,31 @@ func (d *DB) Migrate(ctx context.Context) error {
}
func (d *DB) nonProdMigrate(ctx context.Context) error {
+ rows, err := d.db.QueryContext(ctx, "SHOW TABLES")
+ if err != nil {
+ return errors.Errorf("failed to query database tables: %s", err)
+ }
+ if rows.Err() != nil {
+ return errors.Errorf("failed to query database tables: %s", err)
+ }
+ defer rows.Close()
+
+ var tables []string
+ for rows.Next() {
+ var table string
+ err := rows.Scan(&table)
+ if err != nil {
+ return errors.Errorf("failed to scan table name: %s", err)
+ }
+ tables = append(tables, table)
+ }
+
+ if len(tables) != 0 {
+ return nil
+ }
+
+ println("no tables in the database. start migration")
+
buf, err := migrationFS.ReadFile("migration/dev/" + latestSchemaFileName)
if err != nil {
return errors.Errorf("failed to read latest schema file: %s", err)