-
-
Notifications
You must be signed in to change notification settings - Fork 560
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
Feature Request: Mysql/PostgreSQL Database option #89
Comments
Would be doable, but definitely needs some work. I limited the data types used to them available in SQLite. Also a lot of the "core logic" is done SQL views where some SQLite specifc SQL syntax/functions are used. Choosed SQLite because of the "everything should be as simple as possible" approach. I personally never had problems with any application that uses SQLite as the database. Also the whole Android app world is based on that database, so it's pretty stable, I think. The general data amount of grocy is also not that big (I use grocy now for over a year and the database file is still under 1 MB). I for myself will not work on that, sorry that I have to say that - but if anyone wants to do it, I'm of course available for questions. |
SQLite is fine for low-traffic databases. MySQL would be most useful for busy instances of grocy, as the more often database writes occur, the more likely it is that SQLite will throw "Database is locked" errors. (I learned this from IRC bots based on SQLite trying to maintain "Last seen" data in busy channels.) The best chance for this request getting implemented might be if grocy gets adopted by an operation—something bigger and more company-like than a household, though a non-profit would be good too—that starts to have scaling problems under SQLite because of the number of users they have. The organization might be willing to spend the time on adding MySQL support instead of switching platforms. |
Hi, I've spent some time today looking at what would be involved for enabling a MySQL backend. So far I've just modified DatabaseService.php to utilise a MySQL database rather than an sqlite database, and have been looking at modifying the queries in other parts of the code. I did get stuck at a point early on, when I got the following Slim Application Error: This was generated in in DatabaseMigrationService.php, by the line I have managed to work my way around that for now, but looking at MySQL logs it does seem like a lot of database connections are opened before closing others — this may be a problem to be reckoned with in the future. For now, it the biggest challenge is the time-consuming process of converting everything in The current state of play is that all paramaterised queries with a Will touch base again with any other findings, if I make further progress. I intend to update my fork of grocy in the coming days with what progress I have made. |
Thanks for your work on this! :)
No. I just put every new migration into a new file, which may depends on the migrations before. I thought about also shipping "the currrent final schema" for new installations in a single file, but so far I saw no problems about speed and the number of migrations... A big part of the logic is done in SQL Views and Triggers and I would say a bigger part of them use SQLite specific things - so maybe that would be a lot to do/change to make it compatible... I also still don't see the benefit. Have you hit problems with SQLite and grocy? If it's about database size and/or performance, see stats about the maybe biggest, yet still tiny, grocy production database (my personal one) in #438... |
There are API routes ( Additionally there is the global JavaScript variable So probably the error is about |
This comment was marked as spam.
This comment was marked as spam.
@jeauxlb Do you have fork, where you have commited these changes, as I could also try work on this. Seems stypid me to start again doing the conversion if you have already done some. |
Ah — MySQL thinks you mean TABLE KEY when it sees an unescaped "key" in a where clause. Escaped now, page loads successfully. My complete steps so far are:
I will try to post the code later this week but it's nowhere near where it needs to be to do that right now. |
Sounds good. If you can create own fork and keep it to date, would be awesome. Just to follow your progress 👍 |
Just a heads up from my time digging into the code I think another issue that will need some thinking about to overcome is monitoring for Db changes. At the moment this is done by checking to see if the sqlite db file has changed. You might need to record latest update times in the db and query it out. Glad you found the DatabaseService.php changes useful. It still needs tome tidying up as it still has the wrapper i inserted to monitor what calls were being made to the db. |
Can you just fake it and return a "yes, it's changed" every time? Is that practical from a usability/computational perspective? Not the most efficient obviously, but I'd just like to get it working. |
I was accually having a little sleep and thinking. Would it be impossible to rewrite this something like doctrine ORM aka, very high level abstraction? Like in case of ORM, we would just need to rebuild the schema and migrations to be correct. Also in case of getting last modified time, I think we do not do anything with that information unless it is record specific. I know this is lot of work, but it might pay back in long term and would help us achieve support for many other databases also. |
It's already using an ORM so that's exactly what my approach is. Some considerations:
|
Yeh, I see that. However, like you said, I have seen plenty of direct SQL code in the source and many of that is SQLite, like you said. That is kind of a problem, instead of that it would make much more sense to have read-write models for tables/views. And the views could be implemented in level of PHP, so it would make database more independent and not so version/type specific. I see your work as trying to do spaghetti top of spaghetti. Writing clear data models to define what table contains instead looking it from migrations folder would make more sense. Also in that case the data model would validate everything is setup correctly. In addition of data model, there can be this infrastructure type of approach having query and read separated into another model(s). I also do understand your way to avoid massive rewriting trough the source. If and when you can provide fork with your work I could start looking trough it and fixing issues while doing so. 🎖 |
The errors started to get more involved with javascript, an area with which I'm less familiar, so I thought I'd take you up on your offer. The schema (default login) is in the zip file attached. My fork is available at https://github.com/jeauxlb/grocy So far, known issues are:
|
What are you doing to test your changes? With a number of bits of work in progress for refactorings that impact much of the application some high level basic component tests or shared advice on testing would be helpful in detecting and understanding regressions easily. |
Well, currently nothing, I will be just testing it overall and checking for a bugs, which I could fix. Currently I need to deal with Magento security flaws, so cannot have time for this yet... |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Worked on this last night and a couple of hours today, not entirely done but I've managed to get almost everything working. This in no way will be "backwards" compatible in it's current shape, but hey at least it works. In my use-case I'm importing everything the supermarket has to offer, and just simply build recipes upon products that are available in the grocery store, makes my life much easier. The products overview page / stock overview page go bankrupt though when you try to pull up 21k products at once, so I'll still have to build in some type of pagination. I have the Cheers! |
It has been my experience that SQLite isn't the most reliable database out there and it would be nice to have the option to use a mysql database instead of SQLite. I noticed you are using LessQL as a ORM which supports mysql. How hard would it be to convert the DB gen scripts to mysql?
The text was updated successfully, but these errors were encountered: