Removing objects from git repo that have be subsequently filtered in SQL Source Control

Hi,

It seems in SQL Source Control (SSC), if you had previously committed an object (say table A), but then later add a Filter into SSC to filter out table A, then the SQL file for table A still remains in the git repo.

Is there any easy way to remove objects from the SSC git that are no longer tracked (i.e. filtered out) in SSC?  I could do the delete manually, but I'm sure I'd overlook some.

Thanks
Peter  

Best Answer

  • David AtkinsonDavid Atkinson Posts: 1,458 Rose Gold 2
    If you use SQL Compare (using the same filter) and script out your database to a scripts folder, then compare this scripts folder against the scripts folder in your Git repo, then you'll get a list of differences which should represent the objects that need to be removed from the repo. SQL Compare should be able to remove them for you if you run a deployment based on the comparison of both scripts folders, this time without the filter being used. 
    David Atkinson
    Product Manager
    Redgate Software

Answers

  • BugmeisterBugmeister Posts: 21 New member
    Ok thanks David, I'll give that a try.  Hadn't really been leveraging SQL Compare for anything, so this'll be a good learning experience.
  • @Bugmeister - Let us know how you're getting on or if you need any further help.

    David Atkinson
    Product Manager
    Redgate Software
  • BugmeisterBugmeister Posts: 21 New member
    David,

    Yep your suggestion worked, with a few comments:

    • Using File -> "Create Scripts Folder..." in SQL Compare 13, I couldn't figure out how to select/specify the existing Filter.scpf.  Ended up using the command line sqlcompare.exe.
    • Would be good if there were SQL Compare Powershell cmdlets.
    • Once I had generated the scripts folder, I used the GUI to compare and found the extra files in repo.  I used SQL Compare to apply the "deletion" however it seemed to only remove the contents of the SQL file, not delete it (that may have been something to do with my options in SQL Compare).
    However those comments aside I managed to do what I required, so thanks!

    Cheers
    Peter
  • @Bugmeister - Great that you found a solution. You're right - Create Scripts Folder doesn't appear to allow a filter to be specified. Another way that you could have achieved this is to compare your database against a scripts folder target (the scripts folder in this case being just an empty database you create on disk). This way you can set the filter in the comparison window (click the filter button in the toolbar if the filter dialog isn't showing) and run a "Deploy..." from the database to the scripts folder. It's probably not as intuitive as it could be admittedly.

    Regarding the blanking of files rather than deleting them, I had forgotten about that. Sorry! I think this is because some version control systems don't like file deletions and will behave unexpectedly if the files disappear. I can't remember the precise details. I guess you would have had to delete the files manually? Anyway, good that it worked out in the end!

    David Atkinson
    Product Manager
    Redgate Software
  • BugmeisterBugmeister Posts: 21 New member
    Yeah where there was a will there was a way, and the toolset managed to get it done.  Even with it only the blanking of files they immediate showed as modified in Git so I had a list of what to delete.  Thanks again!
Sign In or Register to comment.