bstarynk / helpcovid

a C++ free software web application (GPLv3+, Linux) to organize people helping other neighbours in Covid pandemics
GNU General Public License v3.0
2 stars 2 forks source link

program option --clear-database does not work #27

Closed bstarynk closed 4 years ago

bstarynk commented 4 years ago

In commit a22fbc4c64 the --clear-database does not work as it should. It is expected to clear entirely the database but does not. PostgreSQL 12.2 on Debian Buster

bstarynk commented 4 years ago

Notice that we are unable, in commit 2843184d9f589d51bd9bc3eae, to use DROP DATABASE programmatically

bstarynk commented 4 years ago

database-diff-2843184d9f589d51bd.txt is a git diff w.r.t. commit 2843184d9f589d51bd which does not work.

achakravarti commented 4 years ago

@bstarynk's suggestion to DROP OWNED BY CURRENT_USER CASCADE; seems to work:

abhishek@archlinux ~]$ psql -U helpcovid_usr -d helpcovid_db psql (12.2) Type "help" for help.

helpcovid_db=> select * from tb_user helpcovid_db-> ; user_id | user_firstname | user_familyname | user_email | user_gender | user_crtime ---------+----------------+-----------------+------------+-------------+------------- (0 rows)

helpcovid_db=> drop owned by current_user cascade; WARNING: no privileges could be revoked for "helpcovid_db" DROP OWNED helpcovid_db=> select * from tb_user ; ERROR: relation "tb_user" does not exist

montao commented 4 years ago

@bstarynk's suggestion to DROP OWNED BY CURRENT_USER CASCADE; seems to work:

abhishek@archlinux ~]$ psql -U helpcovid_usr -d helpcovid_db psql (12.2) Type "help" for help. helpcovid_db=> select from tb_user helpcovid_db-> ; user_id | user_firstname | user_familyname | user_email | user_gender | user_crtime ---------+----------------+-----------------+------------+-------------+------------- (0 rows) helpcovid_db=> drop owned by current_user cascade; WARNING: no privileges could be revoked for "helpcovid_db" DROP OWNED helpcovid_db=> select from tb_user ; ERROR: relation "tb_user" does not exist

Great, but will it be safe if CURRENT_USER happens to own several databases or will that not happen? An alternative could be to connect to another database e.g. the rdbms postgres database and drop the app database from there or create a temporary new dummy database named _tmp, connect to the new dummy database and from there drop the app database (once we got the name of the app database in a variable)? Or are we happy with it already?