Guide on Connecting IntelliJ to Postgres #1416
Mythicaeda
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It is often useful to be able to view the contents of the database when debugging or writing new DB code. Having a connection to the database in IntelliJ is a convenient alternative to the Hasura console, especially for untracked tables or for DB Tests.
How to Connect
Expand the
Database
tab in the right upper-sidebar. From there, click the+
button ->Data Source
->PostgreSQL
.Set up the connection information. By default, it will correctly set the
Host
andPort
fields tolocalhost
and5432
respectively. You will need to provide theUser
andPassword
fields. While this can be any user in the database, I recommend setting them to yourAERIE_USER
andAERIE_PASSWORD
variables. Set theDatabase
field toaerie
. Additionally, while you can proceed with the defaultName
, I recommend changing it to something meaningful for you. For instance, I have multiple configurations for when I have to connect as a different database user (ie, as the merlin service), so I prefer to include that in the name of the configuration.OK
you should test your configuration with theTest Connection
button on the bottom left. If you see the promptDownload missing driver files
, do so before hittingTest Connection
. Below is an example of what that prompt looks like. If you forget, the prompt will appear when you right click on the Connection in the Database tab.1 of 3
from besides the connection's name, then expand the entryaerie
(ifaerie
is not selected, select it now). If you know which schemas are relevant to you, select them, otherwise checkSelect All
.PostgresSQL
.Useful Tips:
Refreshing the Database
If the database structure changes between connections (ie, you compose up a new version of Aerie that's at a higher migration), you will need to "introspect" the database for it to find the changes. Introspection can be done by selecting the
aerie
database and either pressing CMD+R or clicking therefresh
button in the top bar of the Database tab. If you're ever not seeing tables or columns that you know should be there, you probably need to refresh.Attaching a Session to a File
Once you have a made a connection to the database, whenever you have code blocks tagged as SQL statements (ie by using the
@Language("SQL")
annotation) or are working in a.sql
file, you can attach a DB session to the file. This is extremely useful for creating and debugging SQL code.This is done by right-clicking on the code block and pressing
Attach Session
. From there you can choose to reuse an existing session or make a new one.The Query Console
The query console is a good tool when you want to run a quick SQL statement. To open the query console, select the icon of a window with
QL
in it, then pressOpen Default Console
. The query console can also be found by searchingconsole
in theSearch Everywhere
window. Query consoles are excluded fromgit
, so the contents will persist between branches.Viewing and Changing a Table
It is possible to view and alter the contents of tables (add, update, delete). If you know what the table is called and the schema it is in, the quickest way to pull this up is to run
select * from <SCHEMA>.<TABLE>
. Otherwise, you can use the explorer in the Database tab to drill down to the table and double-click it.Executing Part of a SQL File
When working with a SQL File with multiple statements, you can choose to only run part of it. If you put your cursor in the statement you want to run, then press the execute button (Green Play button in the top left or CMD+Enter) will prompt you to pick how much you want to execute: the specific statement or the entire file. If you highlight some SQL code and press the execute button, this prompt will be skipped and exactly what you have highlighted will be executed. This means if you have only part of a statement highlighted, only that part of the statement will be run.
Cleaning up after Canceling E2E Tests
If you accidentally cancel an e2e-test, you can generally clean up your database by executing the following two statements:
This will remove ALL mission models and plans from the database, as well as any data that was connected to them (ie activity directives, simulations). Note that for certain tests you may need to
truncate
additional tables.Debugging DB Tests
If you need to review the contents of the database during a DB Test, you can do the following:
1 of X
text to the right of the Configuration name and select the temporary database (Note, this text may instead state the number of connections instead of1 of X
). Additionally, expand it and select its schemas. You can now inspect this database the way you would theaerie
database.Beta Was this translation helpful? Give feedback.
All reactions