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

SqlPgsql::dbExists checking exit code is not enough #5643

Closed
Sweetchuck opened this issue Jun 9, 2023 · 0 comments
Closed

SqlPgsql::dbExists checking exit code is not enough #5643

Sweetchuck opened this issue Jun 9, 2023 · 0 comments

Comments

@Sweetchuck
Copy link
Contributor

Sweetchuck commented Jun 9, 2023

Problem

\Drush\Sql\SqlPgsql::dbExists()
Always returns TRUE with PostgreSQL-15.

Exit code of the command psql --no-psqlrc -t -c "SELECT 1 AS result FROM pg_database WHERE datname='foo'" shows that the query ran successfully.
It doesn't care about the number of records.

When the database IS exists, then the stdOutput is 1\n\n
When the database IS NOT exists, then the stdOutput is \n. It is not an empty string, so it is converted to TRUE.

Suggested solution

return $process->isSuccessful()
    && trim($process->getOutput()) === '1';

Originally posted by @Sweetchuck in #5545 (comment)

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

No branches or pull requests

1 participant