Skip to content

[11.x] feat: Create missing pgsql database when running migrations#54314

Merged
taylorotwell merged 7 commits into
11.xfrom
feat-create-missing-pgsql-database
Jan 27, 2025
Merged

[11.x] feat: Create missing pgsql database when running migrations#54314
taylorotwell merged 7 commits into
11.xfrom
feat-create-missing-pgsql-database

Conversation

@mathiasgrimm
Copy link
Copy Markdown
Member

@mathiasgrimm mathiasgrimm commented Jan 23, 2025

This PR is the MySQL counterpart to #44153
Create missing pgsql database like we do for MySQL(and SQLite) when running migrations

When creating a fresh Laravel install, it will fail
image

|| (
($e->getPrevious()->errorInfo[0] ?? null) == '08006'
&& $connection->getDriverName() == 'pgsql'
&& Str::contains($e->getPrevious()->getMessage(), '"'.$connection->getDatabaseName().'"')
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pgsql has no specific code for missing database. https://www.postgresql.org/docs/current/errcodes-appendix.html

image

If we don't check for a string such as the database name which is part of the error, a wrong username or password would also offer the user the option to create a database.

@taylorotwell taylorotwell merged commit 96302bf into 11.x Jan 27, 2025
@taylorotwell taylorotwell deleted the feat-create-missing-pgsql-database branch January 27, 2025 22:22
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

Successfully merging this pull request may close these issues.

2 participants