Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primary key required in MySQL DB clusters #16802

Closed
2 of 6 tasks
aqos156 opened this issue Aug 24, 2021 · 9 comments · Fixed by #16813
Closed
2 of 6 tasks

Primary key required in MySQL DB clusters #16802

aqos156 opened this issue Aug 24, 2021 · 9 comments · Fixed by #16813
Labels
type/enhancement An improvement of existing functionality

Comments

@aqos156
Copy link

aqos156 commented Aug 24, 2021

  • Gitea version (or commit ref): gitea/gitea:1.15.0
  • Git version: -
  • Operating system: Linux (docker)
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
  • Log gist:
    ORM engine initialization attempt #1/10 failed. Error: migrate: do migrate: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

Description

Certain DB clusters (for example DigitalOcean's MySQL cluster) require the use of primary keys which until now was fine. It seems like this support was dropped since 1.15. This issue occurs at fresh installation of 1.15 and also when upgrading from 1.14

@lunny
Copy link
Member

lunny commented Aug 24, 2021

Could you give more logs, if you can enable log level to info, some information like Migration[%d]: %s should be above the error line.

@aqos156
Copy link
Author

aqos156 commented Aug 24, 2021

@lunny log level is set to info in conf and this is the output of a fresh installation:

Server listening on :: port 22.

Server listening on 0.0.0.0 port 22.

2021/08/24 13:17:13 cmd/web.go:97:runWeb() [I] Starting Gitea on PID: 17

2021/08/24 13:17:13 cmd/web.go:141:runWeb() [I] Global init

2021/08/24 13:17:13 routers/init.go:74:GlobalInit() [I] Git Version: 2.30.2, Wire Protocol Version 2 Enabled

2021/08/24 13:17:13 routers/init.go:77:GlobalInit() [I] AppPath: /app/gitea/gitea

2021/08/24 13:17:13 routers/init.go:78:GlobalInit() [I] AppWorkPath: /app/gitea

2021/08/24 13:17:13 routers/init.go:79:GlobalInit() [I] Custom path: /data/gitea

2021/08/24 13:17:13 routers/init.go:80:GlobalInit() [I] Log path: /data/gitea/log

2021/08/24 13:17:13 routers/init.go:81:GlobalInit() [I] Run Mode: Prod

2021/08/24 13:17:14 ...dules/setting/log.go:286:newLogService() [I] Gitea v1.15.0 built with GNU Make 4.3, go1.16.7 : bindata, timetzdata, sqlite, sqlite_unlock_notify

2021/08/24 13:17:14 ...dules/setting/log.go:333:newLogService() [I] Gitea Log Mode: Console(Console:)

2021/08/24 13:17:14 ...dules/setting/log.go:249:generateNamedLogger() [I] Router Log: Console(console:)

2021/08/24 13:17:14 ...les/setting/cache.go:78:newCacheService() [I] Cache Service Enabled

2021/08/24 13:17:14 ...les/setting/cache.go:93:newCacheService() [I] Last Commit Cache Service Enabled

2021/08/24 13:17:14 ...s/setting/session.go:77:newSessionService() [I] Session Service Enabled

2021/08/24 13:17:14 ...s/storage/storage.go:170:initAttachments() [I] Initialising Attachment storage with type: 

2021/08/24 13:17:14 ...les/storage/local.go:47:NewLocalStorage() [I] Creating new Local Storage at /data/gitea/attachments

2021/08/24 13:17:14 ...s/storage/storage.go:164:initAvatars() [I] Initialising Avatar storage with type: 

2021/08/24 13:17:14 ...les/storage/local.go:47:NewLocalStorage() [I] Creating new Local Storage at /data/gitea/avatars

2021/08/24 13:17:14 ...s/storage/storage.go:182:initRepoAvatars() [I] Initialising Repository Avatar storage with type: 

2021/08/24 13:17:14 ...les/storage/local.go:47:NewLocalStorage() [I] Creating new Local Storage at /data/gitea/repo-avatars

2021/08/24 13:17:14 ...s/storage/storage.go:176:initLFS() [I] Initialising LFS storage with type: 

2021/08/24 13:17:14 ...les/storage/local.go:47:NewLocalStorage() [I] Creating new Local Storage at /data/git/lfs

2021/08/24 13:17:14 ...s/storage/storage.go:188:initRepoArchives() [I] Initialising Repository Archive storage with type: 

2021/08/24 13:17:14 ...les/storage/local.go:47:NewLocalStorage() [I] Creating new Local Storage at /data/gitea/repo-archive

2021/08/24 13:17:14 routers/init.go:93:GlobalInit() [I] SQLite3 Supported

2021/08/24 13:17:14 routers/common/db.go:20:InitDBEngine() [I] Beginning ORM engine initialization.

2021/08/24 13:17:14 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #1/10...

2021/08/24 13:17:14 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:17:18 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #1/10 failed. Error: sync database struct error: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:17:18 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

2021/08/24 13:17:21 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #2/10...

2021/08/24 13:17:21 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:17:22 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #2/10 failed. Error: sync database struct error: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:17:22 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

2021/08/24 13:17:25 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #3/10...

2021/08/24 13:17:25 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:17:25 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #3/10 failed. Error: sync database struct error: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:17:25 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

2021/08/24 13:17:28 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #4/10...

2021/08/24 13:17:28 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:17:29 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #4/10 failed. Error: sync database struct error: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:17:29 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

2021/08/24 13:17:32 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #5/10...

2021/08/24 13:17:32 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:17:32 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #5/10 failed. Error: sync database struct error: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:17:32 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

2021/08/24 13:17:35 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #6/10...

2021/08/24 13:17:35 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:17:35 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #6/10 failed. Error: sync database struct error: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:17:35 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

2021/08/24 13:17:38 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #7/10...

2021/08/24 13:17:38 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:17:39 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #7/10 failed. Error: sync database struct error: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:17:39 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

2021/08/24 13:17:42 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #8/10...

2021/08/24 13:17:42 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:17:42 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #8/10 failed. Error: sync database struct error: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:17:42 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

2021/08/24 13:17:45 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #9/10...

2021/08/24 13:17:45 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:17:46 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #9/10 failed. Error: sync database struct error: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:17:46 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

2021/08/24 13:17:49 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #10/10...

2021/08/24 13:17:49 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:17:49 routers/init.go:100:GlobalInit() [F] ORM engine initialization failed: sync database struct error: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

Received signal 15; terminating.

And this is log of migration from 1.14:

Server listening on :: port 22.

Server listening on 0.0.0.0 port 22.

2021/08/24 13:10:45 cmd/web.go:97:runWeb() [I] Starting Gitea on PID: 16

2021/08/24 13:10:45 cmd/web.go:141:runWeb() [I] Global init

2021/08/24 13:10:45 routers/init.go:74:GlobalInit() [I] Git Version: 2.30.2, Wire Protocol Version 2 Enabled

2021/08/24 13:10:45 routers/init.go:77:GlobalInit() [I] AppPath: /app/gitea/gitea

2021/08/24 13:10:45 routers/init.go:78:GlobalInit() [I] AppWorkPath: /app/gitea

2021/08/24 13:10:45 routers/init.go:79:GlobalInit() [I] Custom path: /data/gitea

2021/08/24 13:10:45 routers/init.go:80:GlobalInit() [I] Log path: /data/gitea/log

2021/08/24 13:10:45 routers/init.go:81:GlobalInit() [I] Run Mode: Prod

2021/08/24 13:10:45 ...dules/setting/log.go:286:newLogService() [I] Gitea v1.15.0 built with GNU Make 4.3, go1.16.7 : bindata, timetzdata, sqlite, sqlite_unlock_notify

2021/08/24 13:10:45 ...dules/setting/log.go:333:newLogService() [I] Gitea Log Mode: Console(Console:)

2021/08/24 13:10:45 ...dules/setting/log.go:249:generateNamedLogger() [I] Router Log: Console(console:)

2021/08/24 13:10:45 ...les/setting/cache.go:78:newCacheService() [I] Cache Service Enabled

2021/08/24 13:10:45 ...les/setting/cache.go:93:newCacheService() [I] Last Commit Cache Service Enabled

2021/08/24 13:10:45 ...s/setting/session.go:77:newSessionService() [I] Session Service Enabled

2021/08/24 13:10:45 ...s/storage/storage.go:170:initAttachments() [I] Initialising Attachment storage with type: 

2021/08/24 13:10:45 ...les/storage/local.go:47:NewLocalStorage() [I] Creating new Local Storage at /data/gitea/attachments

2021/08/24 13:10:45 ...s/storage/storage.go:164:initAvatars() [I] Initialising Avatar storage with type: 

2021/08/24 13:10:45 ...les/storage/local.go:47:NewLocalStorage() [I] Creating new Local Storage at /data/gitea/avatars

2021/08/24 13:10:45 ...s/storage/storage.go:182:initRepoAvatars() [I] Initialising Repository Avatar storage with type: 

2021/08/24 13:10:45 ...les/storage/local.go:47:NewLocalStorage() [I] Creating new Local Storage at /data/gitea/repo-avatars

2021/08/24 13:10:45 ...s/storage/storage.go:176:initLFS() [I] Initialising LFS storage with type: 

2021/08/24 13:10:45 ...les/storage/local.go:47:NewLocalStorage() [I] Creating new Local Storage at /data/git/lfs

2021/08/24 13:10:45 ...s/storage/storage.go:188:initRepoArchives() [I] Initialising Repository Archive storage with type: 

2021/08/24 13:10:45 ...les/storage/local.go:47:NewLocalStorage() [I] Creating new Local Storage at /data/gitea/repo-archive

2021/08/24 13:10:45 routers/init.go:93:GlobalInit() [I] SQLite3 Supported

2021/08/24 13:10:45 routers/common/db.go:20:InitDBEngine() [I] Beginning ORM engine initialization.

2021/08/24 13:10:45 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #1/10...

2021/08/24 13:10:45 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:10:45 ...ations/migrations.go:419:Migrate() [I] Migration[178]: Add LFS columns to Mirror

2021/08/24 13:10:45 routers/common/db.go:28:InitDBEngine() [W] Table mirror has column id but struct has not related field

2021/08/24 13:10:45 routers/common/db.go:28:InitDBEngine() [W] Table mirror has column repo_id but struct has not related field

2021/08/24 13:10:45 routers/common/db.go:28:InitDBEngine() [W] Table mirror has column interval but struct has not related field

2021/08/24 13:10:45 routers/common/db.go:28:InitDBEngine() [W] Table mirror has column enable_prune but struct has not related field

2021/08/24 13:10:45 routers/common/db.go:28:InitDBEngine() [W] Table mirror has column updated_unix but struct has not related field

2021/08/24 13:10:45 routers/common/db.go:28:InitDBEngine() [W] Table mirror has column next_update_unix but struct has not related field

2021/08/24 13:10:45 ...ations/migrations.go:419:Migrate() [I] Migration[179]: Convert avatar url to text

2021/08/24 13:10:45 ...ations/migrations.go:419:Migrate() [I] Migration[180]: Delete credentials from past migrations

2021/08/24 13:10:45 ...ations/migrations.go:419:Migrate() [I] Migration[181]: Always save primary email on email address table

2021/08/24 13:10:45 routers/common/db.go:28:InitDBEngine() [W] Table email_address Column lower_email db nullable is true, struct nullable is false

2021/08/24 13:10:45 ...ations/migrations.go:419:Migrate() [I] Migration[182]: Add issue resource index table

2021/08/24 13:10:45 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #1/10 failed. Error: migrate: do migrate: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:10:45 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

2021/08/24 13:10:48 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #2/10...

2021/08/24 13:10:48 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:10:48 ...ations/migrations.go:419:Migrate() [I] Migration[182]: Add issue resource index table

2021/08/24 13:10:49 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #2/10 failed. Error: migrate: do migrate: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:10:49 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

2021/08/24 13:10:52 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #3/10...

2021/08/24 13:10:52 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:10:52 ...ations/migrations.go:419:Migrate() [I] Migration[182]: Add issue resource index table

2021/08/24 13:10:52 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #3/10 failed. Error: migrate: do migrate: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:10:52 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

2021/08/24 13:10:55 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #4/10...

2021/08/24 13:10:55 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:10:55 ...ations/migrations.go:419:Migrate() [I] Migration[182]: Add issue resource index table

2021/08/24 13:10:55 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #4/10 failed. Error: migrate: do migrate: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:10:55 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

2021/08/24 13:10:58 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #5/10...

2021/08/24 13:10:58 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:10:58 ...ations/migrations.go:419:Migrate() [I] Migration[182]: Add issue resource index table

2021/08/24 13:10:58 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #5/10 failed. Error: migrate: do migrate: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:10:58 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

2021/08/24 13:11:01 routers/common/db.go:27:InitDBEngine() [I] ORM engine initialization attempt #6/10...

2021/08/24 13:11:01 ...om/urfave/cli/app.go:524:HandleAction() [I] PING DATABASE mysql

2021/08/24 13:11:01 ...ations/migrations.go:419:Migrate() [I] Migration[182]: Add issue resource index table

2021/08/24 13:11:01 routers/common/db.go:33:InitDBEngine() [E] ORM engine initialization attempt #6/10 failed. Error: migrate: do migrate: Error 3750: Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

2021/08/24 13:11:01 routers/common/db.go:34:InitDBEngine() [I] Backing off for 3 seconds

@zeripath
Copy link
Contributor

Looks like the problem is related to ResourceIndex in models/migrations/v182.go and models/index.go

2021/08/24 13:10:45 ...ations/migrations.go:419:Migrate() [I] Migration[182]: Add issue resource index table

@lunny
Copy link
Member

lunny commented Aug 24, 2021

Yes. So v1.15, we have a new table issue_index struct name is ResourceIndex which has no primary key. But for MySQL DB cluster, a primary key is necessary? (I'm not familiar with MySQL DB cluster)

So MySQL DB cluster is never the design target but it works before v1.15. Should we add a primary key for ResourceIndex and support MySQL DB cluster officially?

@lunny lunny added the type/enhancement An improvement of existing functionality label Aug 24, 2021
@aqos156
Copy link
Author

aqos156 commented Aug 24, 2021 via email

@cboylan
Copy link
Contributor

cboylan commented Aug 24, 2021

I'm not database expert but I don't think this is MySQL DB cluster specific and applies to MySQL and MariaDB generally. It is just that typically MySQL doesn't require you to have a Primary Key and will create one for you when you don't specify one. However, in many circumstances this is problematic so newer MySQL (via sql_require_primary_key) and MariaDB (via innodb_force_primary_key) can force you to create them.

It sounds like DigitalOcean's hosted databases have made this choice for users.

Rather than testing and supporting MySQL DB cluster specifically you may want to set those vars when using MySQL and MariaDB and maintain compatibility that way.

This writeup tries to cover the why and how of this.

@aqos156
Copy link
Author

aqos156 commented Aug 24, 2021

I'm not database expert but I don't think this is MySQL DB cluster specific and applies to MySQL and MariaDB generally. It is just that typically MySQL doesn't require you to have a Primary Key and will create one for you when you don't specify one. However, in many circumstances this is problematic so newer MySQL (via sql_require_primary_key) and MariaDB (via innodb_force_primary_key) can force you to create them.

It sounds like DigitalOcean's hosted databases have made this choice for users.

Rather than testing and supporting MySQL DB cluster specifically you may want to set those vars when using MySQL and MariaDB and maintain compatibility that way.

This writeup tries to cover the why and how of this.

Setting these variables is sometimes not an option, because these variables are managed by the provider who uses them to manage clustering and another link

@zeripath
Copy link
Contributor

zeripath commented Aug 24, 2021

The group_id may as well be a primary key - it has an unique index on it.

@cboylan
Copy link
Contributor

cboylan commented Aug 24, 2021

Setting these variables is sometimes not an option, because these variables are managed by the provider who uses them to manage clustering and another link

Yes, I was suggesting that Gitea may want to set the variables when testing MySQL/MariaDB support rather than figuring out a Galera cluster and testing with that. Primary keys are important to clustered mysql to ensure that rows can be deleted and that you get consistent order of returned data, but flipping these flags on a single database server is probably sufficient for avoiding this incompatibility in the future.

zeripath added a commit to zeripath/gitea that referenced this issue Aug 24, 2021
Make the group_id a primary key in issue_index. This already has an unique index
and therefore is a good candidate for becoming a primary key.

This PR also changes all other uses of this table to add the group_id as the
primary key.

Fix go-gitea#16802

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit that referenced this issue Aug 25, 2021
Make the group_id a primary key in issue_index. This already has an unique index
and therefore is a good candidate for becoming a primary key.

This PR also changes all other uses of this table to add the group_id as the
primary key.

Fix #16802

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit to zeripath/gitea that referenced this issue Aug 25, 2021
Backport go-gitea#16813

Make the group_id a primary key in issue_index. This already has an
unique index and therefore is a good candidate for becoming a primary
key.

This PR also changes all other uses of this table to add the group_id as
the primary key.

The migration v192 from go-gitea#16813 has not been backported but Xorm will
work fine with non-primary keyed tables. If a user on 1.15 wishes to
have the correct schema sooner than 1.16 - they can use gitea doctor
recreate-table issue_index and gitea will recreate the table with the
primary key.

Fix go-gitea#16802

Signed-off-by: Andrew Thornton art27@cantab.net
techknowlogick pushed a commit that referenced this issue Aug 25, 2021
Backport #16813

Make the group_id a primary key in issue_index. This already has an
unique index and therefore is a good candidate for becoming a primary
key.

This PR also changes all other uses of this table to add the group_id as
the primary key.

The migration v192 from #16813 has not been backported but Xorm will
work fine with non-primary keyed tables. If a user on 1.15 wishes to
have the correct schema sooner than 1.16 - they can use gitea doctor
recreate-table issue_index and gitea will recreate the table with the
primary key.

Fix #16802

Signed-off-by: Andrew Thornton art27@cantab.net
@go-gitea go-gitea locked and limited conversation to collaborators Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants