mirror of
https://github.com/usememos/memos.git
synced 2025-10-12 07:16:06 +08:00
fix: migration always in mysql (#2353)
This commit is contained in:
parent
dfaf2ee29c
commit
b2aa66b4fd
1 changed files with 25 additions and 0 deletions
|
@ -30,6 +30,31 @@ func (d *DB) Migrate(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DB) nonProdMigrate(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)
|
buf, err := migrationFS.ReadFile("migration/dev/" + latestSchemaFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Errorf("failed to read latest schema file: %s", err)
|
return errors.Errorf("failed to read latest schema file: %s", err)
|
||||||
|
|
Loading…
Add table
Reference in a new issue