Skip to content

v2.45.0: MySQL migration 13 fails - groups is a reserved word #4579

@backkem

Description

@backkem

Bug

Migration 13 (from #4456) fails on MySQL >= 8.0.2 because groups is a reserved word since that version.

failed to initialize storage: failed to perform migrations: migration 13 statement 2 failed:
Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'groups blob' at line 2

The column name needs backtick-quoting in the MySQL-flavored migration statements in storage/sql/migrate.go:

-- current (fails on MySQL >= 8.0.2)
alter table password add column groups bytea;
update password set groups = '[]' where groups is null;
alter table password modify column groups bytea not null;

-- fix
alter table password add column `groups` bytea;
update password set `groups` = '[]' where `groups` is null;
alter table password modify column `groups` bytea not null;

Additionally, since MySQL auto-commits DDL, statement 1 (preferred_username) gets persisted even when statement 2 fails and the transaction rolls back. This leaves the migration in an unrecoverable half-applied state on restart.

Happy to submit a PR for this if wanted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions