Datagrip Version Controlling Live Templates

Background:

I really enjoy using live templates in my daily workflow. I have a bunch of templates created for myself that I manage locally through the Datagrip UI. I also have Datagrip set up with git, so I have a templates project where I'll make edits to these templates and control changes over time. 

Problem:

Every time I make a change to a template in my project, I then have to copy the changed template back into the live template editor in the UI. This is redundant even for one person, but makes sharing templates across multiple people not possible. 

If I were to make an update to a live template and push it to git, I would then have to let everyone know I made a change to said template and they would then have to go and manually update their templates. 

Ideal State:

I'd like to be able to make a change in the live template editor and be able to directly commit that change to git. 

Make change to Datagrip Live Template in UI → This updates the xml file in my local configuration directory [~/Library/Application Support/JetBrains/DataGrip2024.1/templates/user.xml] → This xml file is tracked by git → I push the changes → Others can pull changes updating their xml file → Changes reflected in Live Templates 

What I've tried:

Altering the path to user.xml causes live templates to disappear in the UI, the application is obviously looking for the file in the templates directory associated with the specific version of git. If I were to initialize a git repo  at ~/Library/Application Support/JetBrains/DataGrip2024.1/templates/ … I believe I would just lose all my templates when upgrading to say DataGrip2024.3 which would alter the path and I'd need to re-init git. 

So I did some digging and it seems like you can alter the location of ide directories. I could do this but I don't really want to copy all the configurations under ~/Library/Application Support/JetBrains/DataGrip2024.1/ and version them… I'd like to just change the path to or initialize git directly at the templates directory. Also if I'm sharing this with others I guess they would also need to alter this in their configuration as well which I'd rather not burden them with. 

 

Questions:

Is there an easy solution here that I'm missing? 

Is this a planned feature moving forward to expand live template functionality in the editor?

Is the best solution to move my configuration directory and init git at that new location?

 

Anyway, I hope I've conveyed my desired end state correctly. It'd be great if I could just integrate live templates in a version controlled environment to be able to embed common statements in my teams workflow. 

Happy to elaborate on anything if its unclear and apologies if I have any misconceptions on how the editor is working in current state. 

Thank you!

 

 

 

 

3
Hi,

Thank you for the detailed description of your use case with live templates.

Have you considered looking at the backup and synch plugin?

https://www.jetbrains.com/help/datagrip/sharing-your-ide-settings.html

It stores the live templates in Code settings and allows you to replicate them onto other Jetrains IDE clients. This could potentially cover your current use case.
0

I went ahead and built out the functionality. Copied my configuration files into a new directory and initialized git. I adjusted idea.properties configuration to point to the new path. 

I threw all the other directories into .gitignore and created a new directory for my SQL templates. Datagrip still uses the templates/ directory for the xml that denotes each live template under a specific group. So I wrote a quick parser which looks for .sql files in my new directory and converts them into the proper .xml format Datagrip expects. This relies on a comment at the top of each file that I can use as the abbreviation for the mapping. I think I can reduce the manual need to run this by creating a hook that does this at the time of the commit, but I haven't done that yet (Weekend project).

So essentially my team will author SQL and then that SQL will get converted into xml in the correct directory that datagrip uses for live templates. When committing changes and performing reviews they will commit the SQL (Easy to read and view what is new) and that will get converted to the necessary xml.

You can also create a project at the new configuration directory and use all the nice features in the project UI to make changes. 

This process has its quirks… since I'm just altering the functionality of live templates.  

  • If you were to upgrade your datagrip version I'm sure you'd need to re-point the configuration to the new directory. 
  • If you pull changes from someone else you have to restart datagrip for them to take effect
  • The setup requires some documentation on my part to make sure everyone knows what to do, this wont just work out of the box with the application unfortunately 

Anyway, maybe this will be a feature in future or someone else will find this useful and it'll save them some time.

 

 

 

1

请先登录再写评论。