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

MySQL/MariaDB: Unique Constraint on Branches doesn't respect casing: UQE_branch_s #28131

Closed
sebastian-sauer opened this issue Nov 20, 2023 · 6 comments · Fixed by #28662
Closed
Labels
issue/workaround it is or has a workaround type/bug

Comments

@sebastian-sauer
Copy link
Contributor

Description

In a repo with two branches feature/test_case and feature\Test_Case gitea throws a 500 exception when syncing branches as the unique constraint is violated.

SyncRepoBranches: Error 1062 (23000): Duplicate entry '<redacted_branch_name>' for key 'UQE_branch_s'

This error happened after an upgrade to 1.21.0 on an existing repo.

Workaround is to rename one of the branches.

Typically having this type of different branch names only based on casing is not needed (imho it's a bug ;) ) - but we shouldn't have a 500 page when accessing the repo.

Gitea Version

1.21.0

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

Linux

How are you running Gitea?

Official binary

Database

MySQL/MariaDB

@yorliuk
Copy link

yorliuk commented Nov 20, 2023

I got the same error in Gitea log after updating to 1.21.
...dules/context/api.go:105:ServerError() [E] SyncRepoBranches: Error 1062 (23000): Duplicate entry '<BRANCH_NAME>' for key 'branch.UQE_branch_s'

But I can't find such branch in DB.
mysql Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)

@silverwind
Copy link
Member

Related: #25909

@sebastian-sauer
Copy link
Contributor Author

Are we "allowed" to remove a unique constraint in a patch release?

@yorliuk
Copy link

yorliuk commented Nov 20, 2023

I got the same error in Gitea log after updating to 1.21. ...dules/context/api.go:105:ServerError() [E] SyncRepoBranches: Error 1062 (23000): Duplicate entry '<BRANCH_NAME>' for key 'branch.UQE_branch_s'

But I can't find such branch in DB. mysql Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)

It helped: #25909 (comment)

@silverwind
Copy link
Member

Are we "allowed" to remove a unique constraint in a patch release?

Anything reasonable is possible, but I think the solution is to make the field case-sensitive.

@wxiaoguang wxiaoguang changed the title MariaDB: Unique Constraint on Branches doesn't respect casing MySQL/MariaDB: Unique Constraint on Branches doesn't respect casing Dec 29, 2023
@wxiaoguang wxiaoguang changed the title MySQL/MariaDB: Unique Constraint on Branches doesn't respect casing MySQL/MariaDB: Unique Constraint on Branches doesn't respect casing: UQE_branch_s Dec 29, 2023
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Dec 29, 2023

For 1.21 (unlucky...) users, the workaround is to run the SQL manually:

ALTER TABLE branch MODIFY COLUMN `name` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL

It won't cause side-effect and won't conflict with the complete fix (if there is anything wrong, it could be revert to old COLLATE utf8mb4_general_ci)

@wxiaoguang wxiaoguang added the issue/workaround it is or has a workaround label Dec 29, 2023
lunny pushed a commit that referenced this issue Jan 10, 2024
…8662)

Mainly for MySQL/MSSQL.

It is important for Gitea to use case-sensitive database charset
collation. If the database is using a case-insensitive collation, Gitea
will show startup error/warning messages, and show the errors/warnings
on the admin panel's Self-Check page.

Make `gitea doctor convert` work for MySQL to convert the collations of
database & tables & columns.

* Fix #28131

## ⚠️ BREAKING ⚠️

It is not quite breaking, but it's highly recommended to convert the
database&table&column to a consistent and case-sensitive collation.
fuxiaohei pushed a commit to fuxiaohei/gitea that referenced this issue Jan 17, 2024
…-gitea#28662)

Mainly for MySQL/MSSQL.

It is important for Gitea to use case-sensitive database charset
collation. If the database is using a case-insensitive collation, Gitea
will show startup error/warning messages, and show the errors/warnings
on the admin panel's Self-Check page.

Make `gitea doctor convert` work for MySQL to convert the collations of
database & tables & columns.

* Fix go-gitea#28131

## ⚠️ BREAKING ⚠️

It is not quite breaking, but it's highly recommended to convert the
database&table&column to a consistent and case-sensitive collation.
silverwind pushed a commit to silverwind/gitea that referenced this issue Feb 20, 2024
…-gitea#28662)

Mainly for MySQL/MSSQL.

It is important for Gitea to use case-sensitive database charset
collation. If the database is using a case-insensitive collation, Gitea
will show startup error/warning messages, and show the errors/warnings
on the admin panel's Self-Check page.

Make `gitea doctor convert` work for MySQL to convert the collations of
database & tables & columns.

* Fix go-gitea#28131

## ⚠️ BREAKING ⚠️

It is not quite breaking, but it's highly recommended to convert the
database&table&column to a consistent and case-sensitive collation.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/workaround it is or has a workaround type/bug
Projects
None yet
4 participants