-
Notifications
You must be signed in to change notification settings - Fork 218
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
Support Mysql #224
Comments
This is a blocker in our evaluation of flipt |
@derekperkins I plan to try and tackle this over the long weekend coming up |
Just an idea: maybe consider using an ORM for a DB storage implementation? There aren't many good ORMs for Go unfortunately, but this looks promising: https://github.com/facebookincubator/ent Normally, I'm not a huge fan of ORMs because they hurt application architecture and gives less experienced developers the wrong ideas, but as an implementation of an interface they work great, because they allow you to work rapidly. |
@sagikazarmark thanks for the suggestion! i'll take a look for future use The squirrel library im using to construct the queries does a pretty good job of abstracting the db specific stuff, so it's mainly just handling the different error codes that are thrown from the different drivers when there are constraint violations/etc. I have a branch where im abstracting the sql code to be able to handle the specific errors more cleanly depending on the driver being used. I hope to have this finished this weekend.. just trying to find the time to work on it! |
@derekperkins @sagikazarmark I am extremely close to shipping this!.. However, I could actually use some help figuring out why a couple test cases are failing intermittently, but only when running with MySQL. Would either of you (or anyone else) be able to help? My MySQL skills are a bit rusty. You can see one of the failures in this Action run: https://github.com/markphelps/flipt/runs/791147606?check_suite_focus=true#step:6:632 And here's another time when running locally:
To Reproduce
IdeasI'm assuming the issue has to do with inconsistent result ordering being return from the following line: Which results in this SQL query:
This seems like a pretty basic query.. so I'm not sure what I'm doing wrong? Again, this works fine in Postgres and SQLite, so im not sure if there is some MySQLism I am missing? Here is the schema that I'm using for MySQL btw: https://github.com/markphelps/flipt/blob/mysql2/config/migrations/mysql/0_initial.up.sql Any pointers would be greatly appreciated 🙇🏻 |
The generated query looks fine and should be reliable. I'm not quite sure what your schema is doing with the
On an unrelated note, the only MySQLism that might get you is that pre-8.0 doesn't use true utf-8 by default. You should probably set your tables with |
I couldn't actually get the tests to run following the instructions above, because the schema migrations failed. After fixing them (#304), the tests are still failing though. One possible reason for that is mysql timestamps store seconds and it looks like records are created too quickly (and the query orders records by the creation timestamp): (Side note: this wouldn't be a problem if you used a lexographically sortable ID, like ULID or KSUID, because MySQL uses the primary key for ordering) Another error I see is also related to time:
Generally, I think time is not a reliable way to order records. If order doesn't actually matter, then I would probably rewrite the tests to ensure each expected item can be found in the result set, regardless of the order. Alternatively, you could mock out time and fake sleep between inserts. That requires you to manage creation and update timestamps, but that's usually in fact a good idea, to not rely on the database, but always set the timestamp from the code which guarantees you will always get the same result. |
Further looking into the topic, it looks like mysql 8 actually supports storing fractional seconds with the original syntax I removed in #304, but my guess for the breaking tests is still wrong order because of time. I guess you could add support for mysql 5.x and 8 separately, but I'm not sure it's worth it. |
@sagikazarmark @derekperkins Thanks for both of your help! I pushed a 'beta' version that supports MySQL to DockerHub:
Please try it out if you can. I want to verify it works as expected before merging it into master and cutting a release version. You can set it to connect to an existing MySQL DB by running it like so:
Here's more info about configuration and running with Docker. |
MySQL is still a popular DB, so let's support it
The text was updated successfully, but these errors were encountered: