Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/BaseMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
));
}

/**
Expand All @@ -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();
}
Expand Down
27 changes: 18 additions & 9 deletions src/Db/Adapter/SqlserverAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand All @@ -794,12 +799,16 @@ public function hasDatabase(string $name): bool
*/
public function dropDatabase(string $name): void
{
$sql = <<<SQL
USE master;
IF EXISTS(select * from sys.databases where name=N'$name')
ALTER DATABASE [$name] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP DATABASE [$name];
SQL;
$quotedName = $this->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 = [];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_app/config/AltSeeds/AnotherNumbersSeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Migrations\BaseSeed;

/**
* NumbersSeed seed.
* AnotherNumbersSeed seed.
*/
class AnotherNumbersSeed extends BaseSeed
{
Expand Down
2 changes: 1 addition & 1 deletion tests/test_app/config/AltSeeds/NumbersAltSeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Migrations\BaseSeed;

/**
* NumbersSeed seed.
* NumbersAltSeed seed.
*/
class NumbersAltSeed extends BaseSeed
{
Expand Down
2 changes: 1 addition & 1 deletion tests/test_app/config/BaseSeeds/MigrationSeedNumbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Migrations\BaseSeed;

/**
* NumbersSeed seed.
* MigrationSeedNumbers seed.
*/
class MigrationSeedNumbers extends BaseSeed
{
Expand Down
2 changes: 1 addition & 1 deletion tests/test_app/config/CallSeeds/DatabaseSeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Migrations\BaseSeed;

/**
* NumbersSeed seed.
* DatabaseSeed seed.
*/
class DatabaseSeed extends BaseSeed
{
Expand Down
2 changes: 1 addition & 1 deletion tests/test_app/config/CallSeeds/LettersSeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Migrations\BaseSeed;

/**
* NumbersSeed seed.
* LettersSeed seed.
*/
class LettersSeed extends BaseSeed
{
Expand Down
2 changes: 1 addition & 1 deletion tests/test_app/config/CallSeeds/NumbersCallSeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Migrations\BaseSeed;

/**
* NumbersSeed seed.
* NumbersCallSeed seed.
*/
class NumbersCallSeed extends BaseSeed
{
Expand Down
2 changes: 1 addition & 1 deletion tests/test_app/config/Seeds/StoresSeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Migrations\BaseSeed;

/**
* NumbersSeed seed.
* StoresSeed seed.
*/
class StoresSeed extends BaseSeed
{
Expand Down