1

I am trying to automate the build/deploy process for our application through Teamcity. One of the steps I need to do through Teamcity is to run the .sql files on the databases. I am able to implement this step, however it runs all of the scripts each time which is very time consuming. I was wondering if there was a way to only run the updated/added .sql files (after running svn-update), or to only run the .sql files that were modified by a certain date, or something to that effect. The script I have now simply runs all sql files in the current directory (including subfolders).

for /R %%G in (*.sql) do sqlcmd /S server /U user /P password /d database -i"%%G"

So is there a way i could possibly tweak this, something like

for /R %%G in (*.sql) where date_modified > "1_28_2016" do sqlcmd /S server /U user /P password /d database -i"%%G"

Or am I way off track here? ANY feedback will help! Thanks!

NOTE: I believe a similar if not same question was asked on here before with almost no feedback that did not seem to work. I am posting again in hopes of finding an answer/reviving the question.

  • 2
    I would recommend you to use a tool like Flyway db or Liquibase. They keep track of what scripts were run on the database. This way you don't need to reinvent the wheel. – Akira Yamamoto Jan 28 '16 at 21:20
  • Awesome thank you! This sounds like exactly what I need! Will do some research on this. – K. Buchanan Jan 28 '16 at 21:42
  • You can limit by date in Powershell. This -can- be done in a cmd .bat script, but it is painful. http://stackoverflow.com/questions/15884173/limiting-powershell-get-childitem-by-file-creation-date-range – lit Jan 29 '16 at 17:50
  • As appealing as that sounds, it seems like Flywaydb or Liquibase would be better overall for the long run. But I definitely appreciate the response! – K. Buchanan Jan 29 '16 at 18:46

0 Answers0