MSSQL: Ctrl+Click on a sql view column referenced in stored procedure jumps to source code of object in database instead of file on disk
Hi,
This used to work before.
I keep the sql stored procedures source code in sql files on disk. They are the source of truth for the sql objects code, not the objects in the various databases.
Before, if I clicked on a column of a view referenced in a stored procedure edited as a sql file, DG used to take me to the sql file containing the source code of the view on disk, not to the source code of the sql object found in the database.
How far was that in the past? I don't know. I don't use DG all the time, but I recall I was very happy because DG opened the file instead of database objects. Right now, it is very annoying because in Database Explore I have 3 servers, each from a different environment. Please note that I added the folders containing the sql objects source files in the Files window via Attach Directory to Project.
Did you guys make any changes recently? Is there an option where I can force DG to look on disk instead of the database?
Thank you
DataGrip 2023.2.1
Build #DB-232.9559.28, built on August 16, 2023
Runtime version: 17.0.8+7-b1000.8 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows Server 2016 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 2560M
Cores: 6
Registry:
documentation.show.toolbar=true
ide.experimental.ui=true
ide.balloon.shadow.size=0
Non-Bundled Plugins:
bundled-datagrip-help (232.9559.28)
Please sign in to leave a comment.
As far as I understand, you have the same stored procedure object stored in a file attached to your DataGrip Project and the same object is also located in your source database within a schema. You were expected to modify the stored procedure DDL in a file, not in your schema. If so, can you please clarify how you opened the file in DataGrip? Important to note that the object editor of DataGrip (an editor instance generated when you click on Go to DDL in the Database Explorer) works with the database directly, preserving a temporary local copy (our internal versioning, so to speak).
Please let us know the exact steps you taken so we can assist you with your concern.
Hi,
Yes, I edit a sql file that contains the create or alter procedure statement the updates a stored procedure. The file was opened by pressing Ctrl + Shift + N, then I typed the name of the file, it appeared in the list and I selected it.
The stored procedure code references sql views. When I Ctrl+Click on a view name, DG takes me to the database sql object source code (i.e. the source code pulled from the db dictionary data - I use sql server 2017) instead of the sql file that contains the create or alter view statement. As far as I recall, it didn't used to do this. Before, it used to open the file containing the source code of the view.
One other thing to mention is that, when I press Ctrl + Shift + N, the scope set is “Attached Directories” not “Project Files”.
So, is there a way to tell DG to open the sql script containing the sql that creates an object when Ctrl+clicking on the name of that object in the sql editor?
Thanks
To my knowledge, it has always been this way. If you have all your object definitions written in a SQL file or separate SQL files, like in the case of your procedure and view, there's no declaration or, in other words, a link pointing to that object in a SQL file. So when you hold Ctrl and click on a view of your procedure in an SQL file, it'll open an instance of the object editor directly making changes to your data source.
Do you recall if that was precisely an instance of SQL file opened when navigating through the declaration, not an instance of the object editor with the definition?
Unfortunately, no!😬 I don't use DG every day and I rely on the fact that this would have bothered me greatly before… It was my impression that somehow DG keeps track of the source code and knows where things are, i.e. file X contains the create or alter statement for a database object so if the user wants to navigate to that object the tool opens the code from that file, especially if the scope selected in the go to *** dialog is set to attached directories.
Thanks
I would like to make a request to have the ability to jump to a sql file when pressing Ctrl+Click (or at least presented the option) implemented in DG. I think it is totally doable. Where do I do it?
Thanks
https://www.jetbrains.com/help/datagrip/ddl-data-sources.html
You can map your data source locally, where all of your data will be kept in SQL files. From there, you can edit your local files and synch with the originating data source if needed.
Thank you for the suggestion, I was able to create a ddl source mapped to a folder, however, again, when I ctrl+click on an object within a sql script code editor, it still jumps to the database object. I also defined the mapping using “Mapping: Source Code Mapping”.
I don't know what else to do. If you have other suggestions, please let me know.
Thanks
Honestly, I feel like giving up - it should be simple. Maybe it's just me. DG always jumps to an object in the database. What is weird is that it seems to keep a local copy of the database object, which I can modify but not run in the database, this after doing all the mapping with the DDL source.
The bottom line is this in my context:
- my source of truth for a sql server coding object (stored proc, function, etc) is in a local file, it's not the text of the sql object in the database
- if I edit a sql file and I ctrl+click on an object, I want it to jump to another local file containing that object.
Given this information, how do I convey it to DG?
As per your suggestion:
- I defined a DDL source which I pointed it to the root folder where all my sql scripts are
- I mapped this DDL source to the development database server data source (ms sql server)
If I open a sql file and try to navigate to an object (go to → Implementations, go to → declarations or usages), it keeps jumping to the sql object in the development database server.
One other thing, when I open the sql script I change its “session” to the develpment database server. The “session” concept is another can of worms!
Let me know if you have other suggestions, otherwise I am giving up.
Thanks for your help to get me this far.
I think there might be a misunderstanding in the mapped DDL concept. The SQL files you have attached to your project directory won't be copied when you map a DDL ie creating a local copy of your data source. When you create a Mapped DDL by dumping it from the data source, it replicates your structure and put them into separate SQL files linked to each, so to say
Once it's created, you need to open the objects, including your procedures, directly from this mapped DLL - not from your originating data source aka source of truth. In doing so, it'll open only local SQL files and the same is true for other objects mentioned in stored procedures - they will be opened in separate local SQL files.
Please read the following guides; they might be helpful:
https://www.jetbrains.com/help/datagrip/creating-and-editing-sql-files.html#define_data
https://www.jetbrains.com/help/datagrip/ddl-mappings.html#settings_of_ddl_mapping_tab