mirror of
https://github.com/writeas/writefreely
synced 2025-01-20 23:37:34 +01:00
Run migrations on db initialization
This makes it so we can keep all schema changes in the `migrations` module, instead of adding them there *and* in the schema files. It fixes #92 and should prevent these kinds of issues in the future.
This commit is contained in:
parent
c08484aa9c
commit
771c7acf5f
8
app.go
8
app.go
@ -637,12 +637,18 @@ func adminInitDatabase(app *app) error {
|
||||
}
|
||||
|
||||
// Set up migrations table
|
||||
log.Info("Updating appmigrations table...")
|
||||
log.Info("Initializing appmigrations table...")
|
||||
err = migrations.SetInitialMigrations(migrations.NewDatastore(app.db.DB, app.db.driverName))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to set initial migrations: %v", err)
|
||||
}
|
||||
|
||||
log.Info("Running migrations...")
|
||||
err = migrations.Migrate(migrations.NewDatastore(app.db.DB, app.db.driverName))
|
||||
if err != nil {
|
||||
return fmt.Errorf("migrate: %s", err)
|
||||
}
|
||||
|
||||
log.Info("Done.")
|
||||
return nil
|
||||
}
|
||||
|
@ -65,7 +65,8 @@ func CurrentVer() int {
|
||||
}
|
||||
|
||||
func SetInitialMigrations(db *datastore) error {
|
||||
_, err := db.Exec("INSERT INTO appmigrations (version, migrated, result) VALUES (?, "+db.now()+", ?)", CurrentVer(), "")
|
||||
// Included schema files represent changes up to V1, so note that in the database
|
||||
_, err := db.Exec("INSERT INTO appmigrations (version, migrated, result) VALUES (?, "+db.now()+", ?)", 1, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user