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

postgres: Add setupSchemaScript option for Schema Setup #1633

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

i-am-logger
Copy link

@i-am-logger i-am-logger commented Dec 7, 2024

Path to a script that will set up or update the PostgreSQL database schema.

This script must be idempotent, meaning it can be run multiple times without causing unintended side effects. If you change your schema dynamically, ensure that this script handles such cases gracefully to maintain database integrity.

this is how i use it:

let
  db-name = "database";
in
{
  services.postgres.setupSchemaScript = ''
      ${builtins.readFile ./setup-local-postgres.sh} // create db and users (idempotent)
      cd infra/sqitch
      sqitch deploy --db-name ${db-name}
    '';
}

Path to a script that will set up or update the PostgreSQL database schema.

This script must be idempotent, meaning it can be run multiple times without causing unintended side effects. If you change your schema dynamically, ensure that this script handles such cases gracefully to maintain database integrity.
@domenkozar
Copy link
Member

This makes me think that initialScript should be named initialSchema and this should be initialScript.

@i-am-logger
Copy link
Author

This makes me think that initialScript should be named initialSchema and this should be initialScript.

I Agree.

I much rather have an idempotent script that runs every time Postgres starts in devenv than a script that runs one time... this is why I moved away from using InitialScript as its quite limited and can cause some headaches around updating the DB.

Maybe I should rename it from InitialSchema to UpdateScript ?

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

Successfully merging this pull request may close these issues.

2 participants