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 case sensitivty fix #28651

Closed
wants to merge 6 commits into from
Closed

MySQL case sensitivty fix #28651

wants to merge 6 commits into from

Commits on Dec 29, 2023

  1. settings: charset & collate settings for the db

    Remove the (undocumented) `Database.MysqlCharset` setting, and
    introduce `Database.DefaultCharset` and `Database.DefaultCollation`
    settings instead.
    
    The reason for the `MysqlCharset` removal is that in a later patch,
    we're going to adjust the engine initialization so that it achieves
    similar results, in a different way.
    
    The new settings will remain undocumented for similar reasons
    `MysqlCharset` was undocumented: the defaults work for the vast majority
    of cases, and it's too easy to break things if changing them.
    
    Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
    algernon committed Dec 29, 2023
    Configuration menu
    Copy the full SHA
    b62b1d3 View commit details
    Browse the repository at this point in the history

Commits on Dec 30, 2023

  1. db: Make ConvertUtf8ToUtf8mb4() more flexible

    Replace `db.ConvertUtf8ToUtf8mb4()` with
    `db.ConvertCharsetAndCollation()`, which does essentially the same
    thing, but the charset and the collation is controlled by the caller.
    
    Also introduce `db.findCaseSensitiveCollation()` which attempts to
    auto-detect the best supported case-sensitive collation for MySQL and
    MariaDB databases.
    
    With these two functions, `gitea doctor check` can be adapted to use the
    charset and collation set in the configuration (or auto-detect them, if
    unset), and this patch does that too.
    
    Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
    algernon committed Dec 30, 2023
    Configuration menu
    Copy the full SHA
    dcde4e3 View commit details
    Browse the repository at this point in the history
  2. cmd/web: Perform a db sanity check on startup

    When starting the web server, perform a sanity check on the database.
    The sanity check currently runs for MySQL/MariaDB only, and verifies
    that the charset and collation are correctly set on both the database,
    and on all tables in it.
    
    If there is a discrepancy, it does not error out, but prints a warning
    only.
    
    Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
    algernon committed Dec 30, 2023
    Configuration menu
    Copy the full SHA
    ec6ba9a View commit details
    Browse the repository at this point in the history
  3. db: Automatically adjust database props on init

    When initializing an empty MySQL/MariaDB database, ensure that the
    character set and collation is set to the desired values.
    
    With these set, creating a table will inherit these settings, unless
    table creation specifies a different charset or collate function. This
    is the reason why `setting.Database.MysqlCharset` was removed: that
    forced table creation to explicitly set a charset, rather than inherit
    the database's default, and in doing so, also changed the collate
    function to the charset's default (which may - and usually is -
    different from the one we want).
    
    Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
    algernon committed Dec 30, 2023
    Configuration menu
    Copy the full SHA
    9f48545 View commit details
    Browse the repository at this point in the history
  4. git/branch: Remove a comment that is no longer relevant

    Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
    algernon committed Dec 30, 2023
    Configuration menu
    Copy the full SHA
    25a1d3d View commit details
    Browse the repository at this point in the history
  5. [DOCS]: Suggest better collate functions for the db

    For MySQL, suggest not setting a collate function, to let Gitea deal
    with it. But also mention some of the options, would one want to set it
    up in advance and not rely on Gitea.
    
    Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
    algernon committed Dec 30, 2023
    Configuration menu
    Copy the full SHA
    1179813 View commit details
    Browse the repository at this point in the history