With DataGrip, I know there's a way to generate SQL scripts based on the database schema (Right click on the table > SQL Scripts
> SQL Generator
). However, is there a way to get DataGrip to automatically update these generated SQL scripts whenever the schema changes via queries (DDL) or the UI (Modify Table
option)?
Right now, if I want my SQL script files to be under version control and if I want these files to reflect the latest state/schema of my database, I have to:
- Manually modify the file(s).
- Copy the contents of the file (query) and paste it onto a console in DataGrip.
- Run the query from the console in order to update the database schema.
- If step 3 succeeds, commit the changes in my file to my local GIT repository. If step 3 fails, start over from step 1.
Instead, I want to:
- Make a schema change directly on DataGrip via a query or
New > Create Table
option orRight click on the table > Modify Table
option. - (If step 1 succeeds) Be shown a change set on DataGrip itself, and upon clicking something like
Save
/Commit
, modify the corresponding SQL scripts in my local repository and create a new commit. This will then trigger my CI/CD pipeline to build, test and deploy my changed schema.
P.S: This is similar to what Red-Gate's SQL Source Control
can do in SQL Server Management Studio. Unfortunately, they don't have a plugin for DataGrip.
Now DataGrip cannot automatically update SQL files according to schema changing. We have the idea to implement this in the future. I think the best ticket to upvote will be: https://youtrack.jetbrains.com/issue/DBE-3852
Anyway, your current algorithm seems to be not the most effective. What I would offer: