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

Improve services.postgres db init #1408

Merged
merged 4 commits into from
Sep 11, 2024

Conversation

ppenguin
Copy link
Contributor

@ppenguin ppenguin commented Sep 1, 2024

Add user/pass capability to services.postgres.initialDatabases because we usually like to test our services with specific DB users. The options are optional, functionality remains the same if not given.

If we now do this:

  services.postgres = {
    enable = true;
    listen_addresses = "localhost";
    port = 15432;
    initialDatabases = [
      {
        name = "pdns";
        user = "pdns";
        pass = "mypdnssecretpass1234";
        schema = ./_testdata; # *.sql in version order
      }
    ];
  };

the following will happen:

  1. postgres DB is created as usual, owned by $USER (who is SUPERUSER) for this instance)
  2. A role pdns with password ${pass} is created
  3. Database ${name} is created
  4. All privileges on pdns are granted to user pdns.
  5. The schema seeding scripts in ${schema} are executed as user pdns.

@domenkozar
Copy link
Member

Since postgresql is critical bit of the infra, can you add a test for it to tests/?

@ppenguin
Copy link
Contributor Author

ppenguin commented Sep 6, 2024

Since postgresql is critical bit of the infra, can you add a test for it to tests/?

Done (finally) ✌️

@domenkozar domenkozar merged commit 7535c11 into cachix:main Sep 11, 2024
22 of 23 checks passed
@ppenguin ppenguin deleted the improve-services.postgres-db-init branch September 11, 2024 14:17
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