1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 21:29:42 +02:00

mark follower instances with prefix of "-" on the db username

This commit is contained in:
Elliott Stoneham 2016-07-27 12:58:19 +01:00
parent a6873f807c
commit 66dfc8c6ca
4 changed files with 659 additions and 724 deletions

View file

@ -50,8 +50,16 @@ func init() {
var err error
environment.GetString(&connectionString, "db", true,
`"username:password@protocol(hostname:port)/databasename" for example "fred:bloggs@tcp(localhost:3306)/documize"`,
`'username:password@protocol(hostname:port)/databasename" for example "fred:bloggs@tcp(localhost:3306)/documize", or if a follower instance "-fred:bloggs@tcp(localhost:3306)/documize"`,
func(*string, string) bool {
isLeader := true
followerPrefix := "-"
if strings.HasPrefix(connectionString, followerPrefix) {
isLeader = false
connectionString = strings.TrimPrefix(connectionString, followerPrefix)
log.Info("This is a follower instance, no DB schema updates will be performed")
}
Db, err = sqlx.Open("mysql", stdConn(connectionString))
if err != nil {
@ -73,7 +81,7 @@ func init() {
// go into setup mode if required
if web.SiteMode != web.SiteModeOffline {
if database.Check(Db, connectionString) {
if err := database.Migrate(true /* the config table exists */); err != nil {
if err := database.Migrate(true /* the config table exists */, isLeader); err != nil {
log.Error("Unable to run database migration: ", err)
os.Exit(2)
}