Skip to content

Commit

Permalink
Merge pull request #1871 from MasterOdin/create_schema
Browse files Browse the repository at this point in the history
add createSchema and dropSchema methods on MigrationInterface
  • Loading branch information
dereuromark committed Sep 28, 2020
2 parents a95dbef + 354c81d commit 1a05e29
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Phinx/Migration/AbstractMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,22 @@ public function dropDatabase($name)
$this->getAdapter()->dropDatabase($name);
}

/**
* @inheritDoc
*/
public function createSchema($name)
{
$this->getAdapter()->createSchema($name);
}

/**
* @inheritDoc
*/
public function dropSchema($name)
{
$this->getAdapter()->dropSchema($name);
}

/**
* @inheritDoc
*/
Expand Down
22 changes: 22 additions & 0 deletions src/Phinx/Migration/MigrationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,28 @@ public function createDatabase($name, $options);
*/
public function dropDatabase($name);

/**
* Creates schema.
*
* This will thrown an error for adapters that do not support schemas.
*
* @param string $name Schema name
* @return void
* @throws \BadMethodCallException
*/
public function createSchema($name);

/**
* Drops schema.
*
* This will thrown an error for adapters that do not support schemas.
*
* @param string $name Schema name
* @return void
* @throws \BadMethodCallException
*/
public function dropSchema($name);

/**
* Checks to see if a table exists.
*
Expand Down
34 changes: 34 additions & 0 deletions tests/Phinx/Migration/AbstractMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,40 @@ public function testDropDatabase()
$migrationStub->dropDatabase('testdb');
}

public function testCreateSchema()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', ['mockenv', 0]);

// stub adapter
$adapterStub = $this->getMockBuilder('\Phinx\Db\Adapter\PdoAdapter')
->setConstructorArgs([[]])
->getMock();
$adapterStub->expects($this->once())
->method('createSchema')
->with('testschema');

$migrationStub->setAdapter($adapterStub);
$migrationStub->createSchema('testschema');
}

public function testDropSchema()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', ['mockenv', 0]);

// stub adapter
$adapterStub = $this->getMockBuilder('\Phinx\Db\Adapter\PdoAdapter')
->setConstructorArgs([[]])
->getMock();
$adapterStub->expects($this->once())
->method('dropSchema')
->with('testschema');

$migrationStub->setAdapter($adapterStub);
$migrationStub->dropSchema('testschema');
}

public function testHasTable()
{
// stub migration
Expand Down

0 comments on commit 1a05e29

Please sign in to comment.