ioBroker / ioBroker.sql

Store history data in SQL Database: MySQL, PostgreSQL or SQLite
MIT License
44 stars 26 forks source link

[postgreSQL] Do not connect to postgres DB when no new DB has to be created (use existing DB) #404

Open GWarsow opened 9 hours ago

GWarsow commented 9 hours ago

Describe the bug
I want to access a cloud-based postgreSQL DB with this adapter. There, I do not have access to the postgres DB, only to my dedicated DB. So it should be sufficient to tick Datenbank nicht erstellen (bereits erstellt) because then no DB would have to be registered in the postgres DB.

To Reproduce
Steps to reproduce the behavior:

  1. Go to /#tab-instances/config/system.adapter.sql.0
  2. Choose PostegreSQL as DB type
  3. Enter valid credentials/parameters
  4. Make sure to select Datenbank nicht erstellen (bereits erstellt)
  5. Click on "Verbindung testen"
  6. See error: error: permission denied for database "postgres"

Expected behavior
A connectin to the DB should be established, even when the DB user does not have permission to access DB postgres if adapter.config.doNotCreateDatabase is true. Currently, connection to postres is attempted altough this is not needed:

                if (adapter.config.doNotCreateDatabase) {
                    _client.disconnect();
                    postgresDbCreated = true;

Versions:

GWarsow commented 9 hours ago

The check https://github.com/ioBroker/ioBroker.sql/blob/0ce044a69ef091d367036a4dcb972febccecff3f/main.js#L526-L528 could be done prior to https://github.com/ioBroker/ioBroker.sql/blob/0ce044a69ef091d367036a4dcb972febccecff3f/main.js#L511