Browse Source

migrations: add MySQL migration to fix missing primary keys on group tables

groups_users and collections_groups were created with UNIQUE constraints
  instead of PRIMARY KEY in the 2022-07-27 migration. Add a new migration
  that promotes the unique indexes to primary keys.

  MySQL auto-names a UNIQUE constraint after its first column, so the index
  names to drop are 'groups_uuid' and 'collections_uuid' respectively.
pull/6997/head
TriplEight 2 weeks ago
parent
commit
7cedcae881
No known key found for this signature in database GPG Key ID: 9E9B1BBD89CE29A1
  1. 4
      migrations/mysql/2022-07-27-110000_add_group_support/up.sql
  2. 7
      migrations/mysql/2026-03-22-100000_add_primary_keys_to_group_tables/down.sql
  3. 10
      migrations/mysql/2026-03-22-100000_add_primary_keys_to_group_tables/up.sql

4
migrations/mysql/2022-07-27-110000_add_group_support/up.sql

@ -11,7 +11,7 @@ CREATE TABLE `groups` (
CREATE TABLE groups_users (
groups_uuid CHAR(36) NOT NULL REFERENCES `groups` (uuid),
users_organizations_uuid VARCHAR(36) NOT NULL REFERENCES users_organizations (uuid),
PRIMARY KEY (groups_uuid, users_organizations_uuid)
UNIQUE (groups_uuid, users_organizations_uuid)
);
CREATE TABLE collections_groups (
@ -19,5 +19,5 @@ CREATE TABLE collections_groups (
groups_uuid CHAR(36) NOT NULL REFERENCES `groups` (uuid),
read_only BOOLEAN NOT NULL,
hide_passwords BOOLEAN NOT NULL,
PRIMARY KEY (collections_uuid, groups_uuid)
UNIQUE (collections_uuid, groups_uuid)
);

7
migrations/mysql/2026-03-22-100000_add_primary_keys_to_group_tables/down.sql

@ -0,0 +1,7 @@
ALTER TABLE groups_users
DROP PRIMARY KEY,
ADD UNIQUE (groups_uuid, users_organizations_uuid);
ALTER TABLE collections_groups
DROP PRIMARY KEY,
ADD UNIQUE (collections_uuid, groups_uuid);

10
migrations/mysql/2026-03-22-100000_add_primary_keys_to_group_tables/up.sql

@ -0,0 +1,10 @@
-- groups_users and collections_groups were created with UNIQUE instead of
-- PRIMARY KEY. Diesel requires primary keys on all tables for schema
-- introspection. Drop the auto-named unique index and add the primary key.
ALTER TABLE groups_users
DROP INDEX groups_uuid,
ADD PRIMARY KEY (groups_uuid, users_organizations_uuid);
ALTER TABLE collections_groups
DROP INDEX collections_uuid,
ADD PRIMARY KEY (collections_uuid, groups_uuid);
Loading…
Cancel
Save