fix: support utf8mb4 across MySQL and MariaDB
Test / test (push) Canceled after 6m35s
Build and publish image / image (push) Successful in 13m42s

This commit is contained in:
bryanpedini committed 2026-11-20 15:14:28 +01:00
1 parent cce17c5fa4
commit d34894c9cd
28 files changed
+224 -121

No files matched your search

+9 -7
View File
@@ -50,7 +50,7 @@ func (s delegationStore) GrantDelegation(ctx context.Context, zone string, userI
func (s delegationStore) RevokeDelegation(ctx context.Context, zone string, userID int64) (bool, error) {
defer traceStore(ctx, "delegationStore.RevokeDelegation")()
res, err := s.q.ExecContext(ctx, s.t.sql("DELETE FROM {delegations} WHERE `zone` = ? AND `user_id` = ?"), zone, userID)
res, err := s.q.ExecContext(ctx, s.t.sql("DELETE FROM {delegations} WHERE `zone` = CAST(? AS BINARY) AND `user_id` = ?"), zone, userID)
if err != nil {
return false, fmt.Errorf("revoke delegation: %w", err)
}
@@ -65,7 +65,7 @@ func (s delegationStore) ZoneUsers(ctx context.Context, zone string) ([]userRow,
defer traceStore(ctx, "delegationStore.ZoneUsers")()
rows, err := s.q.QueryContext(ctx,
s.t.sql("SELECT "+userColumns+" FROM {delegations} d JOIN {users} u ON u.`id` = d.`user_id` "+
"WHERE d.`zone` = ? AND u.`role` = 'user' AND u.`deleted_at` IS NULL ORDER BY u.`username`"), zone)
"WHERE d.`zone` = CAST(? AS BINARY) AND u.`role` = 'user' AND u.`deleted_at` IS NULL ORDER BY u.`username`"), zone)
if err != nil {
return nil, fmt.Errorf("zone users: %w", err)
}
@@ -98,9 +98,11 @@ func (s delegationStore) UserZones(ctx context.Context, userID int64) ([]userZon
func (s delegationStore) DeleteZoneDelegations(ctx context.Context, zone string) ([]delegationRow, error) {
defer traceStore(ctx, "delegationStore.DeleteZoneDelegations")()
// Lock delegations only. Usernames are immutable and the foreign key
// keeps the referenced users present.
rows, err := s.q.QueryContext(ctx,
s.t.sql("SELECT d.`zone`, d.`user_id`, u.`username`, d.`created_at`, d.`created_by` FROM {delegations} d "+
"JOIN {users} u ON u.`id` = d.`user_id` WHERE d.`zone` = ? ORDER BY u.`username` FOR UPDATE OF d"), zone)
s.t.sql("SELECT d.`zone`, d.`user_id`, (SELECT u.`username` FROM {users} u WHERE u.`id` = d.`user_id`) AS username, d.`created_at`, d.`created_by` "+
"FROM {delegations} d WHERE d.`zone` = CAST(? AS BINARY) ORDER BY username FOR UPDATE"), zone)
if err != nil {
return nil, fmt.Errorf("delete zone delegations: %w", err)
}
@@ -122,7 +124,7 @@ func (s delegationStore) DeleteZoneDelegations(ctx context.Context, zone string)
if len(deleted) == 0 {
return nil, nil
}
if _, err := s.q.ExecContext(ctx, s.t.sql("DELETE FROM {delegations} WHERE `zone` = ?"), zone); err != nil {
if _, err := s.q.ExecContext(ctx, s.t.sql("DELETE FROM {delegations} WHERE `zone` = CAST(? AS BINARY)"), zone); err != nil {
return nil, fmt.Errorf("delete zone delegations: %w", err)
}
return deleted, nil
@@ -142,10 +144,10 @@ func (s delegationStore) hasDelegation(ctx context.Context, query, zone string,
func (s delegationStore) HasDelegation(ctx context.Context, zone string, userID int64) (bool, error) {
defer traceStore(ctx, "delegationStore.HasDelegation")()
return s.hasDelegation(ctx, "SELECT 1 FROM {delegations} WHERE `zone` = ? AND `user_id` = ?", zone, userID)
return s.hasDelegation(ctx, "SELECT 1 FROM {delegations} WHERE `zone` = CAST(? AS BINARY) AND `user_id` = ?", zone, userID)
}
func (s delegationStore) HasDelegationForShare(ctx context.Context, zone string, userID int64) (bool, error) {
defer traceStore(ctx, "delegationStore.HasDelegationForShare")()
return s.hasDelegation(ctx, "SELECT 1 FROM {delegations} WHERE `zone` = ? AND `user_id` = ? FOR SHARE", zone, userID)
return s.hasDelegation(ctx, "SELECT 1 FROM {delegations} WHERE `zone` = CAST(? AS BINARY) AND `user_id` = ? LOCK IN SHARE MODE", zone, userID)
}