Skip to content

Commit 2066f72

Browse files
committed
Support MySQL 8.x series
Two issues resolved relating to MySQL 8: 1. DB version checking skips MINOR/PATCH checks if MAJOR release changed. 2. Keyword 'admin' quoted to ensure MySQL compat. Closes #152
1 parent 0f87d5b commit 2066f72

File tree

7 files changed

+700
-673
lines changed

7 files changed

+700
-673
lines changed

compile.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /bin/bash
2+
3+
echo "Generating in-memory static assets..."
4+
# go get -u github.com/jteeuwen/go-bindata/...
5+
# go get -u github.com/elazarl/go-bindata-assetfs/...
6+
cd embed
7+
go generate
8+
9+
echo "Compiling app..."
10+
cd ..
11+
for arch in amd64 ; do
12+
for os in darwin linux windows ; do
13+
if [ "$os" == "windows" ] ; then
14+
echo "Compiling documize-community-$os-$arch.exe"
15+
env GOOS=$os GOARCH=$arch go build -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH -o bin/documize-community-$os-$arch.exe ./edition/community.go
16+
else
17+
echo "Compiling documize-community-$os-$arch"
18+
env GOOS=$os GOARCH=$arch go build -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH -o bin/documize-community-$os-$arch ./edition/community.go
19+
fi
20+
done
21+
done
22+
23+
echo "Finished."

core/database/check.go

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ func Check(runtime *env.Runtime) bool {
7777
}
7878

7979
for k, v := range verInts {
80+
// If major release is higher then skip minor/patch checks (e.g. 8.x.x > 5.x.x)
81+
if k == 0 && len(verNums) > 0 && verNums[0] > verInts[0] {
82+
break
83+
}
8084
if verNums[k] < v {
8185
want := fmt.Sprintf("%d.%d.%d", verInts[0], verInts[1], verInts[2])
8286
runtime.Log.Error("MySQL version element "+strconv.Itoa(k+1)+" of '"+version+"' not high enough, need at least version "+want, errors.New("bad MySQL version"))

core/database/endpoint.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func setupAccount(rt *env.Runtime, completion onboardRequest, serial string) (er
153153

154154
// Link user to organization.
155155
accountID := uniqueid.Generate()
156-
sql = fmt.Sprintf("insert into account (refid, userid, orgid, admin, editor) values (\"%s\", \"%s\", \"%s\",1, 1)", accountID, userID, orgID)
156+
sql = fmt.Sprintf("insert into account (refid, userid, orgid, `admin`, editor) values (\"%s\", \"%s\", \"%s\",1, 1)", accountID, userID, orgID)
157157
_, err = runSQL(rt, sql)
158158

159159
if err != nil {

core/database/scripts/autobuild/db_00020.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ ALTER TABLE useractivity ADD COLUMN `metadata` VARCHAR(1000) NOT NULL DEFAULT ''
1313

1414
-- new role for viewing content analytics
1515
ALTER TABLE account ADD COLUMN `analytics` BOOL NOT NULL DEFAULT 0 AFTER `users`;
16-
UPDATE account SET analytics=1 WHERE admin=1;
16+
UPDATE account SET analytics=1 WHERE `admin`=1;
1717

1818
-- deprecations

domain/account/mysql/store.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (s Scope) Add(ctx domain.RequestContext, account account.Account) (err erro
3333
account.Created = time.Now().UTC()
3434
account.Revised = time.Now().UTC()
3535

36-
_, err = ctx.Transaction.Exec("INSERT INTO account (refid, orgid, userid, admin, editor, users, analytics, active, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
36+
_, err = ctx.Transaction.Exec("INSERT INTO account (refid, orgid, userid, `admin`, editor, users, analytics, active, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
3737
account.RefID, account.OrgID, account.UserID, account.Admin, account.Editor, account.Users, account.Analytics, account.Active, account.Created, account.Revised)
3838

3939
if err != nil {
@@ -46,7 +46,7 @@ func (s Scope) Add(ctx domain.RequestContext, account account.Account) (err erro
4646
// GetUserAccount returns the database account record corresponding to the given userID, using the client's current organizaion.
4747
func (s Scope) GetUserAccount(ctx domain.RequestContext, userID string) (account account.Account, err error) {
4848
err = s.Runtime.Db.Get(&account, `
49-
SELECT a.id, a.refid, a.orgid, a.userid, a.editor, a.admin, a.users, a.analytics, a.active, a.created, a.revised,
49+
SELECT a.id, a.refid, a.orgid, a.userid, a.editor, `+"a.`admin`"+`, a.users, a.analytics, a.active, a.created, a.revised,
5050
b.company, b.title, b.message, b.domain
5151
FROM account a, organization b
5252
WHERE b.refid=a.orgid AND a.orgid=? AND a.userid=?`, ctx.OrgID, userID)
@@ -61,7 +61,7 @@ func (s Scope) GetUserAccount(ctx domain.RequestContext, userID string) (account
6161
// GetUserAccounts returns a slice of database account records, for all organizations that the userID is a member of, in organization title order.
6262
func (s Scope) GetUserAccounts(ctx domain.RequestContext, userID string) (t []account.Account, err error) {
6363
err = s.Runtime.Db.Select(&t, `
64-
SELECT a.id, a.refid, a.orgid, a.userid, a.editor, a.admin, a.users, a.analytics, a.active, a.created, a.revised,
64+
SELECT a.id, a.refid, a.orgid, a.userid, a.editor, `+"a.`admin`"+`, a.users, a.analytics, a.active, a.created, a.revised,
6565
b.company, b.title, b.message, b.domain
6666
FROM account a, organization b
6767
WHERE a.userid=? AND a.orgid=b.refid AND a.active=1 ORDER BY b.title`, userID)
@@ -76,7 +76,7 @@ func (s Scope) GetUserAccounts(ctx domain.RequestContext, userID string) (t []ac
7676
// GetAccountsByOrg returns a slice of database account records, for all users in the client's organization.
7777
func (s Scope) GetAccountsByOrg(ctx domain.RequestContext) (t []account.Account, err error) {
7878
err = s.Runtime.Db.Select(&t,
79-
`SELECT a.id, a.refid, a.orgid, a.userid, a.editor, a.admin, a.users, a.analytics, a.active, a.created, a.revised,
79+
`SELECT a.id, a.refid, a.orgid, a.userid, a.editor, `+"a.`admin`"+`, a.users, a.analytics, a.active, a.created, a.revised,
8080
b.company, b.title, b.message, b.domain
8181
FROM account a, organization b
8282
WHERE a.orgid=b.refid AND a.orgid=? AND a.active=1`, ctx.OrgID)
@@ -109,7 +109,7 @@ func (s Scope) CountOrgAccounts(ctx domain.RequestContext) (c int) {
109109
func (s Scope) UpdateAccount(ctx domain.RequestContext, account account.Account) (err error) {
110110
account.Revised = time.Now().UTC()
111111

112-
_, err = ctx.Transaction.NamedExec("UPDATE account SET userid=:userid, admin=:admin, editor=:editor, users=:users, analytics=:analytics, active=:active, revised=:revised WHERE orgid=:orgid AND refid=:refid", &account)
112+
_, err = ctx.Transaction.NamedExec("UPDATE account SET userid=:userid, `admin`=:admin, editor=:editor, users=:users, analytics=:analytics, active=:active, revised=:revised WHERE orgid=:orgid AND refid=:refid", &account)
113113

114114
if err != sql.ErrNoRows && err != nil {
115115
err = errors.Wrap(err, fmt.Sprintf("execute update for account %s", account.RefID))

domain/user/mysql/store.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (s Scope) GetActiveUsersForOrganization(ctx domain.RequestContext) (u []use
114114

115115
err = s.Runtime.Db.Select(&u,
116116
`SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.lastversion, u.created, u.revised,
117-
u.global, a.active, a.editor, a.admin, a.users as viewusers, a.analytics
117+
u.global, a.active, a.editor, `+"a.`admin`"+`, a.users as viewusers, a.analytics
118118
FROM user u, account a
119119
WHERE u.refid=a.userid AND a.orgid=? AND a.active=1
120120
ORDER BY u.firstname,u.lastname`,
@@ -143,7 +143,7 @@ func (s Scope) GetUsersForOrganization(ctx domain.RequestContext, filter string)
143143

144144
err = s.Runtime.Db.Select(&u,
145145
`SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.lastversion, u.created, u.revised,
146-
u.global, a.active, a.editor, a.admin, a.users as viewusers, a.analytics
146+
u.global, a.active, a.editor `+"a.`admin`"+`, a.users as viewusers, a.analytics
147147
FROM user u, account a
148148
WHERE u.refid=a.userid AND a.orgid=? `+likeQuery+
149149
`ORDER BY u.firstname, u.lastname LIMIT 100`, ctx.OrgID)
@@ -165,7 +165,7 @@ func (s Scope) GetSpaceUsers(ctx domain.RequestContext, spaceID string) (u []use
165165

166166
err = s.Runtime.Db.Select(&u, `
167167
SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.created, u.lastversion, u.revised, u.global,
168-
a.active, a.users AS viewusers, a.editor, a.admin, a.analytics
168+
a.active, a.users AS viewusers, a.editor, `+"a.`admin`"+`, a.analytics
169169
FROM user u, account a
170170
WHERE a.orgid=? AND u.refid = a.userid AND a.active=1 AND u.refid IN (
171171
SELECT whoid from permission WHERE orgid=? AND who='user' AND scope='object' AND location='space' AND refid=? UNION ALL
@@ -194,7 +194,7 @@ func (s Scope) GetUsersForSpaces(ctx domain.RequestContext, spaces []string) (u
194194

195195
query, args, err := sqlx.In(`
196196
SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.lastversion, u.created, u.revised, u.global,
197-
a.active, a.users AS viewusers, a.editor, a.admin, a.analytics
197+
a.active, a.users AS viewusers, a.editor, `+"a.`admin`"+`, a.analytics
198198
FROM user u, account a
199199
WHERE a.orgid=? AND u.refid = a.userid AND a.active=1 AND u.refid IN (
200200
SELECT whoid from permission WHERE orgid=? AND who='user' AND scope='object' AND location='space' AND refid IN(?) UNION ALL
@@ -295,7 +295,7 @@ func (s Scope) MatchUsers(ctx domain.RequestContext, text string, maxMatches int
295295

296296
err = s.Runtime.Db.Select(&u,
297297
`SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.lastversion, u.created, u.revised,
298-
u.global, a.active, a.editor, a.admin, a.users as viewusers, a.analytics
298+
u.global, a.active, a.editor, `+"a.`admin`"+`, a.users as viewusers, a.analytics
299299
FROM user u, account a
300300
WHERE a.orgid=? AND u.refid=a.userid AND a.active=1 `+likeQuery+
301301
`ORDER BY u.firstname,u.lastname LIMIT `+strconv.Itoa(maxMatches),

0 commit comments

Comments
 (0)