Skip to content

psql-remote command #2077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Guide/deployment.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ deploy-to-nixos ihp-app

This will connect to the server via SSH and apply the NixOS configuration to the server.

### Database connectivity

To easily access to the remote database for debugging purpose, you can use:
```bash
make psql-remote env=ihp-app
```

### Backward-incompatible database update

Expand All @@ -336,7 +342,6 @@ Steps to do to start from scratch:
- `exit`
- `rm /tmp/[your-app].sql`


## Deploying with Docker

Deploying IHP with docker is a good choice for a professional production setup.
Expand Down
5 changes: 5 additions & 0 deletions lib/IHP/Makefile.dist
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ postgres: ## Starts the postgresql server
psql: ## Connects to the running postgresql server
@psql -h $$PWD/build/db -d app

psql-remote: ## Connects to the postgresql server of a deployed instance.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should try to stick this into the nix configuration as a devenv script, similarly how deploy-to-nixos is also a devenv script: https://github.com/digitallyinduced/ihp/blob/master/flake-module.nix#L273

Then it could be called by running psql-remote ihp-app

Copy link
Collaborator

@amitaibu amitaibu Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the advantage of this way over make?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As that command depends directly on the nix configuration (by calling nix directly) it feels like it should belong there

@DB_URL=$$(nix eval .#nixosConfigurations.$$env.config.services.ihp.databaseUrl --raw); \
echo "Connecting to remote database on $$env"; \
ssh -t $$env "psql $$DB_URL"; \

db: Application/Schema.sql Application/Fixtures.sql ## Creates a new database with the current Schema and imports Fixtures.sql
(echo "drop schema public cascade; create schema public;" | psql -h $${PWD}/build/db -d app) && \
psql -v ON_ERROR_STOP=1 -h $${PWD}/build/db -d app < "$${IHP_LIB}/IHPSchema.sql" && \
Expand Down