diff --git a/core/database/installer.go b/core/database/installer.go index fd40acec..b3e552a4 100644 --- a/core/database/installer.go +++ b/core/database/installer.go @@ -62,7 +62,9 @@ func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) { } } - // For MySQL type there was major new schema introduced in v24. + runtime.Log.Info(fmt.Sprintf("Database: %d scripts to process", len(toProcess))) + + // For MySQL type there was major new schema introduced in v24. // We check for this release and bypass usual locking code // because tables have changed. legacyMigration := runtime.StoreProvider.Type() == env.StoreTypeMySQL && @@ -72,6 +74,8 @@ func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) { // Bypass all DB locking/checking processes as these look for new schema // which we are about to install. toProcess = toProcess[len(toProcess)-1:] + + runtime.Log.Info(fmt.Sprintf("Database: legacy schema has %d scripts to process", len(toProcess))) } tx, err := runtime.Db.Beginx() @@ -139,28 +143,31 @@ func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) { func runScripts(runtime *env.Runtime, tx *sqlx.Tx, scripts []Script) (err error) { // We can have multiple scripts as each Documize database change has it's own SQL script. for _, script := range scripts { - runtime.Log.Info(fmt.Sprintf("Databasse: processing SQL version %d", script.Version)) + runtime.Log.Info(fmt.Sprintf("Database: processing SQL script %d", script.Version)) err = executeSQL(tx, runtime.StoreProvider.Type(), runtime.StoreProvider.TypeVariant(), script.Script) if err != nil { - runtime.Log.Error(fmt.Sprintf("error executing script version %d", script.Version), err) + runtime.Log.Error(fmt.Sprintf("error executing SQL script %d", script.Version), err) return err } // Record the fact we have processed this database script version. _, err = tx.Exec(runtime.StoreProvider.QueryRecordVersionUpgrade(script.Version)) if err != nil { - // For MySQL we try the legacy DB checks. + // For MySQL we try the legacy DB schema. if runtime.StoreProvider.Type() == env.StoreTypeMySQL { - runtime.Log.Error(fmt.Sprintf("Database: attempting legacy fallback for script version %d", script.Version), err) + runtime.Log.Info(fmt.Sprintf("Database: attempting legacy fallback for SQL script %d", script.Version)) _, err = tx.Exec(runtime.StoreProvider.QueryRecordVersionUpgradeLegacy(script.Version)) if err != nil { + runtime.Log.Error(fmt.Sprintf("error recording execution of SQL script %d", script.Version), err) return err } - } - - return err + } else { + // Unknown issue running script on non-MySQL database. + runtime.Log.Error(fmt.Sprintf("error executing SQL script %d", script.Version), err) + return err + } } } diff --git a/core/database/setup_endpoint.go b/core/database/setup_endpoint.go index 6491dc1a..894543bb 100644 --- a/core/database/setup_endpoint.go +++ b/core/database/setup_endpoint.go @@ -136,7 +136,7 @@ func setupAccount(rt *env.Runtime, completion onboardRequest, serial string) (er _, err = runSQL(rt, sql) if err != nil { - rt.Log.Error("Failed to insert into organization", err) + rt.Log.Error("INSERT TINO dmz_org failed", err) return } @@ -147,7 +147,7 @@ func setupAccount(rt *env.Runtime, completion onboardRequest, serial string) (er _, err = runSQL(rt, sql) if err != nil { - rt.Log.Error("Failed with error", err) + rt.Log.Error("INSERT TINO dmz_user failed", err) return err } @@ -157,7 +157,7 @@ func setupAccount(rt *env.Runtime, completion onboardRequest, serial string) (er _, err = runSQL(rt, sql) if err != nil { - rt.Log.Error("Failed with error", err) + rt.Log.Error("INSERT TINO dmz_user_account failed", err) return err } @@ -166,7 +166,7 @@ func setupAccount(rt *env.Runtime, completion onboardRequest, serial string) (er sql = fmt.Sprintf("INSERT INTO dmz_space (c_refid, c_orgid, c_name, c_type, c_userid) VALUES (\"%s\", \"%s\", \"My Project\", 2, \"%s\")", labelID, orgID, userID) _, err = runSQL(rt, sql) if err != nil { - rt.Log.Error("INSERT INTO label failed", err) + rt.Log.Error("INSERT INTO dmz_space failed", err) } // assign permissions to space @@ -175,30 +175,30 @@ func setupAccount(rt *env.Runtime, completion onboardRequest, serial string) (er sql = fmt.Sprintf("INSERT INTO dmz_permission (c_orgid, c_who, c_whoid, c_action, c_scope, c_location, c_refid) VALUES (\"%s\", 'user', \"%s\", \"%s\", 'object', 'space', \"%s\")", orgID, userID, p, labelID) _, err = runSQL(rt, sql) if err != nil { - rt.Log.Error("INSERT INTO permission failed", err) + rt.Log.Error("INSERT INTO dmz_permission failed", err) } } // Create some user groups groupDevID := uniqueid.Generate() - sql = fmt.Sprintf("INSERT INTO group (c_refid, c_orgid, c_name, c_desc) VALUES (\"%s\", \"%s\", \"Technology\", \"On-site and remote development teams\")", groupDevID, orgID) + sql = fmt.Sprintf("INSERT INTO dmz_group (c_refid, c_orgid, c_name, c_desc) VALUES (\"%s\", \"%s\", \"Technology\", \"On-site and remote development teams\")", groupDevID, orgID) _, err = runSQL(rt, sql) if err != nil { - rt.Log.Error("INSERT INTO group failed", err) + rt.Log.Error("INSERT INTO dmz_group failed", err) } groupProjectID := uniqueid.Generate() - sql = fmt.Sprintf("INSERT INTO group (c_refid, c_orgid, c_name, c_desc) VALUES (\"%s\", \"%s\", \"Project Management\", \"HQ project management\")", groupProjectID, orgID) + sql = fmt.Sprintf("INSERT INTO dmz_group (c_refid, c_orgid, c_name, c_desc) VALUES (\"%s\", \"%s\", \"Project Management\", \"HQ project management\")", groupProjectID, orgID) _, err = runSQL(rt, sql) if err != nil { - rt.Log.Error("INSERT INTO group failed", err) + rt.Log.Error("INSERT INTO dmz_group failed", err) } groupBackofficeID := uniqueid.Generate() - sql = fmt.Sprintf("INSERT INTO group (c_refid, c_orgid, c_name, c_desc) VALUES (\"%s\", \"%s\", \"Back Office\", \"Non-IT and PMO personnel\")", groupBackofficeID, orgID) + sql = fmt.Sprintf("INSERT INTO dmz_group (c_refid, c_orgid, c_name, c_desc) VALUES (\"%s\", \"%s\", \"Back Office\", \"Non-IT and PMO personnel\")", groupBackofficeID, orgID) _, err = runSQL(rt, sql) if err != nil { - rt.Log.Error("INSERT INTO group failed", err) + rt.Log.Error("INSERT INTO dmz_group failed", err) } // Join some groups @@ -229,7 +229,7 @@ func runSQL(rt *env.Runtime, sql string) (id uint64, err error) { tx, err := rt.Db.Beginx() if err != nil { - rt.Log.Error("runSql - failed to get transaction", err) + rt.Log.Error("setup - failed to get transaction", err) return } @@ -237,12 +237,12 @@ func runSQL(rt *env.Runtime, sql string) (id uint64, err error) { if err != nil { tx.Rollback() - rt.Log.Error("runSql - unable to run sql", err) + rt.Log.Error("setup - unable to run sql", err) return } if err = tx.Commit(); err != nil { - rt.Log.Error("runSql - unable to commit sql", err) + rt.Log.Error("setup - unable to commit sql", err) return }