Skip to content

Commit 6df28e6

Browse files
committed
Update mysql schema for modern mysql
The groups keyword is reserved in mysql but can still have tables using this name if they are quoted with backticks (`). Additionally, default values cannot be specified for TEXT types unless wrapped in parentheses. Signed-off-by: Billy Olsen <[email protected]>
1 parent 23ec116 commit 6df28e6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

mysql.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ CREATE TABLE IF NOT EXISTS users (
4444
passbcrypt VARCHAR(64) DEFAULT '',
4545
otpsecret VARCHAR(64) DEFAULT '',
4646
yubikey VARCHAR(128) DEFAULT '',
47-
sshkeys TEXT DEFAULT '',
48-
custattr TEXT DEFAULT '{}')
47+
sshkeys TEXT DEFAULT (''),
48+
custattr TEXT DEFAULT ('{}'))
4949
`)
5050
statement.Exec()
5151
statement, _ = db.Prepare("CREATE UNIQUE INDEX idx_user_name on users(name)")
5252
statement.Exec()
53-
statement, _ = db.Prepare("CREATE TABLE IF NOT EXISTS groups (id INTEGER AUTO_INCREMENT PRIMARY KEY, name VARCHAR(64) NOT NULL, gidnumber INTEGER NOT NULL)")
53+
statement, _ = db.Prepare("CREATE TABLE IF NOT EXISTS `groups` (id INTEGER AUTO_INCREMENT PRIMARY KEY, name VARCHAR(64) NOT NULL, gidnumber INTEGER NOT NULL)")
5454
statement.Exec()
55-
statement, _ = db.Prepare("CREATE UNIQUE INDEX idx_group_name on groups(name)")
55+
statement, _ = db.Prepare("CREATE UNIQUE INDEX idx_group_name on `groups`(name)")
5656
statement.Exec()
5757
statement, _ = db.Prepare("CREATE TABLE IF NOT EXISTS includegroups (id INTEGER AUTO_INCREMENT PRIMARY KEY, parentgroupid INTEGER NOT NULL, includegroupid INTEGER NOT NULL)")
5858
statement.Exec()
@@ -63,7 +63,7 @@ CREATE TABLE IF NOT EXISTS users (
6363
// Migrate schema if necessary
6464
func (b MysqlBackend) MigrateSchema(db *sql.DB, checker func(*sql.DB, string) bool) {
6565
if !checker(db, "sshkeys") {
66-
statement, _ := db.Prepare("ALTER TABLE users ADD COLUMN sshkeys TEXT DEFAULT ''")
66+
statement, _ := db.Prepare("ALTER TABLE users ADD COLUMN sshkeys TEXT DEFAULT ('')")
6767
statement.Exec()
6868
}
6969
}

0 commit comments

Comments
 (0)