diff --git a/src/BaseMigration.php b/src/BaseMigration.php index b5df6c622..2969933aa 100644 --- a/src/BaseMigration.php +++ b/src/BaseMigration.php @@ -431,7 +431,7 @@ public function table(string $tableName, array $options = []): Table /** * Create a new ForeignKey object. * - * @params string|string[] $columns Columns + * @param string|string[] $columns Columns * @return \Migrations\Db\Table\ForeignKey */ public function foreignKey(string|array $columns): ForeignKey @@ -442,7 +442,7 @@ public function foreignKey(string|array $columns): ForeignKey /** * Create a new Index object. * - * @params string|string[] $columns Columns + * @param string|string[] $columns Columns * @return \Migrations\Db\Table\Index */ public function index(string|array $columns): Index diff --git a/src/Db/Adapter/PostgresAdapter.php b/src/Db/Adapter/PostgresAdapter.php index 8720b9c59..4df4e6e47 100644 --- a/src/Db/Adapter/PostgresAdapter.php +++ b/src/Db/Adapter/PostgresAdapter.php @@ -823,7 +823,11 @@ protected function getDropCheckConstraintInstructions(string $tableName, string public function createDatabase(string $name, array $options = []): void { $charset = $options['charset'] ?? 'utf8'; - $this->execute(sprintf("CREATE DATABASE %s WITH ENCODING = '%s'", $name, $charset)); + $this->execute(sprintf( + 'CREATE DATABASE %s WITH ENCODING = %s', + $this->quoteSchemaName($name), + $this->quoteString($charset), + )); } /** @@ -849,7 +853,7 @@ public function hasDatabase(string $name): bool public function dropDatabase($name): void { $this->disconnect(); - $this->execute(sprintf('DROP DATABASE IF EXISTS %s', $name)); + $this->execute(sprintf('DROP DATABASE IF EXISTS %s', $this->quoteSchemaName($name))); $this->createdTables = []; $this->connect(); } diff --git a/src/Db/Adapter/SqlserverAdapter.php b/src/Db/Adapter/SqlserverAdapter.php index 14602abc8..a6b91efcc 100644 --- a/src/Db/Adapter/SqlserverAdapter.php +++ b/src/Db/Adapter/SqlserverAdapter.php @@ -767,12 +767,17 @@ protected function getDropForeignKeyByColumnsInstructions(string $tableName, arr */ public function createDatabase(string $name, array $options = []): void { + $quotedName = $this->quoteSchemaName($name); if (isset($options['collation'])) { - $this->execute(sprintf('CREATE DATABASE [%s] COLLATE [%s]', $name, $options['collation'])); + $this->execute(sprintf( + 'CREATE DATABASE %s COLLATE %s', + $quotedName, + $this->quoteSchemaName($options['collation']), + )); } else { - $this->execute(sprintf('CREATE DATABASE [%s]', $name)); + $this->execute(sprintf('CREATE DATABASE %s', $quotedName)); } - $this->execute(sprintf('USE [%s]', $name)); + $this->execute(sprintf('USE %s', $quotedName)); } /** @@ -794,12 +799,16 @@ public function hasDatabase(string $name): bool */ public function dropDatabase(string $name): void { - $sql = <<quoteSchemaName($name); + $sql = sprintf( + 'USE master; +IF EXISTS(select * from sys.databases where name=%s) +ALTER DATABASE %s SET SINGLE_USER WITH ROLLBACK IMMEDIATE; +DROP DATABASE %s;', + $this->quoteString($name), + $quotedName, + $quotedName, + ); $this->execute($sql); $this->createdTables = []; } diff --git a/tests/test_app/config/AltSeeds/AnotherNumbersSeed.php b/tests/test_app/config/AltSeeds/AnotherNumbersSeed.php index f72c0a34d..efa478b60 100644 --- a/tests/test_app/config/AltSeeds/AnotherNumbersSeed.php +++ b/tests/test_app/config/AltSeeds/AnotherNumbersSeed.php @@ -3,7 +3,7 @@ use Migrations\BaseSeed; /** - * NumbersSeed seed. + * AnotherNumbersSeed seed. */ class AnotherNumbersSeed extends BaseSeed { diff --git a/tests/test_app/config/AltSeeds/NumbersAltSeed.php b/tests/test_app/config/AltSeeds/NumbersAltSeed.php index 4c9e3c6da..1455134eb 100644 --- a/tests/test_app/config/AltSeeds/NumbersAltSeed.php +++ b/tests/test_app/config/AltSeeds/NumbersAltSeed.php @@ -3,7 +3,7 @@ use Migrations\BaseSeed; /** - * NumbersSeed seed. + * NumbersAltSeed seed. */ class NumbersAltSeed extends BaseSeed { diff --git a/tests/test_app/config/BaseSeeds/MigrationSeedNumbers.php b/tests/test_app/config/BaseSeeds/MigrationSeedNumbers.php index d12df2697..5558fb593 100644 --- a/tests/test_app/config/BaseSeeds/MigrationSeedNumbers.php +++ b/tests/test_app/config/BaseSeeds/MigrationSeedNumbers.php @@ -3,7 +3,7 @@ use Migrations\BaseSeed; /** - * NumbersSeed seed. + * MigrationSeedNumbers seed. */ class MigrationSeedNumbers extends BaseSeed { diff --git a/tests/test_app/config/CallSeeds/DatabaseSeed.php b/tests/test_app/config/CallSeeds/DatabaseSeed.php index 90954c90d..e8e69f01d 100644 --- a/tests/test_app/config/CallSeeds/DatabaseSeed.php +++ b/tests/test_app/config/CallSeeds/DatabaseSeed.php @@ -3,7 +3,7 @@ use Migrations\BaseSeed; /** - * NumbersSeed seed. + * DatabaseSeed seed. */ class DatabaseSeed extends BaseSeed { diff --git a/tests/test_app/config/CallSeeds/LettersSeed.php b/tests/test_app/config/CallSeeds/LettersSeed.php index 300d6688c..a2591b6ff 100644 --- a/tests/test_app/config/CallSeeds/LettersSeed.php +++ b/tests/test_app/config/CallSeeds/LettersSeed.php @@ -3,7 +3,7 @@ use Migrations\BaseSeed; /** - * NumbersSeed seed. + * LettersSeed seed. */ class LettersSeed extends BaseSeed { diff --git a/tests/test_app/config/CallSeeds/NumbersCallSeed.php b/tests/test_app/config/CallSeeds/NumbersCallSeed.php index a6843abb3..24f56bde2 100644 --- a/tests/test_app/config/CallSeeds/NumbersCallSeed.php +++ b/tests/test_app/config/CallSeeds/NumbersCallSeed.php @@ -3,7 +3,7 @@ use Migrations\BaseSeed; /** - * NumbersSeed seed. + * NumbersCallSeed seed. */ class NumbersCallSeed extends BaseSeed { diff --git a/tests/test_app/config/Seeds/StoresSeed.php b/tests/test_app/config/Seeds/StoresSeed.php index 961bd42e1..e9ac51751 100644 --- a/tests/test_app/config/Seeds/StoresSeed.php +++ b/tests/test_app/config/Seeds/StoresSeed.php @@ -5,7 +5,7 @@ use Migrations\BaseSeed; /** - * NumbersSeed seed. + * StoresSeed seed. */ class StoresSeed extends BaseSeed {