YunoHost-Apps / flask_ynh

Flask template for YunoHost
6 stars 9 forks source link

Added choice between postgresql/sqlite3 database type at install #5

Closed a0kami closed 5 years ago

a0kami commented 6 years ago

Proposed the option to choose between postgresql (using driver psycopg2) and sqlite3 at install.

Feel free to review it when you'll have some time, and suggests better ways to implement and/or tests to add before merging. ;)

Among install and remove scripts supporting database type, this PR basically adds separate dependencies whether you choose postgresql or sqlite3, creates the database according to the option chosen (sqlite3 is in /var/www/app_name/app_name.sqlite3) and some sqlite3 very basic helpers.

alexAubin commented 6 years ago

That looks nice and clean, thanks !

If you tested that we can merge it right away imho

a0kami commented 6 years ago

Tested with both database types and from both ssh and admin panel.

I get some debconf warning installing from admin panel:

dpkg-preconfigure: unable to re-open stdin:
debconf: falling back to frontend: Teletype
debconf: (This frontend requires a controlling tty.)
debconf: unable to initialize frontend: Readline
debconf: falling back to frontend: Readline
debconf: (Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.)
debconf: unable to initialize frontend: Dialog

which seems to be coming from apt-get commands besides the use of "DEBIAN_FRONTEND=noninteractive" environment variable in the ynh helpers, so I don't get it (is it coming from the script or ynh pipeline ?)

Also I got a warning from installing psycopg2 driver for sqlalchemy:

Warning: /var/www/flask/venv/lib/python3.5/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
Warning:   """)

due to the name of the package being changed soon. (Both psycopg2 and psycopg2-binary packages will be available when 2.8 is released, which does seem better ?)

Although I saw the ynh_psql_test_if_first_run() postgresql test function in the _future.sh helpers and wanted to make something similar, I can't think of how to test (if even appropriate) sqlite3 setup (as it's basically just a file). And I don't quite know if the database setup is correct and works (can't see any tables with sqlite3 but there's a user table with postgresql belonging to flask user).

alexAubin commented 5 years ago

Didnt took the time to test all those but eh, let's yolomerge this :D Sorry for the delay