-
-
Notifications
You must be signed in to change notification settings - Fork 260
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
Add metadata to stored procedures for 3rd party libs #3408
base: master
Are you sure you want to change the base?
Conversation
Ohh, I hoped you already have a solution, but this PR is just an issue, with a code example, isn't it? Just reading the title and the description I tought you would implement a new entrypoint for 3rd party libs in the ddl generation code to programatically put those (Just to note: I'm just a follower, I don't even use Ebean. 😅 But the solution you came up is very interesting. Subscribed to the issue.) |
No, this is not just an issue, it's also an actual pull request with the change required to make this work. The only thing that needs to be discussed is the naming of the "meta data".
No, this isn't necessary, my solution is much simpler and does its job perfectly.
You come here from the Play Framework issue? |
I was browsing the activity of the repo with OctoDroid and noticed that the lead developer of Play! Framework opened a PR with an interesting title. 🙂 |
Well, I think there are 2 other alternatives to consider. One option would be to just copy Ebean's DdlParser code - https://github.com/ebean-orm/ebean-ddl-runner/blob/main/src/main/java/io/ebean/ddlrunner/DdlParser.java#L55-L61 ... with the benefit that this would work with not just ebean migrations but any DDL scripts that people want to parse and execute. A second option is to adjust the Play parser to support the "more standard" delimiters and I'm pretty sure there are only the 2 cases needed to be supported for identifying the start and end which is:
So these approaches have some benefit as I see it. Have these options been considered? |
I'm not sure if there is a misunderstanding here but Ebean has 2 types of DDL generation: Ebean will regenerate the "create-all.sql" / "drop-all.sql" every time but to be clear these are never intended to be used for db migrations but instead for general local development running tests. People should not be treating these as migration scripts. Ebean has a separate tool to generate db migrations (based on a "diff" of the model). This tool is generally explicitly run to generate the next db migration script (and model change). When we want to create a db migration we should use this tool and this does not re-generate or override any ddl scripts etc.
To me that sounds like it does not support MS SQL Server |
a011610
to
c26ff41
Compare
@rbygrave This is what we do currently: https://github.com/playframework/play-ebean/blob/main/play-ebean/src/main/java/play/db/ebean/EbeanDynamicEvolutions.java#L118-L137 And how does your diff mechanism work? Thanks! |
@rbygrave One more thing: I do think about that our play evolutions script parser should eventually become smart enough to understand stored procedures. However, I want to make that bullet proof and will need some time. Completely independent of that (play-)ebean problem we face, what I also want to do in general, is to add a config to Play where folks can define a start "label" and end "label", as sql comments, which makes the play evolutions script parser not split on semicolon for all semicolons that are between such two labels (sql comments). Again, this is a more general issue for us and not directly related to play-ebean. I opened an issue for that with example code: Now... if you look at the diff of this pull request, would it be possible if you add such meta comments to you procedures, just like this PR? You could choose any comment "names" you desire, it just would have to be a "start" and and "end" label. Would you consider merging my PR with a naming of the comments that you choose? |
Just an idea, something like:
|
c26ff41
to
7a481e7
Compare
This way a third party can parse the meta data and knows how to handle the bodies of a stored procedure
7a481e7
to
6d3552a
Compare
@rbygrave So I updated the pr with |
@mkurz Any thoughts? |
Hi @rbygrave!
You may remember the problem we, from the Play Framework, had in
The problem is that Play splits sql scripts by
;
meaning that any stored procedures that usually contains;
in their body will be split into weird statements, making the sql script fail. We do have an escape mechanism by using two;;
, which avoids the string getting split and the double;;
will end up as a single;
in the final statement.The problem is that when ebean (re)generates its ddl scripts it will override existing once, so each time people would have to replace
;
with;;
which is annoying. Even worse, lots of people don't even know what's going on and just see an exception without having a clue why ebean generated ddl scripts don't apply with Play evolutions and just open issues like "ebean doesn't work", "play-ebean doesn' work", etc.Now I think the solution to this problem is actually quite easy:
If you could add meta data to your ddl scripts, like shown in this pull request, we could easily parse that meta data and make Play evolution ignore the semicolon within such a "meta data block".
The naming of the meta data comments I came up with is currently:
but I am totally open for other naming.
What do you think about that? IMHO this shouldn't hurt ebean but 3rd party libraries would benefit from finally being able to correctly handle your ddl scripts.
Thanks!