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

feat: PostgresProvider - Add POSTGRES_URL_OVERRIDE #3395

Merged
merged 19 commits into from
Apr 4, 2024

Conversation

tba-code
Copy link
Contributor

@tba-code tba-code commented Mar 30, 2024

What type of PR is this?

  • bug
  • cleanup
  • documentation
  • feature

What this PR does / why we need it:

  • Added POSTGRES_URL to PostgresProvider as an override for the individual POSTGRES_* variables currently in use.
  • PostgresProvider.db_url no longer rebuilds the db url on every call.
  • Updated the documentation to reflect the new variable and it's usage.
  • The override can be used to specify a UNIX socket for postgres.

Which issue(s) this PR fixes:

Fixes #3392

Testing

1). Installed postgres locally into a mealie devcontainer.
2). Created a database for mealie
3). Tested multiple values of POSTGRES_URL (omitted, specified using default config, specified using file socket). using task dev:services and task py:postgres for more complete testing.

@tba-code tba-code changed the title feat: PostgresProvider - Add POSTGRES_URL override feat: PostgresProvider - Add POSTGRES_URL_OVERRIDE Mar 31, 2024
hay-kot
hay-kot previously approved these changes Apr 1, 2024
Copy link
Collaborator

@hay-kot hay-kot left a comment

Choose a reason for hiding this comment

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

LGTM, will defer to @boc-the-git for merge

@@ -33,6 +33,7 @@
| POSTGRES_SERVER | postgres | Postgres database server address |
| POSTGRES_PORT | 5432 | Postgres database port |
| POSTGRES_DB | mealie | Postgres database name |
| POSTGRES_URL_OVERRIDE | None | Postgres URL override. Must be used with DB_ENGINE: postgres |
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like the wording "Must" here - it implies it's mandatory when in fact it's optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not optional if using the variable. You must define that or it will not work because the provider is created based on DB_ENGINE.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea, I understand the message you're trying to communicate, but I don't agree that the words achieve that. Otherwise that same message should be on all the POSTGRES_x env vars?

Something that talks to what it replaces would make more sense, e.g. (don't quote me, I've given this very little thought!!) "Postgres URL override. Used in place of POSTGRES_x/POSTGRES_y/... if you want to specify the full connection URI"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what I came up with: "Optional Postgres URL override to use instead of POSTGRES_* variables. Must be used in conjunction with DB_ENGINE: postgres to have an effect."

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's absolutely an improvement, I just still find this a weird addition Must be used in conjunction with DB_ENGINE: postgres to have an effect., per previous comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd be nervous to not add something similar as this is a quirk of the implementation.

The URL includes the dialect already, so its quite weird to have it specific to postgres if I am honest here.
If you don't specify it must still be used in conjunction with DB_ENGINE: postgres, someone may think that specifying DB_ENGINE is redundant, and remove it, only to find the instance has gone back to sqlite.

Copy link
Collaborator

@boc-the-git boc-the-git Apr 3, 2024

Choose a reason for hiding this comment

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

Pretend this new variable doesn't exist..
If a user does not specify DB_ENGINE: postgres, they get a sqlite DB already, right?
It looks that way to me, based on https://github.com/mealie-recipes/mealie/blob/mealie-next/mealie/core/settings/settings.py#L215

I'm all for the docs being improved, but adding this exact message, to this one environment variable, adds more confusion rather than simplifying things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

Copy link
Collaborator

@boc-the-git boc-the-git left a comment

Choose a reason for hiding this comment

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

One doco change needed, but otherwise happy for this to be merged - even ahead of the security release if that's how the timing works out. I don't see this as being a risky change given it's a new env var being introduced.

Oh, and I'm crowd sourcing an opinion to the change of how timezone is set in the sample files.. that's on Discord.

Copy link
Collaborator

@boc-the-git boc-the-git left a comment

Choose a reason for hiding this comment

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

👍

@boc-the-git boc-the-git merged commit bae7acb into mealie-recipes:mealie-next Apr 4, 2024
10 checks passed
@tba-code tba-code deleted the postgres-url-feature branch April 4, 2024 02:19
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.

[BUG] - Failure to connect to Postgres over a unix socket
3 participants