diff --git a/app.go b/app.go index e286ef0..40f42c9 100644 --- a/app.go +++ b/app.go @@ -613,5 +613,15 @@ func adminInitDatabase(app *app) { log.Info("Created.") } } + + // Set up migrations table + log.Info("Updating appmigrations table...") + err = migrations.SetInitialMigrations(migrations.NewDatastore(app.db.DB, app.db.driverName)) + if err != nil { + log.Error("Unable to set initial migrations: %v", err) + os.Exit(1) + } + log.Info("Done.") + os.Exit(0) } diff --git a/migrations/migrations.go b/migrations/migrations.go index 2aa3643..1d6e0c4 100644 --- a/migrations/migrations.go +++ b/migrations/migrations.go @@ -58,6 +58,19 @@ var migrations = []Migration{ New("support user invites", supportUserInvites), // -> V1 (v0.8.0) } +// CurrentVer returns the current migration version the application is on +func CurrentVer() int { + return len(migrations) +} + +func SetInitialMigrations(db *datastore) error { + _, err := db.Exec("INSERT INTO appmigrations (version, migrated, result) VALUES (?, "+db.now()+", ?)", CurrentVer(), "") + if err != nil { + return err + } + return nil +} + func Migrate(db *datastore) error { var version int var err error diff --git a/schema.sql b/schema.sql index 6687f5d..b3fae97 100644 --- a/schema.sql +++ b/schema.sql @@ -34,6 +34,18 @@ CREATE TABLE IF NOT EXISTS `appcontent` ( -- -------------------------------------------------------- +-- +-- Table structure for table `appmigrations` +-- + +CREATE TABLE `appmigrations` ( + `version` int(11) NOT NULL, + `migrated` datetime NOT NULL, + `result` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + -- -- Table structure for table `collectionattributes` -- diff --git a/sqlite.sql b/sqlite.sql index 6c7160a..90989ed 100644 --- a/sqlite.sql +++ b/sqlite.sql @@ -32,6 +32,18 @@ CREATE TABLE IF NOT EXISTS `appcontent` ( -- -------------------------------------------------------- +-- +-- Table structure for table appmigrations +-- + +CREATE TABLE `appmigrations` ( + `version` INT NOT NULL, + `migrated` DATETIME NOT NULL, + `result` TEXT NOT NULL +); + +-- -------------------------------------------------------- + -- -- Table structure for table collectionattributes --