-
-
Notifications
You must be signed in to change notification settings - Fork 355
Feature mysql driver support #511
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
base: develop
Are you sure you want to change the base?
Conversation
…an once in a prepared statement"
Thanks so much for this contribution. I really appreciate the time and thought you’ve put into it. That said, I’m going to hold off on merging this for now. There are a number of large features in the pipeline, and introducing support for two database engines would slow things down quite a bit. A few key reasons:
I'm not ruling this out permanently. If there's strong community demand and enough interest in maintaining MySQL compatibility, I'm open to revisiting it in the future. Thanks again. This is genuinely appreciated. |
…an once in a prepared statement"
Hi @daveearley , I want to clarify that I mean it as unofficial support. In my opinion, unofficial means that the project doesn't make any guarantees that it's tested or works with MySQL, like Wikimedia doesn't for PostgreSQL. Apart from adding I would find it pretty cool if all tests ran for MySQL and PostgreSQL, but I totally understand that there's a limit on how many GitHub Actions you get per month for free, and running tests twice would use that up twice as fast. That's not economical for you. The main work was to get the initial migration to work, which is all written in plain PostgreSQL. Existing migrations don't change; therefore, adding separate ones for MySQL doesn't introduce extra complexity, unlike queries that could change over time.
The type I agree, using conditional logic to run different raw SQL queries for MySQL and PostgreSQL maybe wasn't the right choice. It introduces the risk of bugs when the code for Postgres gets changed and MySQL gets forgotten, or it is double the work to maintain both versions. As you aren't interested in merging this, you probably don't want me to rewrite the queries without the conditional logic in Laravel's query builder? My idea was that with early unofficial support for MySQL, the project could incorporate tiny additions that don't cost any more time or mean more work but help the project to be more open to MySQL. For example, you already cast some datetimes and arrays with Laravel's cast functionality. If the project would cast all datetime and boolean values, that would help a lot. Is there any chance I can convince you to merge the changes for the old migrations and the casts, maybe in a different merge request? |
Laravels query builder supports mysql out of the box. Only raw sql must be altered for mysql support. Thankfully, apart from the inital migration, only four files contain some postgres specifc queries. Fixes #488.
Migrations
The initial migration is a big raw sql file. It got adapted to mysqls syntax whenever possible. When migrating the schema.sql or the schema.mysql.sql get executed based on the selected driver. Here are the modifications
boolean casting
Mysql does not have a native boolean type. Instead it uses tinying(1) which can only be 0 or 1. In c that would be considered a boolean but PHP differentiates and does not allow implicit int to boolean casting. The programm adds that to the function getCastMap(): array. It does not affect postgresql. It does not add complexity nor potential for bugs.
prepared statements and named bindings
In the official php docs (https://www.php.net/manual/en/pdo.prepare.php) it says:
The code fixes that in a separat commit. Apparently,it still worked anyway in postgresql.
single binding array syntax
In psql arrays can be passed as one value and than unnested. This means data is grouped by column not by row and thus only needing |columns| many placeholders/bindings. Mysql does not has an array datatype outside of json. I decided to not change that code but rather branch by database driver to leave code untoched and leave in potential performance gains.
The mysql specific code updates/inserts data row by row in the traditional way in a foreach loop. It would be possible to pack it into one query with many questionmarks as placeholders/bindings but i don't know how many rows will be updated. Mysql like postgresql has a prepared parameter count limit in the thousands so at some point it had to be split into multiple queries. To avoid that added complexity, it's a simple loop.
different time syntax
Mysql und psql use different syntax for time. The new code differentiates with a simple variable and if statement.
Checklist
Thank you for your contribution! 🎉