ownrecipes / OwnRecipes

Self Hosted Recipe Management App
https://ownrecipes.github.io/ownrecipes-web/
Other
10 stars 3 forks source link

Support of PostgreSQL #96

Open pleblancq opened 1 year ago

pleblancq commented 1 year ago

Hello, long time user of OpenEats, I migrated to OwnRecipes after changing my python version (3.9 to 3.11).

My setup is the following:

The migration was pretty easy actually since its baremetal, I didn't have to migrate my DB, I juste ran the migrations.

When I was using OpenEats, I modified the base/settings.py to have:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': os.environ.get('POSTGRESQL_DATABASE', 'database_name'),
        'USER': os.environ.get('POSTGRESQL_USER', 'database_user'),
        'PASSWORD': os.environ.get('POSTGRESQL_PASSWORD', 'database_password'),
        'HOST': os.environ.get('POSTGRESQL_HOST', '127.0.0.1'),
        'PORT': os.environ.get('POSTGRESQL_PORT', '5432'),
    }
}

and removed everthing associated to mysql and removed the mysql python package and replaced it with psycopg2 package. Since django supports natively PostgreSQL, it works out-of-the-box.

Its just a suggestion since your project seems active and it give the chance to people to use another DB. And I won't have to apply my hack at each release.

By the way, thank you for your fork, it keeps my wife happy and works with new tech.

sepulzera commented 1 year ago

Glad to hear that the migraton went smoothly! šŸ˜€

I am afraid that supporting another database is adding quite some overhead to the project. Sure, we could just document the required changes and hope for the best. But after all, it would not been being tested. And the database is actually the layer where things could become dicey, as there are all your data being stored.

Therefore, to support other databases officially, there should be a really strong need. What is your reason to not just stick with the mariadb?

Just providing different, perhaps db-name-independent environment variables would be another story. We could also introduce a variable for the engine. Though modifying the settings.py is kind of okay, if you know what you are doing. šŸ˜‰


And slightly off the topic: I could never get OpenEats up and running. Do you still have a copy? If so, would you mind to send me some screenshots about its sites, as sample/inspiration? šŸ˜‡

pleblancq commented 1 year ago

I prefer PostgreSQL for performance reasons and I already use it with a bunch of other projects.

Yeah, I still have it installed. You can take a look of the original author demo site

For the PostgreSQL issue, if you do pure SQL it should always work with django. With OpenEats, everything worked fine even if the original author only supported mysql/mariadb.

I can send you a recipe creation screenshot since you can see the others views in the demo site.

sepulzera commented 1 year ago

About the performance, I doubt that we will ever hit any bottleneck caused by the database. I am hosting over 700 recipes on a raspberry pi 3 and mariadb.

Well, we could add a dedicated docs site about how to switch the database to another one, with a chapter for postgres that is marked as experimental. That isn't something that I will spend time on. If you would like to help, then those information could be of interest for other future users.

Some quick thoughts about the docs:

  1. I couldn't find any other related mysql settings in the base/settings.py that need to be removed. The two mysql-specific settings are set conditionally.
  2. As you said, the requirements.txt needs to be changed, to exclude the mysqlclient and to include the psycopg2 package.
  3. Sample configuration files for docker should be provided. db needs to pull a postgres-image, volumes needs to be corrected and the healthcheck needs to be reimplemented.
  4. It needs to be elaborated if the postgres-docker-image requires some unique environment-variables, like mysql/mariadb do.
  5. If there is an easy way to provide a nice alias for the db environment variables, that will work with the base/settings.py and the docker images, then we should add that.
  6. No inline comments into the productive files should be added. People who want to switch the database, will find the required information. Adding a section to the Running-docs, like about Connecting to a remote db, would be fine.

In any case, even the information you wrote down into this issue is a nice source for other people that want to use postgresql. Thanks for your effort!


Thanks for the link!