-
Notifications
You must be signed in to change notification settings - Fork 824
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
Replace Database layer with doctrine/dbal #6632
Comments
Dan, could you outline which classes you'd see as being replaced by dbal, and where the coupling points to dbal woud be? |
I think this work is something that will need to be done in steps. In the long term I'd like to see pretty much everything in our The more I'm looking into doctirne/dbal the more I'm seeing how powerful it is and that it appears that it will solve some problems for us or, at least, make it simpler to do things we do now. Automatica aliasing of table names is one example. I don't see a big change in coupling points; anywhere we currently couple to |
Ok I'm not opposed to this, but I'm not sure I'd rate its priority highly for SS4. My instinct is that it's probably more work to do this that fix the issues we already know about. That said, if you were going to drive this, you'd get to make the priority call. ;-) I've got mixed feelings about doing a half-job of this to hit the SS4 timeline too. It depends a bit on what a "half job" would look like but I'd be more keen to leave SS4 in a consistent state than to just try and squeeze something in. I'd also note that I'm much more nervous about replacing the ORM, but you seem to be more or less in agreement with that too. |
That may well be the case; but I think this is the wrong way to approach. Whilst the cost to solve the known issues now may be less than integrating a 3rd party lib, the integration will pay-off in the long run, especially if SS4 is going to be an LTS release. Having said that, I don't think it should be a priority for SS4 - there's only so much that can be done in time for the release. I've been taking a look at integrating it in my evenings and it does look very nice and I've got the CMS loading and so on, so I'll spend some more time looking into it but with no commitment to being able to complete for the beta. |
RE the ORM - yes, I don't think that's anything we can remove any time soon. Laravel's is the closest in terms of syntax and familiarity, but there's no MTI. No matter what we'd be maintaining our own extension of another ORM if that were ever to happen... I'm focused on the areas where we have little differentiation from other libraries. Right now, doctrine/dbal looks like a great fit. |
I haven't used either of those database connectors extensively so can't really comment on the specifics for each, but I think that the idea of changing out the DB connector is a good one for the exact reasons you've outlined. |
I'd merge a PR if you did this, but it won't get into open sourcerers' backlog. |
This won't block the beta1 milestone. If you manage to do this, then great, otherwise it'll likely be an SS5 item. |
From my initial investigation work on this there are a few key areas where doctrine/dbal doesn't work quite the same way that our DB layer does or has "missing features". Potential blockers:
High effort upgrades:
Benefits of doctrine/dbal:
|
OK, based on that feedback, particularly point 2 of "high-effort upgrades", I can't see this happening in SS4. On the potential blockers:
|
On the benefits: I see point 2 as being achieved by moving the database to an Injector service, which is something that is much more likely for SS4. |
If the ORM were split into a separate composer package, then you could potentially use |
Blockers:
That's true and I'd like that myself, but we'd have to decide how granular we really want to split the framework... A discussion for another thread, perhaps. |
In terms of high effort upgrade points, really the solution is to improve the abstraction layer ( |
Have you looked at readbeanphp http://redbeanphp.com/index.php? Very lightweight, manages the schema for you (unless you say 'freeze' e.g. in test/live environments), I've used in play code and great for prototyping, not sure re production, performance etc. |
I've had a few plays with redbean, it's pretty nice, but I'm not well-informed enough to know if it suits SilverStripe |
I haven't looked at redbean. I've take a quick browse now but it doesn't look quite right for SS. doctrine/dbal works really well with our current approach |
Summary of stuff @dhensby and I discussed on slack:
On enums, they aren't supported well in many DB connectors anyway. I don't mind it being supported above the DB level if necessary. Framework also has multi enum, which is again harder to support. |
You need quotes for capital letters. Although you're recommending that capital letters are removed from identifiers, you're likely to get edge-case issues for example in the code that migrates from the old identifier names to the new. As such I'd recommend that anything that auto-generates SQL only adds quotes to identifiers that contain a capital letter or other reserved character, rather than avoiding them entirely. |
Apparently quoting happens internally in doctrine so not anything we need to worry about. :) I'm not sure I understand the significance of capital letters in identifiers. @dhensby says we need to use all lowercase from here on anyway. I think we probably just strtolower in the sql generation (middleware?). |
doctrine/dbal does this automatically (at least for reserved words). You can see their response to a ticket I opened a while ago here: doctrine/dbal#2710 (comment)
We will need to write this kind of migration manually, I'm afraid. The dbal layer doesn't provide a way to distinguish between different cased identifiers in the abstraction layer. This could be part of upgrader 2.0. It'll also spell the end of case correction logic for table names / columns. |
I've raised an RFC to remove support for enums at #8401 |
This hasn't been touched in a few years, and I want to flag that I question whether the benefit of this will ever be worth the upgrade pain that it would inevitably cause. The fact is that the current base access layer, while not perfect, is not in my view a particularly large source of either bugs or or maintenance (feel free to challenge that). I noted on #9520 a comment from @dnsl48:
As such, I wonder if keeping this ticket open as a "someday, maybe" item is preventing appropriate decision-making on other issues. |
Regarding #9520, I don't think this issue affected my judgement there :) |
Ah, right :) |
I agree there probably isn't much value in keeping this open. It's a huge amount of work. I've actually had a DBAL rewrite done and then got most of the tests green only to find our approach of using case sensitive column names was actually a bit of a problem and that using ansi-quotes was also an issue. This drastically increased the scope of the work and I haven't been able to progress it since then. To get a new DB layer in we actually need a proper domain specific querying layer (which we almost have with DataQuery) except that we also allow raw SQL to be injected and that needs to be replaced with an abstracted layer. All-in-all, it's going to need some proper concerted effort and a hell-of-a-lot of cross-module breaking changes... |
More and more we're seeing issues raised about our DB layer and it not working under specific circumstances. Our DB layer is also in need of a slight refactor to properly separate concerns and stop us hard coding logic related to DB drivers into our generic connectors.
Rather than spending our time re-factoring our DB connectors and maintaining an incomplete set of DB drivers I suggest we move our DB layer to a thirdparty - this will have the advantages of:
I've looked at Laravel's Illuminate and Doctrine's DBAL. Laravel's database component is far too tightly coupled to the Eloquent ORM - we'd have to pull it in even though we aren't going to use it.
Looking into doctrine/dbal and it's got a really nice API and a very similar architecture to our current DB layer. It looks like a pretty awesome and well architected DB layer as well as giving us the advantage of a lot of stock drivers and any other open-source drivers that have subsequently been written.
If we're able to swap out our DB layer, we'll drop a lot of hand-rolled code whilst improving functionality and focusing on adding value.
Other advantages:
Issues:
*Personally, I think this is something that we should be doing anyway as Enums can be painful for a number of reasons see doctrine's docs on enums
The text was updated successfully, but these errors were encountered: