mirror of
https://github.com/writeas/writefreely
synced 2025-01-02 19:19:32 +01:00
Set up migrations table on initial setup
This includes the appmigrations table in the schema files, and inserts the current database version when running writefreely --init-db
This commit is contained in:
parent
5e686a5b0f
commit
3a6118c207
10
app.go
10
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)
|
||||
}
|
||||
|
@ -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
|
||||
|
12
schema.sql
12
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`
|
||||
--
|
||||
|
12
sqlite.sql
12
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
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user