Skip to content
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

Automate the creation of a server #714

Open
orf opened this issue Apr 19, 2023 · 3 comments
Open

Automate the creation of a server #714

orf opened this issue Apr 19, 2023 · 3 comments

Comments

@orf
Copy link

orf commented Apr 19, 2023

Hello,
I'm wondering if there is a way to automate the creation of a Postgres.app managed database server? It would be very handy when setting up new developer machines to be able to also create a Postgres.app server for them. Right now you can obviously run initdb via a shell script, but it's not possible to fully automate the "create a new server" action and have the server appear in the sidebar.

@jakob
Copy link
Member

jakob commented Apr 19, 2023

The servers are stored in the user defaults, so you can just use the defaults write com.postgresapp.Postgres2 .... command to programmatically add it to the sidebar.

There's no official docs, but it should be pretty self-explanatory. If it's unclear, feel free to post follow up questions.

The Postgres.app GUI reads the user defaults on launch, so make sure to quit the app before making changes.

@orf
Copy link
Author

orf commented Apr 19, 2023

Yeah I saw this, but you may wish for the server to be running before you take a next step. If you're bootstrapping a machine or project with some dependencies from homebrew(such as this one), the next steps may require a Postgres.app server to be running and available. It's minor, but it's a bit annoying to block that and say "now go to this UI and press a few buttons".

If you're not against it then I could take a stab at adding an additional AppleScript interface to do this, perhaps? I've got the start of a branch here that adds a create server command with a paramater and inits/starts the server.

@jakob
Copy link
Member

jakob commented Apr 19, 2023

You can already start/stop servers without using the GUI -- all the GUI does is call pg_ctl.

But adding AppleScript actions does sound useful! I just did a cursory glance at you branch -- the first thing that jumped out were the try! statements. I assume those are just for testing, but they should be replaced by proper error handling (the error should be reported back to Apple Script).

One caveat with Apple Script is that macOS recently started showing permission dialogs when you try automating an app for the first time, and I haven't found a way around that yet. (But I haven't looked into it yet in detail)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants