Skip to content

Quote database names in PostgreSQL and SQL Server adapters#1002

Merged
markstory merged 2 commits into5.xfrom
fix/database-name-quoting
Jan 20, 2026
Merged

Quote database names in PostgreSQL and SQL Server adapters#1002
markstory merged 2 commits into5.xfrom
fix/database-name-quoting

Conversation

@dereuromark
Copy link
Member

@dereuromark dereuromark commented Jan 19, 2026

Summary

  • MySQL adapter properly quotes database names in createDatabase() and dropDatabase() using quoteTableName(), but PostgreSQL and SQL Server did not quote these identifiers consistently.

PostgreSQL fixes:

  • createDatabase(): Use quoteSchemaName() for database name and quoteString() for charset encoding
  • dropDatabase(): Use quoteSchemaName() for database name

SQL Server fixes:

  • createDatabase(): Use quoteSchemaName() for database name and collation instead of manual [brackets]
  • dropDatabase(): Replace heredoc with sprintf using quoteSchemaName() for identifiers and quoteString() for string comparisons

Docblock fixes:

  • Fix @params typo to @param in BaseMigration.php foreignKey() and index() methods
  • Fix copy-paste docblock errors in 7 test seed files where "NumbersSeed seed" was incorrectly used

This ensures consistent identifier quoting across all database adapters and fixes documentation errors.

Test plan

  • PHPStan passes
  • PHPCS passes
  • Existing tests pass

MySQL adapter properly quotes database names in createDatabase/dropDatabase
using quoteTableName(), but PostgreSQL and SQL Server did not.

- PostgreSQL: Use quoteSchemaName() for database name and quoteString() for charset
- SQL Server: Use quoteSchemaName() for database name and quoteString() for string comparisons

This ensures consistent identifier quoting across all database adapters.
- Fix @params typo to @param in BaseMigration.php foreignKey() and index() methods
- Fix copy-paste docblock errors in test seed files where "NumbersSeed seed" was
  used for classes with different names
@markstory markstory merged commit 49b3db5 into 5.x Jan 20, 2026
14 checks passed
@markstory markstory deleted the fix/database-name-quoting branch January 20, 2026 03:27
dereuromark added a commit that referenced this pull request Jan 20, 2026
This backports several important bug fixes from recent 5.x PRs:

**From PR #1001 (Fix release readiness issues for 5.x):**

- Fix copy-paste bug in Migrator::shouldDropTables() using $messages['down']
  instead of $messages['missing']
- Fix uninitialized $command property in Migrations.php
- Fix weak equality in Table::saveData() (use !== instead of !=)
- Replace assert() with explicit RuntimeException in BaseSeed for
  production safety
- Fix DumpCommand using non-existent $io->error() method (should be $io->err())
- Replace unsafe addslashes() with proper driver escaping (schemaValue())
  for column comments in MysqlAdapter::getRenameColumnInstructions()

**From PR #1002 (Quote database names in PostgreSQL and SQL Server adapters):**

- PostgresAdapter: Quote database name and charset in createDatabase()
- PostgresAdapter: Quote database name in dropDatabase()
- SqlserverAdapter: Use quoteSchemaName() instead of manual brackets in
  createDatabase() and dropDatabase()
- SqlserverAdapter: Fix SQL injection vulnerability in dropDatabase()

**From PR #1003 (Improve SQL quoting and fix docblock issues):**

- SqlserverAdapter: Use quoteString() for sp_rename parameters in
  getRenameTableInstructions() and getRenameColumnInstructions()
- PostgresAdapter/SqlserverAdapter: Use quoteColumnName() for foreign key
  column definitions instead of hard-coded double quotes
markstory pushed a commit that referenced this pull request Jan 21, 2026
This backports several important bug fixes from recent 5.x PRs:

**From PR #1001 (Fix release readiness issues for 5.x):**

- Fix copy-paste bug in Migrator::shouldDropTables() using $messages['down']
  instead of $messages['missing']
- Fix uninitialized $command property in Migrations.php
- Fix weak equality in Table::saveData() (use !== instead of !=)
- Replace assert() with explicit RuntimeException in BaseSeed for
  production safety
- Fix DumpCommand using non-existent $io->error() method (should be $io->err())
- Replace unsafe addslashes() with proper driver escaping (schemaValue())
  for column comments in MysqlAdapter::getRenameColumnInstructions()

**From PR #1002 (Quote database names in PostgreSQL and SQL Server adapters):**

- PostgresAdapter: Quote database name and charset in createDatabase()
- PostgresAdapter: Quote database name in dropDatabase()
- SqlserverAdapter: Use quoteSchemaName() instead of manual brackets in
  createDatabase() and dropDatabase()
- SqlserverAdapter: Fix SQL injection vulnerability in dropDatabase()

**From PR #1003 (Improve SQL quoting and fix docblock issues):**

- SqlserverAdapter: Use quoteString() for sp_rename parameters in
  getRenameTableInstructions() and getRenameColumnInstructions()
- PostgresAdapter/SqlserverAdapter: Use quoteColumnName() for foreign key
  column definitions instead of hard-coded double quotes
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