Declared dependencies #242
Replies: 7 comments 5 replies
-
Cc @wokket |
Beta Was this translation helpful? Give feedback.
-
Thanks for the invite mate, I'd missed this. Can I ask what the situation is that you're hitting here to need this? Migrating from another tool or something? I'll have a proper look through the code soonish, but from the quick first glance I'm interested, but not convinced this adds enough value (vs managing the dependencies with filename, rather than header comments) to be worth the extra complexity. I am a bit scarred atm with the outstanding bugs we need to work through though so a bit gunshy on the new features atm :) |
Beta Was this translation helpful? Give feedback.
-
In my world, the object name (as in SQL Server) is a first class citizen. This is practical for two reasons:
If then I needed to make
One can argue that since B comes before M why do this? Well, What if we then decide to move
If later on you refactor My solution bypasses all of this - but only if requested by the user on the command line. Without them passing the correct flag in, none of the dependency code kicks in. The beauty of this solution for me though is that the dependencies are handled in one location: The file itself. When modifying the script you can simply add or remove the associated line to instantly refactor the dependencies. This also handles when a table structure changes. Right now you may need to have a name like In my World My table folder has subfolders for each table: My script header for dim.Warehouse that requires this table looks like this: /***********************************************************************************************************************
Table: Warehouse
Schema: dim
Created: 09/06/2022
Author: Rachel Ambler
Use:
Requires: Tables\dim.Currency\*.sql
Notes
========================================================================================================================
Change History
Date Initials WI Details
========================================================================================================================
09/06/2022 RHA 0023 Created
***********************************************************************************************************************/ And that's it. That totally defines everything I need to know. In addition anyone else looking at it can see the dependencies without needing to look at the definition. If I ever get to the state where I no longer need that dependency then simply removing the entry performs all my refactoring. No other work needs to happen in the repository and therefore no risk of extra script suddenly executed simply because of a name change. That help clarify this approach? |
Beta Was this translation helpful? Give feedback.
-
To answer your other question: We're moving off Redgate's Sql Source control for a few reasons:
However the one thing which I do like about it is that the repository is clear: The table has a script and that's it. Every object is named exactly as it appears on Sql. I'm a power user at Pure Romance - we automated a huge amount (including building SSIS packages on the fly because they're too large to do manually with a huge number of dependencies). For me I totally understand if y'all prefer to keep |
Beta Was this translation helpful? Give feedback.
-
Hi, @RachelAmbler ! Thanks a lot for starting on this! This feature is really, really interesting! I have looked at a codebase using Redgate tools as well, and tried to use grate instead, but I got stuck pretty quick, due to exactly this, dependency management. I'm really keen to add the feature, I'd just take some time to discuss it, so that we can come of with the simplest/best solution together :) In experience, handling dependencies "manually", via files, comments, etc, is a bit tedious. So, if we could create a way to "magically" handle this, it would be even better (if it is at all possible). When it comes to programmability, I think we could have handled it by just trying to run scripts in the order they are, and save the ones that don't work, due to dependencies, for later (in a list of sorts). The Since you have experience with the Redgate tools, do you know how they handle inter-script dependencies? Is there a service installed on the DB which handles it, do you know? |
Beta Was this translation helpful? Give feedback.
-
@RachelAmbler , Thanks a lot for your work here. I have had the time to look through it a bit more thoroughly now, and I like the feature! I still have some questions on how this will work in a long-lived sources code base, if you change dependencies of tables, etc, over time, but that is perhaps a different question. I'd really like to merge this into grate, as I think it would benefit the whole of grate's user base if we could keep features in the main repo, and not having to have forks all over because I'm a grumpy old guy, and don't want to merge stuff :) That said, I think some cleanup of the code would be good before I merge this into main. How would you prefer to work on this? I have some suggestions, firstly regarding the reading of files in the DependencyHandler, which could be done easier. And, I think I would prefer to separate out the file sorting as a "first-class citizen" of its own (interface/abstract class), where the current sorting behaviour (by filename) could be the default, and the "sort-by-dependencies" strategy that you have created could be an alternate one :) And, in addition, I would appreciate some unit tests on the topological sort as a separate unit, as it is quite complex. I think it would be easier to work together on these fint tunings together if you make a pull request on the changes (I can't see that you have?). I'm not sure if you can do this from Codeberg (I haven't used that previously), or if you need to push it to a Github account. Do you think you can please create a PR, so we can get closer to getting this merged? And again, I appreciate your work! |
Beta Was this translation helpful? Give feedback.
-
I know this discussion is pretty stale, but I'm curious if it ever made any progress? We have many functions/procedures with dependencies, and I think a feature like this would be welcome. I considered using subfolders to group scripts so that they can be run after any required scripts, but would prefer to avoid the discoverability hit of nested folders. |
Beta Was this translation helpful? Give feedback.
-
@erikbra : I had the need to provide for declared file dependencies in grate so I put one together at https://codeberg.org/RachelAmbler/grate/src/branch/Add_Sql_Code_Dependency_Functionality
It's only used if specifically called for and includes all tests etc. I'm still doing some final code cleanup etc. so it's not ready for primetime, but if you're interested in this forming part of grate then let me know and I'll issue a pull request for it. (It is all fully documented with a new docs page for it)
This is the first of a few 'value add' pieces I need to add to bend grate to my will - however they may be more niche than you're looking for in some cases - but let me know your thunks and we can discuss accordingly.
Beta Was this translation helpful? Give feedback.
All reactions