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 Cluster support - Need primary keys on all tables #2769

Closed
jgupta opened this issue Apr 7, 2021 · 8 comments · Fixed by #2794
Closed

MySQL Cluster support - Need primary keys on all tables #2769

jgupta opened this issue Apr 7, 2021 · 8 comments · Fixed by #2794
Milestone

Comments

@jgupta
Copy link

jgupta commented Apr 7, 2021

Bug Report

Current Behavior
Installation on Percona MySQL Cluster fails with error - Something went wrong: SQLSTATE[HY000]: General error: 1105 Percona-XtraDB-Cluster prohibits use of DML command on a table (xxx.fl_migrations) without an explicit primary key with pxc_strict_mode = ENFORCING or MASTER (SQL: insert into xx_migrations (migration, extension) values (2015_02_24_000000_create_access_tokens_table, ?))

Steps to Reproduce

  1. Install on Percona MySQL cluster (or any mysql cluster) with strict mode set to enforcing.

Expected Behaviour
Installation should work.

Possible Solution
All tables should have primary keys

Additional Context
https://www.percona.com/doc/percona-xtradb-cluster/LATEST/features/pxc-strict-mode.html#tables-without-primary-keys

@luceos
Copy link
Member

luceos commented Apr 7, 2021

We had the same issue at @blomstra using Percona and are migrating that manually for now. But this is a great addition to flarum/issue-archive#121.

@askvortsov1
Copy link
Sponsor Member

Agree we should implement this. Other than migrations, which tables are affected?

@jgupta
Copy link
Author

jgupta commented Apr 7, 2021

@askvortsov1 All other tables except migrations seem to have primary keys.

Can you guide me to the correct place in code so that I could maybe patch this and finish installation at my end? I tried to look for the code that is creating migrations table.

@askvortsov1
Copy link
Sponsor Member

Interesting, looks like it's hardcoded outside of migrations in https://github.com/flarum/core/blob/94d69fe15fbcc459c84fcad5a0d5b274d9d7fe48/src/Database/DatabaseMigrationRepository.php#L91-L104.

We should adjust that to include a proper primary key on new installs, but how do we want to handle old installs? Could do a migration and include that by default on new installs...

@jgupta
Copy link
Author

jgupta commented Apr 8, 2021

Thank you @askvortsov1
I changed the code to following.

        $schema->create($this->table, function ($table) {
            $table->increments('id');
            $table->string('migration');
            $table->string('extension')->nullable();
        });

There was another error related to posts table being MyISAM. Change it to InnoDB from the beginning (I think it is later altered to InnoDB later in setup).

Now that initial setup is done, we can test it further.

@askvortsov1 askvortsov1 added this to the 1.0 milestone Apr 16, 2021
@askvortsov1
Copy link
Sponsor Member

@luceos @tankerkiller125 let's just add an incrementing ID in a migration + in the DatabaseMigrationRepository script? Or should we use the migration column as an explicit primary key?

@tankerkiller125
Copy link
Contributor

I'm for making the migration name the primary key. Notably since it's basically impossible to have duplicate names there anyway.

@askvortsov1
Copy link
Sponsor Member

I'm for making the migration name the primary key. Notably since it's basically impossible to have duplicate names there anyway.

Tested locally, and immediately ran into a duplicate migration name 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants