mirror of
https://github.com/documize/community.git
synced 2025-08-07 14:35:28 +02:00
Put default values into config table
This commit is contained in:
parent
d1608aa802
commit
7925695d0b
6 changed files with 47 additions and 28 deletions
|
@ -1,11 +1,9 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/documize/community/wordsmith/environment"
|
||||
"github.com/documize/community/wordsmith/log"
|
||||
"github.com/documize/community/wordsmith/utility"
|
||||
)
|
||||
|
||||
|
@ -29,12 +27,11 @@ func ConfigString(area, path string) (ret string) {
|
|||
sql := `SELECT JSON_EXTRACT(details,'$` + path + `') AS item FROM config WHERE area = '` + area + `';`
|
||||
|
||||
stmt, err := Db.Preparex(sql)
|
||||
defer utility.Close(stmt)
|
||||
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("Unable to prepare select for ConfigString: %s", sql), err)
|
||||
//log.Error(fmt.Sprintf("Unable to prepare select for ConfigString: %s", sql), err)
|
||||
return ""
|
||||
}
|
||||
defer utility.Close(stmt)
|
||||
|
||||
var item = make([]uint8, 0)
|
||||
|
||||
|
|
|
@ -66,28 +66,27 @@ func init() {
|
|||
// go into setup mode if required
|
||||
if database.Check(Db, connectionString) {
|
||||
log.Info("database.Check(Db) OK")
|
||||
migrations, err := database.Migrations(ConfigString("DATABASE", "last_migration"))
|
||||
if err != nil {
|
||||
log.Error("Unable to find required database migrations: ", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
if len(migrations) > 0 {
|
||||
if strings.ToLower(upgrade) != "true" {
|
||||
log.Error("database migrations are required",
|
||||
errors.New("the -upgrade flag is not 'true'"))
|
||||
os.Exit(2)
|
||||
|
||||
}
|
||||
if err := migrations.Migrate(); err != nil {
|
||||
log.Error("Unable to run database migration: ", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Info("database.Check(Db) !OK, going into setup mode")
|
||||
}
|
||||
|
||||
migrations, err := database.Migrations(ConfigString("DATABASE", "last_migration"))
|
||||
if err != nil {
|
||||
log.Error("Unable to find required database migrations: ", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
if len(migrations) > 0 {
|
||||
if strings.ToLower(upgrade) != "true" {
|
||||
log.Error("database migrations are required",
|
||||
errors.New("the -upgrade flag is not 'true'"))
|
||||
os.Exit(2)
|
||||
|
||||
}
|
||||
if err := migrations.Migrate(); err != nil {
|
||||
log.Error("Unable to run database migration: ", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
return false // value not changed
|
||||
})
|
||||
}
|
||||
|
|
|
@ -262,3 +262,17 @@ ALTER TABLE label CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
|
|||
ALTER TABLE document CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
|
||||
ALTER TABLE page CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS `config`;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `config` (
|
||||
`area` CHAR(16) NOT NULL,
|
||||
`details` JSON,
|
||||
UNIQUE INDEX `idx_config_area` (`area` ASC) ) ;
|
||||
|
||||
INSERT INTO `config` VALUES ('DOCUMIZE','{\"plugin\": \"PLUGIN\"}');
|
||||
INSERT INTO `config` VALUES ('PLUGIN',
|
||||
'[{\"Comment\": \"Disable (or not) built-in html import (NOTE: no Plugin name)\",\"Disabled\": false,\"API\": \"Convert\",\"Actions\": [\"htm\",\"html\"]},{\"Comment\": \"Disable (or not) built-in Documize API import used from SDK (NOTE: no Plugin name)\",\"Disabled\": false,\"API\": \"Convert\",\"Actions\": [\"documizeapi\"]}]');
|
||||
|
||||
INSERT INTO `config` VALUES ('DATABASE','{\"last_migration\": \"migrate-00002.sql\"}');
|
||||
/* NOTE the line above must be changed every time a new migration is incorporated into this file */
|
||||
|
|
|
@ -4,4 +4,9 @@ CREATE TABLE IF NOT EXISTS `config` (
|
|||
`area` CHAR(16) NOT NULL,
|
||||
`details` JSON,
|
||||
UNIQUE INDEX `idx_config_area` (`area` ASC) ) ;
|
||||
|
||||
|
||||
INSERT INTO `config` VALUES ('DOCUMIZE','{\"plugin\": \"PLUGIN\"}');
|
||||
INSERT INTO `config` VALUES ('PLUGIN',
|
||||
'[{\"Comment\": \"Disable (or not) built-in html import (NOTE: no Plugin name)\",\"Disabled\": false,\"API\": \"Convert\",\"Actions\": [\"htm\",\"html\"]},{\"Comment\": \"Disable (or not) built-in Documize API import used from SDK (NOTE: no Plugin name)\",\"Disabled\": false,\"API\": \"Convert\",\"Actions\": [\"documizeapi\"]}]');
|
||||
|
||||
INSERT INTO `config` VALUES ('DATABASE','{\"last_migration\": \"migrate-00002.sql\"}');
|
||||
|
|
|
@ -59,6 +59,8 @@ func GetString(target *string, name string, required bool, usage string, callbac
|
|||
vars.vv = append(vars.vv, varT{target: target, name: name, required: required, callback: callback, value: value, setter: setter})
|
||||
}
|
||||
|
||||
var showSettings = flag.Bool("showsettings", false, "if true, show settings in the log (WARNING: these settings may include passwords)")
|
||||
|
||||
// Parse calls flag.Parse() then checks that the required environment variables are all set.
|
||||
// It should be the first thing called by any main() that uses this library.
|
||||
// If all the required variables are not present, it prints an error and calls os.Exit(2) like flag.Parse().
|
||||
|
@ -94,9 +96,11 @@ func Parse(doFirst string) {
|
|||
}
|
||||
typ = "Required"
|
||||
}
|
||||
if *(v.target) != "" && vars.vv[vi].setter != goInit {
|
||||
fmt.Fprintf(os.Stdout, "%s setting from '%s' is: '%s'\n",
|
||||
typ, vars.vv[vi].setter, *(v.target))
|
||||
if *showSettings {
|
||||
if *(v.target) != "" && vars.vv[vi].setter != goInit {
|
||||
fmt.Fprintf(os.Stdout, "%s setting from '%s' is: '%s'\n",
|
||||
typ, vars.vv[vi].setter, *(v.target))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import "github.com/documize/community/wordsmith/log"
|
|||
|
||||
// Close is a convenience function to close an io.Closer, usually in a defer.
|
||||
func Close(f io.Closer) {
|
||||
if f != nil {
|
||||
if f != nil && f != io.Closer(nil) {
|
||||
log.IfErr(f.Close())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue