diff --git a/composer.json b/composer.json index 0dba8225..47fbbc81 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,12 @@ }, "require": { "php": ">=5.6.0", - "robmorgan/phinx": "~0.8.1", + "robmorgan/phinx": "~0.10.3", "cakephp/orm": "^3.6.0", "cakephp/cache": "^3.6.0" }, "require-dev": { - "phpunit/phpunit": "^5.7.14", + "phpunit/phpunit": "^5.7.14|^6.0", "cakephp/cakephp": "^3.6.0", "cakephp/bake": "^1.7.0", "cakephp/cakephp-codesniffer": "^3.0" diff --git a/src/CakeAdapter.php b/src/CakeAdapter.php index 2b67a268..d3ea4124 100644 --- a/src/CakeAdapter.php +++ b/src/CakeAdapter.php @@ -15,6 +15,7 @@ use Cake\Database\Driver\Postgres; use PDO; use Phinx\Db\Adapter\AdapterInterface; +use Phinx\Db\Adapter\AdapterWrapper; use Phinx\Db\Table as PhinxTable; use Phinx\Db\Table\Column; use Phinx\Db\Table\ForeignKey; @@ -27,16 +28,9 @@ * Decorates an AdapterInterface in order to proxy some method to the actual * connection object. */ -class CakeAdapter implements AdapterInterface +class CakeAdapter extends AdapterWrapper { - /** - * Decorated adapter - * - * @var \Phinx\Db\Adapter\AdapterInterface - */ - protected $adapter; - /** * Database connection * @@ -48,11 +42,16 @@ class CakeAdapter implements AdapterInterface * Constructor * * @param \Phinx\Db\Adapter\AdapterInterface $adapter The original adapter to decorate. - * @param \Cake\Database\Connection $connection The connection to actually use. + * @param \Cake\Database\Connection|null $connection The connection to actually use. */ - public function __construct(AdapterInterface $adapter, Connection $connection) + public function __construct(AdapterInterface $adapter, Connection $connection = null) { - $this->adapter = $adapter; + if ($connection === null) { + throw new \InvalidArgumentException("The cake connection cannot be null"); + } + + parent::__construct($adapter); + $this->connection = $connection; $pdo = $adapter->getConnection(); @@ -69,27 +68,6 @@ public function __construct(AdapterInterface $adapter, Connection $connection) $connection->getDriver()->setConnection($pdo); } - /** - * Gets the database PDO connection object. - * - * @return \PDO - */ - public function getConnection() - { - return $this->adapter->getConnection(); - } - - /** - * Gets the database PDO connection object. - * - * @param \PDO $connection Connection - * @return AdapterInterface - */ - public function setConnection($connection) - { - return $this->adapter->setConnection($connection); - } - /** * Gets the CakePHP Connection object. * @@ -101,680 +79,22 @@ public function getCakeConnection() } /** - * Get all migrated version numbers. - * - * @return array - */ - public function getVersions() - { - return $this->adapter->getVersions(); - } - - /** - * Get all migration log entries, indexed by version number. - * - * @return array - */ - public function getVersionLog() - { - return $this->adapter->getVersionLog(); - } - - /** - * Set adapter configuration options. - * - * @param array $options Options array. - * @return $this - */ - public function setOptions(array $options) - { - return $this->adapter->setOptions($options); - } - - /** - * Get all adapter options. - * - * @return array - */ - public function getOptions() - { - return $this->adapter->getOptions(); - } - - /** - * Check if an option has been set. - * - * @param string $name Option name. - * @return bool - */ - public function hasOption($name) - { - return $this->adapter->hasOption($name); - } - - /** - * Get a single adapter option, or null if the option does not exist. - * - * @param string $name Option name. - * @return mixed - */ - public function getOption($name) - { - return $this->adapter->getOption($name); - } - - /** - * Sets the console output. - * - * @param OutputInterface $output Output - * @return $this - */ - public function setOutput(OutputInterface $output) - { - return $this->adapter->setOutput($output); - } - - /** - * Gets the console output. - * - * @return OutputInterface - */ - public function getOutput() - { - return $this->adapter->getOutput(); - } - - /** - * Sets the command start time + * Returns a new Query object * - * @param int $time Start time. - * @return $this + * @return \Cake\Database\Query */ - public function setCommandStartTime($time) + public function getQueryBuilder() { - return $this->adapter->setCommandStartTime($time); + return $this->getCakeConnection()->newQuery(); } /** - * Gets the command start time - * - * @return int - */ - public function getCommandStartTime() - { - return $this->adapter->getCommandStartTime(); - } - - /** - * Start timing a command. - * - * @return void - */ - public function startCommandTimer() - { - $this->adapter->startCommandTimer(); - } - - /** - * Stop timing the current command and write the elapsed time to the - * output. - * - * @return void - */ - public function endCommandTimer() - { - $this->adapter->endCommandTimer(); - } - - /** - * Write a Phinx command to the output. - * - * @param string $command Command Name - * @param array $args Command Args - * @return void - */ - public function writeCommand($command, $args = []) - { - $this->adapter->writeCommand($command, $args); - } - - /** - * Records a migration being run. - * - * @param MigrationInterface $migration Migration - * @param string $direction Direction - * @param int $startTime Start Time - * @param int $endTime End Time - * @return $this - */ - public function migrated(MigrationInterface $migration, $direction, $startTime, $endTime) - { - return $this->adapter->migrated($migration, $direction, $startTime, $endTime); - } - - /** - * Does the schema table exist? - * - * @deprecated use hasTable instead. - * @return bool - */ - public function hasSchemaTable() - { - return $this->adapter->hasSchemaTable(); - } - - /** - * Creates the schema table. - * - * @return void - */ - public function createSchemaTable() - { - $this->adapter->createSchemaTable(); - } - - /** - * Returns the adapter type. + * Returns the adapter type name, for example mysql * * @return string */ public function getAdapterType() { - return $this->adapter->getAdapterType(); - } - - /** - * Initializes the database connection. - * - * @throws \RuntimeException When the requested database driver is not installed. - * @return void - */ - public function connect() - { - $this->adapter->connect(); - } - - /** - * Closes the database connection. - * - * @return void - */ - public function disconnect() - { - $this->adapter->disconnect(); - } - - /** - * Does the adapter support transactions? - * - * @return bool - */ - public function hasTransactions() - { - return $this->adapter->hasTransactions(); - } - - /** - * Begin a transaction. - * - * @return void - */ - public function beginTransaction() - { - $this->connection->begin(); - } - - /** - * Commit a transaction. - * - * @return void - */ - public function commitTransaction() - { - $this->connection->commit(); - } - - /** - * Rollback a transaction. - * - * @return void - */ - public function rollbackTransaction() - { - $this->connection->rollback(); - } - - /** - * Executes a SQL statement and returns the number of affected rows. - * - * @param string $sql SQL - * @return int - */ - public function execute($sql) - { - return $this->adapter->execute($sql); - } - - /** - * Executes a SQL statement and returns the result as an array. - * - * @param string $sql SQL - * @return array - */ - public function query($sql) - { - return $this->adapter->query($sql); - } - - /** - * Executes a query and returns only one row as an array. - * - * @param string $sql SQL - * @return array - */ - public function fetchRow($sql) - { - return $this->adapter->fetchRow($sql); - } - - /** - * Executes a query and returns an array of rows. - * - * @param string $sql SQL - * @return array - */ - public function fetchAll($sql) - { - return $this->adapter->fetchAll($sql); - } - - /** - * Inserts data into a table. - * - * @param \Phinx\Db\Table $table where to insert data - * @param array $row Row array. - * @return void - */ - public function insert(PhinxTable $table, $row) - { - $this->adapter->insert($table, $row); - } - - /** - * Quotes a table name for use in a query. - * - * @param string $tableName Table Name - * @return string - */ - public function quoteTableName($tableName) - { - return $this->adapter->quoteTableName($tableName); - } - - /** - * Quotes a column name for use in a query. - * - * @param string $columnName Table Name - * @return string - */ - public function quoteColumnName($columnName) - { - return $this->adapter->quoteColumnName($columnName); - } - - /** - * Checks to see if a table exists. - * - * @param string $tableName Table Name - * @return bool - */ - public function hasTable($tableName) - { - return $this->adapter->hasTable($tableName); - } - - /** - * Creates the specified database table. - * - * @param \Phinx\Db\Table $table Table - * @return void - */ - public function createTable(PhinxTable $table) - { - $this->adapter->createTable($table); - } - - /** - * Renames the specified database table. - * - * @param string $tableName Table Name - * @param string $newName New Name - * @return void - */ - public function renameTable($tableName, $newName) - { - $this->adapter->renameTable($tableName, $newName); - } - - /** - * Drops the specified database table. - * - * @param string $tableName Table Name - * @return void - */ - public function dropTable($tableName) - { - $this->adapter->dropTable($tableName); - } - - /** - * Truncates the specified table - * - * @param string $tableName Table name. - * @return void - */ - public function truncateTable($tableName) - { - $this->adapter->truncateTable($tableName); - } - - /** - * Returns table columns - * - * @param string $tableName Table Name - * @return Column[] - */ - public function getColumns($tableName) - { - return $this->adapter->getColumns($tableName); - } - - /** - * Checks to see if a column exists. - * - * @param string $tableName Table Name - * @param string $columnName Column Name - * @return bool - */ - public function hasColumn($tableName, $columnName) - { - return $this->adapter->hasColumn($tableName, $columnName); - } - - /** - * Adds the specified column to a database table. - * - * @param \Phinx\Db\Table $table Table - * @param \Phinx\Db\Table\Column $column Column - * @return void - */ - public function addColumn(PhinxTable $table, Column $column) - { - $this->adapter->addColumn($table, $column); - } - - /** - * Renames the specified column. - * - * @param string $tableName Table Name - * @param string $columnName Column Name - * @param string $newColumnName New Column Name - * @return void - */ - public function renameColumn($tableName, $columnName, $newColumnName) - { - $this->adapter->renameColumn($tableName, $columnName, $newColumnName); - } - - /** - * Change a table column type. - * - * @param string $tableName Table Name - * @param string $columnName Column Name - * @param \Phinx\Db\Table\Column $newColumn New Column - * @return \Phinx\Db\Table - */ - public function changeColumn($tableName, $columnName, Column $newColumn) - { - return $this->adapter->changeColumn($tableName, $columnName, $newColumn); - } - - /** - * Drops the specified column. - * - * @param string $tableName Table Name - * @param string $columnName Column Name - * @return void - */ - public function dropColumn($tableName, $columnName) - { - $this->adapter->dropColumn($tableName, $columnName); - } - - /** - * Checks to see if an index exists. - * - * @param string $tableName Table Name - * @param mixed $columns Column(s) - * @return bool - */ - public function hasIndex($tableName, $columns) - { - return $this->adapter->hasIndex($tableName, $columns); - } - - /** - * Checks to see if an index specified by name exists. - * - * @param string $tableName Table name. - * @param string $indexName Index name. - * @return bool - */ - public function hasIndexByName($tableName, $indexName) - { - return $this->adapter->hasIndexByName($tableName, $indexName); - } - - /** - * Adds the specified index to a database table. - * - * @param \Phinx\Db\Table $table Table - * @param Index $index Index - * @return void - */ - public function addIndex(PhinxTable $table, Index $index) - { - $this->adapter->addIndex($table, $index); - } - - /** - * Drops the specified index from a database table. - * - * @param string $tableName Table name. - * @param mixed $columns Column(s) - * @return void - */ - public function dropIndex($tableName, $columns) - { - $this->adapter->dropIndex($tableName, $columns); - } - - /** - * Drops the index specified by name from a database table. - * - * @param string $tableName Table name. - * @param string $indexName Index name. - * @return void - */ - public function dropIndexByName($tableName, $indexName) - { - $this->adapter->dropIndexByName($tableName, $indexName); - } - - /** - * Checks to see if a foreign key exists. - * - * @param string $tableName Table name. - * @param string[] $columns Column(s) - * @param string|null $constraint Constraint name - * @return bool - */ - public function hasForeignKey($tableName, $columns, $constraint = null) - { - return $this->adapter->hasForeignKey($tableName, $columns, $constraint); - } - - /** - * Adds the specified foreign key to a database table. - * - * @param \Phinx\Db\Table $table Table object. - * @param \Phinx\Db\Table\ForeignKey $foreignKey Foreign key object. - * @return void - */ - public function addForeignKey(PhinxTable $table, ForeignKey $foreignKey) - { - $this->adapter->addForeignKey($table, $foreignKey); - } - - /** - * Drops the specified foreign key from a database table. - * If the adapter property is an instance of the \Phinx\Db\Adapter\SQLiteAdapter, - * a specific method will be called. The original one from Phinx contains a bug - * that can drop a table in certain conditions. - * - * @param string $tableName Table name. - * @param string[] $columns Column(s) - * @param string|null $constraint Constraint name - * @return void - */ - public function dropForeignKey($tableName, $columns, $constraint = null) - { - $this->adapter->dropForeignKey($tableName, $columns, $constraint); - } - - /** - * Returns an array of the supported Phinx column types. - * - * @return array - */ - public function getColumnTypes() - { - return $this->adapter->getColumnTypes(); - } - - /** - * Checks that the given column is of a supported type. - * - * @param \Phinx\Db\Table\Column $column Column object. - * @return bool - */ - public function isValidColumnType(Column $column) - { - return $this->adapter->isValidColumnType($column); - } - - /** - * Converts the Phinx logical type to the adapter's SQL type. - * - * @param string $type Type name. - * @param int|null $limit Limit. - * @return string - */ - public function getSqlType($type, $limit = null) - { - return $this->adapter->getSqlType($type, $limit); - } - - /** - * Creates a new database. - * - * @param string $name Database Name - * @param array $options Options - * @return void - */ - public function createDatabase($name, $options = []) - { - $this->adapter->createDatabase($name, $options); - } - - /** - * Checks to see if a database exists. - * - * @param string $name Database Name - * @return bool - */ - public function hasDatabase($name) - { - return $this->adapter->hasDatabase($name); - } - - /** - * Drops the specified database. - * - * @param string $name Database Name - * @return void - */ - public function dropDatabase($name) - { - $this->adapter->dropDatabase($name); - } - - /** - * Cast a value to a boolean appropriate for the adapter. - * - * @param mixed $value The value to be cast - * - * @return mixed - */ - public function castToBool($value) - { - return $this->adapter->castToBool($value); - } - - /** - * Sets the console input. - * - * @param InputInterface $input Input - * @return $this - */ - public function setInput(InputInterface $input) - { - $this->adapter->setInput($input); - - return $this; - } - - /** - * Gets the console input. - * - * @return InputInterface - */ - public function getInput() - { - return $this->adapter->getInput(); - } - - /** - * Toggle a migration breakpoint. - * - * @param MigrationInterface $migration Migration instance. - * - * @return $this - */ - public function toggleBreakpoint(MigrationInterface $migration) - { - $this->adapter->toggleBreakpoint($migration); - - return $this; - } - - /** - * Reset all migration breakpoints. - * - * @return int The number of breakpoints reset - */ - public function resetAllBreakpoints() - { - return $this->adapter->resetAllBreakpoints(); + return $this->getAdapter()->getAdapterType(); } } diff --git a/src/CakeManager.php b/src/CakeManager.php index 367ccfc8..23e6d804 100644 --- a/src/CakeManager.php +++ b/src/CakeManager.php @@ -61,14 +61,14 @@ public function printStatus($environment, $format = null) { $migrations = []; $isJson = $format === 'json'; - if (count($this->getMigrations())) { + if (count($this->getMigrations('default'))) { $env = $this->getEnvironment($environment); $versions = $env->getVersionLog(); $this->maxNameLength = $versions ? max(array_map(function ($version) { return strlen($version['migration_name']); }, $versions)) : 0; - foreach ($this->getMigrations() as $migration) { + foreach ($this->getMigrations('default') as $migration) { if (array_key_exists($migration->getVersion(), $versions)) { $status = 'up'; unset($versions[$migration->getVersion()]); @@ -117,9 +117,9 @@ public function printStatus($environment, $format = null) /** * {@inheritdoc} */ - public function migrateToDateTime($environment, \DateTime $dateTime) + public function migrateToDateTime($environment, \DateTime $dateTime, $fake = false) { - $versions = array_keys($this->getMigrations()); + $versions = array_keys($this->getMigrations('default')); $dateString = $dateTime->format('Ymdhis'); $versionToMigrate = null; foreach ($versions as $version) { @@ -139,7 +139,7 @@ public function migrateToDateTime($environment, \DateTime $dateTime) $this->getOutput()->writeln( 'Migrating to version ' . $versionToMigrate ); - $this->migrate($environment, $versionToMigrate); + $this->migrate($environment, $versionToMigrate, $fake); } /** @@ -215,7 +215,7 @@ public function markMigrated($version, $path) $migrationFile = $migrationFile[0]; $className = $this->getMigrationClassName($migrationFile); require_once $migrationFile; - $Migration = new $className($version); + $Migration = new $className('default', $version); $time = date('Y-m-d H:i:s', time()); @@ -235,7 +235,7 @@ public function markMigrated($version, $path) */ public function getVersionsToMark($input) { - $migrations = $this->getMigrations(); + $migrations = $this->getMigrations('default'); $versions = array_keys($migrations); $versionArg = $input->getArgument('version'); diff --git a/src/Command/Migrate.php b/src/Command/Migrate.php index 1389915b..f4fcbfe6 100644 --- a/src/Command/Migrate.php +++ b/src/Command/Migrate.php @@ -37,9 +37,11 @@ protected function configure() ->setHelp('runs all available migrations, optionally up to a specific version') ->addOption('--target', '-t', InputOption::VALUE_REQUIRED, 'The version number to migrate to') ->addOption('--date', '-d', InputOption::VALUE_REQUIRED, 'The date to migrate to') + ->addOption('--dry-run', '-x', InputOption::VALUE_NONE, 'Dump queries to standard output instead of executing it') ->addOption('--plugin', '-p', InputOption::VALUE_REQUIRED, 'The plugin containing the migrations') ->addOption('--connection', '-c', InputOption::VALUE_REQUIRED, 'The datasource connection to use') ->addOption('--source', '-s', InputOption::VALUE_REQUIRED, 'The folder where migrations are in') + ->addOption('--fake', null, InputOption::VALUE_NONE, "Mark any migrations selected as run, but don't actually execute them") ->addOption( '--no-lock', null, diff --git a/src/Command/Rollback.php b/src/Command/Rollback.php index d149cb85..f3af4647 100644 --- a/src/Command/Rollback.php +++ b/src/Command/Rollback.php @@ -41,6 +41,8 @@ protected function configure() ->addOption('--connection', '-c', InputOption::VALUE_REQUIRED, 'The datasource connection to use') ->addOption('--source', '-s', InputOption::VALUE_REQUIRED, 'The folder where migrations are in') ->addOption('--force', '-f', InputOption::VALUE_NONE, 'Force rollback to ignore breakpoints') + ->addOption('--dry-run', '-x', InputOption::VALUE_NONE, 'Dump queries to standard output instead of executing it') + ->addOption('--fake', null, InputOption::VALUE_NONE, "Mark any rollbacks selected as run, but don't actually execute them") ->addOption( '--no-lock', null, diff --git a/src/ConfigurationTrait.php b/src/ConfigurationTrait.php index 66da0abf..aa1e4083 100644 --- a/src/ConfigurationTrait.php +++ b/src/ConfigurationTrait.php @@ -103,6 +103,7 @@ public function getConfig($forceRefresh = false) 'name' => $connectionConfig['database'], 'charset' => isset($connectionConfig['encoding']) ? $connectionConfig['encoding'] : null, 'unix_socket' => isset($connectionConfig['unix_socket']) ? $connectionConfig['unix_socket'] : null, + 'suffix' => '', ] ] ]; diff --git a/src/Migrations.php b/src/Migrations.php index 1bbf541c..0d01377f 100644 --- a/src/Migrations.php +++ b/src/Migrations.php @@ -14,6 +14,7 @@ use Cake\Datasource\ConnectionManager; use Phinx\Config\Config; use Phinx\Config\ConfigInterface; +use Phinx\Db\Adapter\WrapperInterface; use Phinx\Migration\Manager; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; @@ -306,9 +307,11 @@ protected function run($method, $params, $input) $manager->setInput($input); if (isset($pdo)) { - $this->manager->getEnvironment('default') - ->getAdapter() - ->setConnection($pdo); + $adapter = $this->manager->getEnvironment('default')->getAdapter(); + while ($adapter instanceof WrapperInterface) { + $adapter = $adapter->getAdapter(); + } + $adapter->setConnection($pdo); } $newMigrationPaths = $newConfig->getMigrationPaths(); diff --git a/src/Shell/MigrationsShell.php b/src/Shell/MigrationsShell.php index 56661bc8..f45e0501 100644 --- a/src/Shell/MigrationsShell.php +++ b/src/Shell/MigrationsShell.php @@ -74,7 +74,7 @@ public function getOptionParser() ->addOption('template', ['short' => 't']) ->addOption('format', ['short' => 'f']) ->addOption('only', ['short' => 'o']) - ->addOption('exclude', ['short' => 'x']); + ->addOption('exclude', ['short' => 'e']); } /** diff --git a/src/Shell/Task/MigrateTask.php b/src/Shell/Task/MigrateTask.php index 384b6a1f..50bb0999 100644 --- a/src/Shell/Task/MigrateTask.php +++ b/src/Shell/Task/MigrateTask.php @@ -38,6 +38,8 @@ public function getOptionParser() 'help' => 'The date to migrate to', 'required' => false ]) + ->addOption('dry-run', ['short' => 'x']) + ->addOption('fake', ['boolean' => true]) ->addOption('no-lock', [ 'help' => 'If present, no lock file will be generated after migrating', 'boolean' => true diff --git a/src/Shell/Task/RollbackTask.php b/src/Shell/Task/RollbackTask.php index 46c2f88b..a11dbdb3 100644 --- a/src/Shell/Task/RollbackTask.php +++ b/src/Shell/Task/RollbackTask.php @@ -38,6 +38,8 @@ public function getOptionParser() 'help' => 'The date to migrate to', 'required' => false ]) + ->addOption('dry-run', ['short' => 'x']) + ->addOption('fake', ['boolean' => true]) ->addOption('no-lock', [ 'help' => 'If present, no lock file will be generated after rolling back', 'boolean' => true diff --git a/src/Table.php b/src/Table.php index 42fd6a0b..64447fab 100644 --- a/src/Table.php +++ b/src/Table.php @@ -66,12 +66,12 @@ public function addColumn($columnName, $type = null, $options = []) */ public function create() { - if ((!isset($this->options['id']) || $this->options['id'] === false) && !empty($this->primaryKey)) { - $this->options['primary_key'] = $this->primaryKey; + $options = $this->getTable()->getOptions(); + if ((!isset($options['id']) || $options['id'] === false) && !empty($this->primaryKey)) { + $options['primary_key'] = $this->primaryKey; $this->filterPrimaryKey(); } - $options = $this->getOptions(); if ($this->getAdapter()->getAdapterType() === 'mysql' && empty($options['collation'])) { $encodingRequest = 'SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = "%s"'; @@ -83,10 +83,11 @@ public function create() $defaultEncoding = $cakeConnection->execute($encodingRequest)->fetch('assoc'); if (!empty($defaultEncoding['DEFAULT_COLLATION_NAME'])) { $options['collation'] = $defaultEncoding['DEFAULT_COLLATION_NAME']; - $this->setOptions($options); } } + $this->getTable()->setOptions($options); + parent::create(); } @@ -99,10 +100,6 @@ public function create() */ public function update() { - if ($this->getAdapter()->getAdapterType() == 'sqlite') { - $this->foreignKeys = []; - } - parent::update(); TableRegistry::clear(); } @@ -134,17 +131,24 @@ public function dropForeignKey($columns, $constraint = null) */ protected function filterPrimaryKey() { - if ($this->getAdapter()->getAdapterType() !== 'sqlite' || empty($this->options['primary_key'])) { + $options = $this->getTable()->getOptions(); + if ($this->getAdapter()->getAdapterType() !== 'sqlite' || empty($options['primary_key'])) { return; } - $primaryKey = $this->options['primary_key']; + $primaryKey = $options['primary_key']; if (!is_array($primaryKey)) { $primaryKey = [$primaryKey]; } $primaryKey = array_flip($primaryKey); - $columnsCollection = new Collection($this->columns); + $columnsCollection = (new Collection($this->actions->getActions())) + ->filter(function ($action) { + return $action instanceof \Phinx\Db\Action\AddColumn; + }) + ->map(function ($action) { + return $action->getColumn(); + }); $primaryKeyColumns = $columnsCollection->filter(function ($columnDef, $key) use ($primaryKey) { return isset($primaryKey[$columnDef->getName()]); })->toArray(); @@ -162,9 +166,11 @@ protected function filterPrimaryKey() $primaryKey = array_flip($primaryKey); if (!empty($primaryKey)) { - $this->options['primary_key'] = $primaryKey; + $options['primary_key'] = $primaryKey; } else { - unset($this->options['primary_key']); + unset($options['primary_key']); } + + $this->getTable()->setOptions($options); } } diff --git a/src/Template/Bake/config/diff.ctp b/src/Template/Bake/config/diff.ctp index 50745780..2f44f55d 100644 --- a/src/Template/Bake/config/diff.ctp +++ b/src/Template/Bake/config/diff.ctp @@ -110,7 +110,7 @@ class <%= $name %> extends AbstractMigration <%- if (!empty($tables['remove'])): %> <%- foreach ($tables['remove'] as $tableName => $table): %> - $this->dropTable('<%= $tableName %>'); + $this->table('<%= $tableName %>')->drop()->save(); <%- endforeach; %> <%- endif; %> } @@ -131,7 +131,7 @@ class <%= $name %> extends AbstractMigration <%- foreach ($columnsList as $key => $columns): %> ->dropForeignKey( <%= $columns %> - )<%= ($key === $maxKey) ? ';' : '' %> + )<%= ($key === $maxKey) ? '->save();' : '' %> <%- endforeach; %> <%- endforeach; %> <%- endif; %> @@ -197,7 +197,7 @@ class <%= $name %> extends AbstractMigration <%- if (!empty($tables['add'])): %> <%- foreach ($tables['add'] as $tableName => $table): %> - $this->dropTable('<%= $tableName %>'); + $this->table('<%= $tableName %>')->drop()->save(); <%- endforeach; %> <%- endif; %> } diff --git a/src/Template/Bake/config/snapshot.ctp b/src/Template/Bake/config/snapshot.ctp index 71b5164c..19f7ddab 100644 --- a/src/Template/Bake/config/snapshot.ctp +++ b/src/Template/Bake/config/snapshot.ctp @@ -47,14 +47,14 @@ class <%= $name %> extends AbstractMigration <%- foreach ($columnsList as $key => $columns): %> ->dropForeignKey( <%= $columns %> - )<%= ($key === $maxKey) ? ';' : '' %> + )<%= ($key === $maxKey) ? '->save();' : '' %> <%- endforeach; %> <%- endforeach; endif; %> <%- foreach ($tables as $table): %> - $this->dropTable('<%= $table%>'); + $this->table('<%= $table%>')->drop()->save(); <%- endforeach; %> } } diff --git a/tests/TestCase/Command/CreateTest.php b/tests/TestCase/Command/CreateTest.php index 6800b9b4..c1131c73 100644 --- a/tests/TestCase/Command/CreateTest.php +++ b/tests/TestCase/Command/CreateTest.php @@ -7,6 +7,7 @@ use Cake\TestSuite\TestCase; use Migrations\CakeManager; use Migrations\MigrationsDispatcher; +use Phinx\Db\Adapter\WrapperInterface; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\StreamOutput; use Symfony\Component\Console\Tester\CommandTester; @@ -117,7 +118,11 @@ protected function getCommandTester($params) $input = new ArrayInput($params, $this->command->getDefinition()); $this->command->setInput($input); $manager = new CakeManager($this->command->getConfig(), $input, $this->streamOutput); - $manager->getEnvironment('default')->getAdapter()->setConnection($this->Connection->getDriver()->getConnection()); + $adapter = $manager->getEnvironment('default')->getAdapter(); + while ($adapter instanceof WrapperInterface) { + $adapter = $adapter->getAdapter(); + } + $adapter->setConnection($this->Connection->getDriver()->getConnection()); $this->command->setManager($manager); $commandTester = new \Migrations\Test\CommandTester($this->command); diff --git a/tests/TestCase/Command/DumpTest.php b/tests/TestCase/Command/DumpTest.php index 0d0781f0..67e7e24c 100644 --- a/tests/TestCase/Command/DumpTest.php +++ b/tests/TestCase/Command/DumpTest.php @@ -20,6 +20,7 @@ use Migrations\CakeManager; use Migrations\Migrations; use Migrations\MigrationsDispatcher; +use Phinx\Db\Adapter\WrapperInterface; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\StreamOutput; use Symfony\Component\Console\Tester\CommandTester; @@ -71,6 +72,7 @@ public function setUp() parent::setUp(); $this->Connection = ConnectionManager::get('test'); + $this->Connection->connect(); $this->pdo = $this->Connection->getDriver()->getConnection(); $application = new MigrationsDispatcher('testing'); $this->command = $application->find('dump'); @@ -149,7 +151,7 @@ public function testExecuteTables() $this->assertEquals(['id', 'number', 'radix'], $generatedDump['numbers']->columns()); $this->assertEquals(['id', 'letter'], $generatedDump['letters']->columns()); - $migrations->rollback(['target' => 0]); + $migrations->rollback(['target' => 'all']); } /** @@ -166,7 +168,15 @@ protected function getCommandTester($params) $input = new ArrayInput($params, $this->command->getDefinition()); $this->command->setInput($input); $manager = new CakeManager($this->command->getConfig(), $input, $this->streamOutput); - $manager->getEnvironment('default')->getAdapter()->setConnection($this->pdo); + + $adapter = $manager + ->getEnvironment('default') + ->getAdapter(); + while ($adapter instanceof WrapperInterface) { + $adapter = $adapter->getAdapter(); + } + $adapter->setConnection($this->pdo); + $this->command->setManager($manager); $commandTester = new \Migrations\Test\CommandTester($this->command); @@ -186,11 +196,16 @@ protected function getMigrations() 'source' => 'TestsMigrations' ]; $migrations = new Migrations($params); - $migrations + $adapter = $migrations ->getManager($this->command->getConfig()) ->getEnvironment('default') - ->getAdapter() - ->setConnection($this->pdo); + ->getAdapter(); + + while ($adapter instanceof WrapperInterface) { + $adapter = $adapter->getAdapter(); + } + + $adapter->setConnection($this->pdo); $tables = (new Collection($this->Connection))->listTables(); if (in_array('phinxlog', $tables)) { diff --git a/tests/TestCase/Command/MarkMigratedTest.php b/tests/TestCase/Command/MarkMigratedTest.php index 6652b46e..19a5e3c3 100644 --- a/tests/TestCase/Command/MarkMigratedTest.php +++ b/tests/TestCase/Command/MarkMigratedTest.php @@ -62,6 +62,7 @@ public function setUp() parent::setUp(); $this->Connection = ConnectionManager::get('test'); + $this->Connection->connect(); $this->pdo = $this->Connection->getDriver()->getConnection(); $this->Connection->execute('DROP TABLE IF EXISTS phinxlog'); $this->Connection->execute('DROP TABLE IF EXISTS numbers'); @@ -140,7 +141,7 @@ public function testExecute() $config = $this->command->getConfig(); $env = $this->command->getManager()->getEnvironment('default'); - $migrations = $this->command->getManager()->getMigrations(); + $migrations = $this->command->getManager()->getMigrations('default'); $manager = $this->getMockBuilder('\Migrations\CakeManager') ->setMethods(['getEnvironment', 'markMigrated', 'getMigrations']) diff --git a/tests/TestCase/Command/SeedTest.php b/tests/TestCase/Command/SeedTest.php index 85a78796..94bcc2b5 100644 --- a/tests/TestCase/Command/SeedTest.php +++ b/tests/TestCase/Command/SeedTest.php @@ -18,6 +18,7 @@ use Migrations\CakeManager; use Migrations\Migrations; use Migrations\MigrationsDispatcher; +use Phinx\Db\Adapter\WrapperInterface; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\StreamOutput; @@ -66,6 +67,7 @@ public function setUp() parent::setUp(); $this->Connection = ConnectionManager::get('test'); + $this->Connection->connect(); $this->pdo = $this->Connection->getDriver()->getConnection(); $application = new MigrationsDispatcher('testing'); $this->command = $application->find('seed'); @@ -124,7 +126,7 @@ public function testExecute() ]; $this->assertEquals($expected, $result); - $migrations->rollback(['target' => 0]); + $migrations->rollback(['target' => 'all']); } /** @@ -165,7 +167,7 @@ public function testExecuteCustomParams() ] ]; $this->assertEquals($expected, $result); - $migrations->rollback(['target' => 0]); + $migrations->rollback(['target' => 'all']); } /** @@ -191,7 +193,7 @@ public function testExecuteWrongCustomParams() $display = $this->getDisplayFromOutput(); $this->assertTextNotContains('seeded', $display); - $migrations->rollback(['target' => 0]); + $migrations->rollback(['target' => 'all']); } /** @@ -219,7 +221,7 @@ public function testExecuteSeedCallingOtherSeeders() $display = $this->getDisplayFromOutput(); $this->assertTextContains('==== NumbersCallSeed: seeded', $display); $this->assertTextContains('==== LettersSeed: seeded', $display); - $migrations->rollback(['target' => 0]); + $migrations->rollback(['target' => 'all']); } /** @@ -236,7 +238,13 @@ protected function getCommandTester($params) $input = new ArrayInput($params, $this->command->getDefinition()); $this->command->setInput($input); $manager = new CakeManager($this->command->getConfig(), $input, $this->streamOutput); - $manager->getEnvironment('default')->getAdapter()->setConnection($this->pdo); + $adapter = $manager + ->getEnvironment('default') + ->getAdapter(); + while ($adapter instanceof WrapperInterface) { + $adapter = $adapter->getAdapter(); + } + $adapter->setConnection($this->pdo); $this->command->setManager($manager); $commandTester = new \Migrations\Test\CommandTester($this->command); @@ -256,11 +264,15 @@ protected function getMigrations() 'source' => 'TestsMigrations' ]; $migrations = new Migrations($params); - $migrations + $adapter = $migrations ->getManager($this->command->getConfig()) ->getEnvironment('default') - ->getAdapter() - ->setConnection($this->pdo); + ->getAdapter(); + + while ($adapter instanceof WrapperInterface) { + $adapter = $adapter->getAdapter(); + } + $adapter->setConnection($this->pdo); return $migrations; } diff --git a/tests/TestCase/Command/StatusTest.php b/tests/TestCase/Command/StatusTest.php index 7e6a0aee..c7759291 100644 --- a/tests/TestCase/Command/StatusTest.php +++ b/tests/TestCase/Command/StatusTest.php @@ -16,6 +16,7 @@ use Migrations\CakeManager; use Migrations\Migrations; use Migrations\MigrationsDispatcher; +use Phinx\Db\Adapter\WrapperInterface; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\StreamOutput; @@ -71,6 +72,7 @@ public function setUp() parent::setUp(); $this->Connection = ConnectionManager::get('test'); + $this->Connection->connect(); $this->pdo = $this->Connection->getDriver()->getConnection(); $this->Connection->execute('DROP TABLE IF EXISTS phinxlog'); $this->Connection->execute('DROP TABLE IF EXISTS numbers'); @@ -164,7 +166,7 @@ public function testExecuteWithMigrated() $this->assertTextContains('up 20150724233100 UpdateNumbersTable', $display); $this->assertTextContains('up 20150826191400 CreateLettersTable', $display); - $migrations->rollback(['target' => 0]); + $migrations->rollback(['target' => 'all']); } /** @@ -202,7 +204,7 @@ public function testExecuteWithInconsistency() rename($destination, $origin); - $migrations->rollback(['target' => 0]); + $migrations->rollback(['target' => 'all']); } /** @@ -219,7 +221,13 @@ protected function getCommandTester($params) $input = new ArrayInput($params, $this->command->getDefinition()); $this->command->setInput($input); $manager = new CakeManager($this->command->getConfig(), $input, $this->streamOutput); - $manager->getEnvironment('default')->getAdapter()->setConnection($this->pdo); + $adapter = $manager + ->getEnvironment('default') + ->getAdapter(); + while ($adapter instanceof WrapperInterface) { + $adapter = $adapter->getAdapter(); + } + $adapter->setConnection($this->pdo); $this->command->setManager($manager); $commandTester = new \Migrations\Test\CommandTester($this->command); @@ -239,11 +247,15 @@ protected function getMigrations() 'source' => 'TestsMigrations' ]; $migrations = new Migrations($params); - $migrations + + $adapter = $migrations ->getManager($this->command->getConfig()) ->getEnvironment('default') - ->getAdapter() - ->setConnection($this->pdo); + ->getAdapter(); + while ($adapter instanceof WrapperInterface) { + $adapter = $adapter->getAdapter(); + } + $adapter->setConnection($this->pdo); return $migrations; } diff --git a/tests/TestCase/MigrationsTest.php b/tests/TestCase/MigrationsTest.php index f3d60e81..dbec67f7 100644 --- a/tests/TestCase/MigrationsTest.php +++ b/tests/TestCase/MigrationsTest.php @@ -17,6 +17,7 @@ use Cake\ORM\TableRegistry; use Cake\TestSuite\TestCase; use Migrations\Migrations; +use Phinx\Db\Adapter\WrapperInterface; /** * Tests the Migrations class @@ -62,11 +63,15 @@ public function setUp() // Get an instance of the Migrations object on which we will run the tests $this->migrations = new Migrations($params); - $this->migrations - ->getManager($migrations->getConfig()) - ->getEnvironment('default') - ->getAdapter() - ->setConnection($connection); + $adapter = $this->migrations + ->getManager($migrations->getConfig()) + ->getEnvironment('default') + ->getAdapter(); + + while ($adapter instanceof WrapperInterface) { + $adapter = $adapter->getAdapter(); + } + $adapter->setConnection($connection); $tables = (new Collection($this->Connection))->listTables(); if (in_array('phinxlog', $tables)) { @@ -180,7 +185,7 @@ public function testMigrateAndRollback() // Migrate all again and rollback all $this->migrations->migrate(); - $rollback = $this->migrations->rollback(['target' => 0]); + $rollback = $this->migrations->rollback(['target' => 'all']); $this->assertTrue($rollback); $expectedStatus[0]['status'] = $expectedStatus[1]['status'] = 'down'; $status = $this->migrations->status(); @@ -209,7 +214,7 @@ public function testCreateWithEncoding() $options = $lettersTable->getSchema()->getOptions(); $this->assertEquals('utf8mb4_general_ci', $options['collation']); - $this->migrations->rollback(['target' => 0]); + $this->migrations->rollback(['target' => 'all']); } /** @@ -726,7 +731,7 @@ public function testSeed() ] ]; $this->assertEquals($expected, $result); - $this->migrations->rollback(['target' => 0]); + $this->migrations->rollback(['target' => 'all']); } /** @@ -775,7 +780,7 @@ public function testSeedOneSeeder() ]; $this->assertEquals($expected, $result); - $this->migrations->rollback(['target' => 0]); + $this->migrations->rollback(['target' => 'all']); } /** @@ -836,7 +841,7 @@ public function testSeedCallSeeder() ]; $this->assertEquals($expected, $result); - $this->migrations->rollback(['target' => 0]); + $this->migrations->rollback(['target' => 'all']); } /** @@ -879,7 +884,7 @@ public function testMigrateSnapshots($basePath, $files) $result = $this->migrations->migrate(['source' => 'SnapshotTests']); $this->assertTrue($result); - $this->migrations->rollback(['target' => 0, 'source' => 'SnapshotTests']); + $this->migrations->rollback(['target' => 'all', 'source' => 'SnapshotTests']); unlink($destination . $copiedFileName); } } diff --git a/tests/TestCase/Shell/Task/CommandTaskTest.php b/tests/TestCase/Shell/Task/CommandTaskTest.php index e0ffa1c2..5033ed4d 100644 --- a/tests/TestCase/Shell/Task/CommandTaskTest.php +++ b/tests/TestCase/Shell/Task/CommandTaskTest.php @@ -126,8 +126,9 @@ public function testMigrationsOptionsMigrate() { $this->Shell->runCommand(['options', 'Migrations.migrations', 'migrate']); $output = $this->out->output; - $expected = "--ansi --help -h --no-ansi --no-interaction -n --no-lock --quiet -q --verbose -v --connection -c"; - $expected .= " --date -d --plugin -p --source -s --target -t"; + $expected = "--ansi --dry-run -x --fake --help -h --no-ansi --no-interaction"; + $expected .= " -n --no-lock --quiet -q --verbose -v --connection -c --date -d"; + $expected .= " --plugin -p --source -s --target -t"; $outputExplode = explode(' ', trim($output)); sort($outputExplode); $expectedExplode = explode(' ', $expected); @@ -146,8 +147,8 @@ public function testMigrationsOptionsRollback() { $this->Shell->runCommand(['options', 'Migrations.migrations', 'rollback']); $output = $this->out->output; - $expected = "--ansi --help -h --no-ansi --no-interaction -n --no-lock --quiet -q --verbose -v --connection -c"; - $expected .= " --date -d --plugin -p --source -s --target -t"; + $expected = "--ansi --dry-run -x --fake --help -h --no-ansi --no-interaction -n --no-lock"; + $expected .= " --quiet -q --verbose -v --connection -c --date -d --plugin -p --source -s --target -t"; $outputExplode = explode(' ', trim($output)); sort($outputExplode); $expectedExplode = explode(' ', $expected); diff --git a/tests/TestCase/Shell/Task/MigrationDiffTaskTest.php b/tests/TestCase/Shell/Task/MigrationDiffTaskTest.php index f48b45b9..f61fa740 100644 --- a/tests/TestCase/Shell/Task/MigrationDiffTaskTest.php +++ b/tests/TestCase/Shell/Task/MigrationDiffTaskTest.php @@ -222,7 +222,7 @@ public function testBakingDiff() 'end_time' => '2016-05-22 16:51:46', ]) ->execute(); - $this->getMigrations()->rollback(['target' => 0]); + $this->getMigrations()->rollback(['target' => 'all']); foreach ($table->dropSql($connection) as $stmt) { $connection->query($stmt); @@ -304,7 +304,7 @@ public function testBakingDiffSimple() 'end_time' => '2016-05-22 16:51:46', ]) ->execute(); - $this->getMigrations('MigrationsDiffSimple')->rollback(['target' => 0]); + $this->getMigrations('MigrationsDiffSimple')->rollback(['target' => 'all']); unlink($destinationDumpPath); unlink($destination); } @@ -381,7 +381,7 @@ public function testBakingDiffAddRemove() 'end_time' => '2016-05-22 16:51:46', ]) ->execute(); - $this->getMigrations('MigrationsDiffAddRemove')->rollback(['target' => 0]); + $this->getMigrations('MigrationsDiffAddRemove')->rollback(['target' => 'all']); unlink($destinationDumpPath); unlink($destination); } diff --git a/tests/comparisons/Diff/simple/the_diff_simple_mysql.php b/tests/comparisons/Diff/simple/the_diff_simple_mysql.php index b3f2137e..2e50ac58 100644 --- a/tests/comparisons/Diff/simple/the_diff_simple_mysql.php +++ b/tests/comparisons/Diff/simple/the_diff_simple_mysql.php @@ -55,7 +55,7 @@ public function down() $this->table('articles') ->dropForeignKey( 'user_id' - ); + )->save(); $this->table('articles') ->removeIndexByName('user_id') @@ -65,7 +65,7 @@ public function down() ->removeColumn('user_id') ->update(); - $this->dropTable('users'); + $this->table('users')->drop()->save(); } } diff --git a/tests/comparisons/Diff/simple/the_diff_simple_pgsql.php b/tests/comparisons/Diff/simple/the_diff_simple_pgsql.php index 8a189e21..fbca11d2 100644 --- a/tests/comparisons/Diff/simple/the_diff_simple_pgsql.php +++ b/tests/comparisons/Diff/simple/the_diff_simple_pgsql.php @@ -55,7 +55,7 @@ public function down() $this->table('articles') ->dropForeignKey( 'user_id' - ); + )->save(); $this->table('articles') ->removeIndexByName('user_id') @@ -65,7 +65,7 @@ public function down() ->removeColumn('user_id') ->update(); - $this->dropTable('users'); + $this->table('users')->drop->save(); } } diff --git a/tests/comparisons/Diff/the_diff.php b/tests/comparisons/Diff/the_diff.php index 9ca4350d..aa7701d8 100644 --- a/tests/comparisons/Diff/the_diff.php +++ b/tests/comparisons/Diff/the_diff.php @@ -114,7 +114,7 @@ public function up() ) ->update(); - $this->dropTable('tags'); + $this->table('tags')->drop()->save(); } public function down() @@ -122,12 +122,12 @@ public function down() $this->table('categories') ->dropForeignKey( 'user_id' - ); + )->save(); $this->table('articles') ->dropForeignKey( 'category_id' - ); + )->save(); $this->table('tags') ->addColumn('name', 'string', [ @@ -201,7 +201,7 @@ public function down() ) ->update(); - $this->dropTable('categories'); + $this->table('categories')->drop()->save(); } } diff --git a/tests/comparisons/Diff/the_diff_mysql.php b/tests/comparisons/Diff/the_diff_mysql.php index 39f5cfe9..4ff9c666 100644 --- a/tests/comparisons/Diff/the_diff_mysql.php +++ b/tests/comparisons/Diff/the_diff_mysql.php @@ -114,7 +114,7 @@ public function up() ) ->update(); - $this->dropTable('tags'); + $this->table('tags')->drop()->save(); } public function down() @@ -122,12 +122,12 @@ public function down() $this->table('categories') ->dropForeignKey( 'user_id' - ); + )->save(); $this->table('articles') ->dropForeignKey( 'category_id' - ); + )->save(); $this->table('tags') ->addColumn('name', 'string', [ @@ -201,7 +201,7 @@ public function down() ) ->update(); - $this->dropTable('categories'); + $this->table('categories')->drop()->save(); } } diff --git a/tests/comparisons/Diff/the_diff_pgsql.php b/tests/comparisons/Diff/the_diff_pgsql.php index 8615a923..d910e626 100644 --- a/tests/comparisons/Diff/the_diff_pgsql.php +++ b/tests/comparisons/Diff/the_diff_pgsql.php @@ -114,7 +114,7 @@ public function up() ) ->update(); - $this->dropTable('tags'); + $this->table('tags')->drop()->save(); } public function down() @@ -122,12 +122,12 @@ public function down() $this->table('categories') ->dropForeignKey( 'user_id' - ); + )->save(); $this->table('articles') ->dropForeignKey( 'category_id' - ); + )->save(); $this->table('tags') ->addColumn('name', 'string', [ @@ -201,7 +201,7 @@ public function down() ) ->update(); - $this->dropTable('categories'); + $this->table('categories')->drop()->save(); } } diff --git a/tests/comparisons/Migration/pgsql/test_auto_id_disabled_snapshot_pgsql.php b/tests/comparisons/Migration/pgsql/test_auto_id_disabled_snapshot_pgsql.php index 3820579c..e042b495 100644 --- a/tests/comparisons/Migration/pgsql/test_auto_id_disabled_snapshot_pgsql.php +++ b/tests/comparisons/Migration/pgsql/test_auto_id_disabled_snapshot_pgsql.php @@ -359,7 +359,7 @@ public function down() ) ->dropForeignKey( 'product_id' - ); + )->save(); $this->table('orders') ->dropForeignKey( @@ -367,20 +367,20 @@ public function down() 'product_category', 'product_id', ] - ); + )->save(); $this->table('products') ->dropForeignKey( 'category_id' - ); + )->save(); - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('composite_pks'); - $this->dropTable('orders'); - $this->dropTable('products'); - $this->dropTable('special_pks'); - $this->dropTable('special_tags'); - $this->dropTable('users'); + $this->table('articles')->drop()->save(); + $this->table('categories')->drop()->save(); + $this->table('composite_pks')->drop()->save(); + $this->table('orders')->drop()->save(); + $this->table('products')->drop()->save(); + $this->table('special_pks')->drop()->save(); + $this->table('special_tags')->drop()->save(); + $this->table('users')->drop()->save(); } } diff --git a/tests/comparisons/Migration/pgsql/test_not_empty_snapshot_pgsql.php b/tests/comparisons/Migration/pgsql/test_not_empty_snapshot_pgsql.php index 600fd553..aff10645 100644 --- a/tests/comparisons/Migration/pgsql/test_not_empty_snapshot_pgsql.php +++ b/tests/comparisons/Migration/pgsql/test_not_empty_snapshot_pgsql.php @@ -312,7 +312,7 @@ public function down() ) ->dropForeignKey( 'product_id' - ); + )->save(); $this->table('orders') ->dropForeignKey( @@ -320,20 +320,20 @@ public function down() 'product_category', 'product_id', ] - ); + )->save(); $this->table('products') ->dropForeignKey( 'category_id' - ); + )->save(); - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('composite_pks'); - $this->dropTable('orders'); - $this->dropTable('products'); - $this->dropTable('special_pks'); - $this->dropTable('special_tags'); - $this->dropTable('users'); + $this->table('articles')->drop()->save(); + $this->table('categories')->drop()->save(); + $this->table('composite_pks')->drop()->save(); + $this->table('orders')->drop()->save(); + $this->table('products')->drop()->save(); + $this->table('special_pks')->drop()->save(); + $this->table('special_tags')->drop()->save(); + $this->table('users')->drop()->save(); } } diff --git a/tests/comparisons/Migration/pgsql/test_plugin_blog_pgsql.php b/tests/comparisons/Migration/pgsql/test_plugin_blog_pgsql.php index 2ca7b7c7..db74772c 100644 --- a/tests/comparisons/Migration/pgsql/test_plugin_blog_pgsql.php +++ b/tests/comparisons/Migration/pgsql/test_plugin_blog_pgsql.php @@ -144,8 +144,8 @@ public function down() 'product_id' ); - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('parts'); + $this->table('articles')->drop()->save(); + $this->table('categories')->drop()->save(); + $this->table('parts')->drop()->save(); } } diff --git a/tests/comparisons/Migration/sqlite/test_auto_id_disabled_snapshot_sqlite.php b/tests/comparisons/Migration/sqlite/test_auto_id_disabled_snapshot_sqlite.php index cd0b4ce7..5df06db6 100644 --- a/tests/comparisons/Migration/sqlite/test_auto_id_disabled_snapshot_sqlite.php +++ b/tests/comparisons/Migration/sqlite/test_auto_id_disabled_snapshot_sqlite.php @@ -359,7 +359,7 @@ public function down() ) ->dropForeignKey( 'product_id' - ); + )->save(); $this->table('orders') ->dropForeignKey( @@ -367,20 +367,20 @@ public function down() 'product_category', 'product_id', ] - ); + )->save(); $this->table('products') ->dropForeignKey( 'category_id' - ); + )->save(); - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('composite_pks'); - $this->dropTable('orders'); - $this->dropTable('products'); - $this->dropTable('special_pks'); - $this->dropTable('special_tags'); - $this->dropTable('users'); + $this->table('articles')->drop()->save(); + $this->table('categories')->drop()->save(); + $this->table('composite_pks')->drop()->save(); + $this->table('orders')->drop()->save(); + $this->table('products')->drop()->save(); + $this->table('special_pks')->drop()->save(); + $this->table('special_tags')->drop()->save(); + $this->table('users')->drop()->save(); } } diff --git a/tests/comparisons/Migration/sqlite/test_not_empty_snapshot_sqlite.php b/tests/comparisons/Migration/sqlite/test_not_empty_snapshot_sqlite.php index 601e3a3c..73b55c88 100644 --- a/tests/comparisons/Migration/sqlite/test_not_empty_snapshot_sqlite.php +++ b/tests/comparisons/Migration/sqlite/test_not_empty_snapshot_sqlite.php @@ -312,7 +312,7 @@ public function down() ) ->dropForeignKey( 'product_id' - ); + )->save(); $this->table('orders') ->dropForeignKey( @@ -320,20 +320,20 @@ public function down() 'product_category', 'product_id', ] - ); + )->save(); $this->table('products') ->dropForeignKey( 'category_id' - ); + )->save(); - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('composite_pks'); - $this->dropTable('orders'); - $this->dropTable('products'); - $this->dropTable('special_pks'); - $this->dropTable('special_tags'); - $this->dropTable('users'); + $this->table('articles')->drop()->save(); + $this->table('categories')->drop()->save(); + $this->table('composite_pks')->drop()->save(); + $this->table('orders')->drop()->save(); + $this->table('products')->drop()->save(); + $this->table('special_pks')->drop()->save(); + $this->table('special_tags')->drop()->save(); + $this->table('users')->drop()->save(); } } diff --git a/tests/comparisons/Migration/sqlite/test_plugin_blog_sqlite.php b/tests/comparisons/Migration/sqlite/test_plugin_blog_sqlite.php index ca482f1b..d50c3c2d 100644 --- a/tests/comparisons/Migration/sqlite/test_plugin_blog_sqlite.php +++ b/tests/comparisons/Migration/sqlite/test_plugin_blog_sqlite.php @@ -143,10 +143,10 @@ public function down() ) ->dropForeignKey( 'product_id' - ); + )->save(); - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('parts'); + $this->table('articles')->drop()->save(); + $this->table('categories')->drop()->save(); + $this->table('parts')->drop()->save(); } } diff --git a/tests/comparisons/Migration/test_auto_id_disabled_snapshot.php b/tests/comparisons/Migration/test_auto_id_disabled_snapshot.php index 9b59b59d..6e4d4138 100644 --- a/tests/comparisons/Migration/test_auto_id_disabled_snapshot.php +++ b/tests/comparisons/Migration/test_auto_id_disabled_snapshot.php @@ -360,7 +360,7 @@ public function down() ) ->dropForeignKey( 'product_id' - ); + )->save(); $this->table('orders') ->dropForeignKey( @@ -368,20 +368,20 @@ public function down() 'product_category', 'product_id', ] - ); + )->save(); $this->table('products') ->dropForeignKey( 'category_id' - ); + )->save(); - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('composite_pks'); - $this->dropTable('orders'); - $this->dropTable('products'); - $this->dropTable('special_pks'); - $this->dropTable('special_tags'); - $this->dropTable('users'); + $this->table('articles')->drop()->save(); + $this->table('categories')->drop()->save(); + $this->table('composite_pks')->drop()->save(); + $this->table('orders')->drop()->save(); + $this->table('products')->drop()->save(); + $this->table('special_pks')->drop()->save(); + $this->table('special_tags')->drop()->save(); + $this->table('users')->drop()->save(); } } diff --git a/tests/comparisons/Migration/test_auto_id_disabled_snapshot56.php b/tests/comparisons/Migration/test_auto_id_disabled_snapshot56.php index 47004e72..964cec95 100644 --- a/tests/comparisons/Migration/test_auto_id_disabled_snapshot56.php +++ b/tests/comparisons/Migration/test_auto_id_disabled_snapshot56.php @@ -361,7 +361,7 @@ public function down() ) ->dropForeignKey( 'product_id' - ); + )->save(); $this->table('orders') ->dropForeignKey( @@ -369,20 +369,20 @@ public function down() 'product_category', 'product_id', ] - ); + )->save(); $this->table('products') ->dropForeignKey( 'category_id' - ); + )->save(); - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('composite_pks'); - $this->dropTable('orders'); - $this->dropTable('products'); - $this->dropTable('special_pks'); - $this->dropTable('special_tags'); - $this->dropTable('users'); + $this->table('articles')->drop()->save(); + $this->table('categories')->drop()->save(); + $this->table('composite_pks')->drop()->save(); + $this->table('orders')->drop()->save(); + $this->table('products')->drop()->save(); + $this->table('special_pks')->drop()->save(); + $this->table('special_tags')->drop()->save(); + $this->table('users')->drop()->save(); } } diff --git a/tests/comparisons/Migration/test_not_empty_snapshot.php b/tests/comparisons/Migration/test_not_empty_snapshot.php index 1f75a314..a9bdbb66 100644 --- a/tests/comparisons/Migration/test_not_empty_snapshot.php +++ b/tests/comparisons/Migration/test_not_empty_snapshot.php @@ -313,7 +313,7 @@ public function down() ) ->dropForeignKey( 'product_id' - ); + )->save(); $this->table('orders') ->dropForeignKey( @@ -321,20 +321,20 @@ public function down() 'product_category', 'product_id', ] - ); + )->save(); $this->table('products') ->dropForeignKey( 'category_id' - ); + )->save(); - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('composite_pks'); - $this->dropTable('orders'); - $this->dropTable('products'); - $this->dropTable('special_pks'); - $this->dropTable('special_tags'); - $this->dropTable('users'); + $this->table('articles')->drop()->save(); + $this->table('categories')->drop()->save(); + $this->table('composite_pks')->drop()->save(); + $this->table('orders')->drop()->save(); + $this->table('products')->drop()->save(); + $this->table('special_pks')->drop()->save(); + $this->table('special_tags')->drop()->save(); + $this->table('users')->drop()->save(); } } diff --git a/tests/comparisons/Migration/test_not_empty_snapshot56.php b/tests/comparisons/Migration/test_not_empty_snapshot56.php index 4999c074..ae201434 100644 --- a/tests/comparisons/Migration/test_not_empty_snapshot56.php +++ b/tests/comparisons/Migration/test_not_empty_snapshot56.php @@ -314,7 +314,7 @@ public function down() ) ->dropForeignKey( 'product_id' - ); + )->save(); $this->table('orders') ->dropForeignKey( @@ -322,20 +322,20 @@ public function down() 'product_category', 'product_id', ] - ); + )->save(); $this->table('products') ->dropForeignKey( 'category_id' - ); + )->save(); - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('composite_pks'); - $this->dropTable('orders'); - $this->dropTable('products'); - $this->dropTable('special_pks'); - $this->dropTable('special_tags'); - $this->dropTable('users'); + $this->table('articles')->drop()->save(); + $this->table('categories')->drop()->save(); + $this->table('composite_pks')->drop()->save(); + $this->table('orders')->drop()->save(); + $this->table('products')->drop()->save(); + $this->table('special_pks')->drop()->save(); + $this->table('special_tags')->drop()->save(); + $this->table('users')->drop()->save(); } } diff --git a/tests/comparisons/Migration/test_plugin_blog.php b/tests/comparisons/Migration/test_plugin_blog.php index d666180f..a9f2f841 100644 --- a/tests/comparisons/Migration/test_plugin_blog.php +++ b/tests/comparisons/Migration/test_plugin_blog.php @@ -169,10 +169,10 @@ public function down() ) ->dropForeignKey( 'product_id' - ); + )->save(); - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('parts'); + $this->table('articles')->drop()->save(); + $this->table('categories')->drop()->save(); + $this->table('parts')->drop()->save(); } } diff --git a/tests/comparisons/Migration/test_plugin_blog56.php b/tests/comparisons/Migration/test_plugin_blog56.php index af58fb8a..8d02ab44 100644 --- a/tests/comparisons/Migration/test_plugin_blog56.php +++ b/tests/comparisons/Migration/test_plugin_blog56.php @@ -169,10 +169,10 @@ public function down() ) ->dropForeignKey( 'product_id' - ); + )->save(); - $this->dropTable('articles'); - $this->dropTable('categories'); - $this->dropTable('parts'); + $this->table('articles')->drop()->save(); + $this->table('categories')->drop()->save(); + $this->table('parts')->drop()->save(); } } diff --git a/tests/test_app/config/MigrationsDiff/20151218183450_CreateArticles.php b/tests/test_app/config/MigrationsDiff/20151218183450_CreateArticles.php index a12c31a1..57e746ff 100644 --- a/tests/test_app/config/MigrationsDiff/20151218183450_CreateArticles.php +++ b/tests/test_app/config/MigrationsDiff/20151218183450_CreateArticles.php @@ -3,7 +3,7 @@ class CreateArticles extends AbstractMigration { - public function up() + public function change() { $table = $this->table('articles'); $table @@ -24,8 +24,7 @@ public function up() 'default' => null, 'limit' => null, 'null' => false, - ]) - ->create(); + ]); $table->addIndex([ 'rating', @@ -33,11 +32,6 @@ public function up() 'name' => 'rating_index', 'unique' => false, ]) - ->update(); - } - - public function down() - { - $this->dropTable('articles'); + ->create(); } } diff --git a/tests/test_app/config/MigrationsDiffAddRemove/20151218183450_CreateArticlesAddRemove.php b/tests/test_app/config/MigrationsDiffAddRemove/20151218183450_CreateArticlesAddRemove.php index 0ce6b06a..8c9df1f5 100644 --- a/tests/test_app/config/MigrationsDiffAddRemove/20151218183450_CreateArticlesAddRemove.php +++ b/tests/test_app/config/MigrationsDiffAddRemove/20151218183450_CreateArticlesAddRemove.php @@ -3,7 +3,7 @@ class CreateArticlesAddRemove extends AbstractMigration { - public function up() + public function change() { $table = $this->table('articles'); $table @@ -18,9 +18,4 @@ public function up() ]) ->create(); } - - public function down() - { - $this->dropTable('articles'); - } } diff --git a/tests/test_app/config/MigrationsDiffSimple/20151218183450_CreateArticlesSimple.php b/tests/test_app/config/MigrationsDiffSimple/20151218183450_CreateArticlesSimple.php index 8690f9b1..a676d8b3 100644 --- a/tests/test_app/config/MigrationsDiffSimple/20151218183450_CreateArticlesSimple.php +++ b/tests/test_app/config/MigrationsDiffSimple/20151218183450_CreateArticlesSimple.php @@ -3,7 +3,7 @@ class CreateArticlesSimple extends AbstractMigration { - public function up() + public function change() { $table = $this->table('articles'); $table @@ -24,8 +24,7 @@ public function up() 'default' => null, 'limit' => null, 'null' => false, - ]) - ->create(); + ]); $table->addIndex([ 'rating', @@ -33,11 +32,6 @@ public function up() 'name' => 'rating_index', 'unique' => false, ]) - ->update(); - } - - public function down() - { - $this->dropTable('articles'); + ->create(); } } diff --git a/tests/test_app/config/TestsMigrations/20150704160200_create_numbers_table.php b/tests/test_app/config/TestsMigrations/20150704160200_create_numbers_table.php index 7a62be41..78a3c1bb 100644 --- a/tests/test_app/config/TestsMigrations/20150704160200_create_numbers_table.php +++ b/tests/test_app/config/TestsMigrations/20150704160200_create_numbers_table.php @@ -4,7 +4,7 @@ class CreateNumbersTable extends AbstractMigration { - public function up() + public function change() { $table = $this->table('numbers', ['collation' => 'utf8_bin']); $table @@ -15,9 +15,4 @@ public function up() ]) ->create(); } - - public function down() - { - $this->dropTable('numbers'); - } } diff --git a/tests/test_app/config/TestsMigrations/20150826191400_create_letters_table.php b/tests/test_app/config/TestsMigrations/20150826191400_create_letters_table.php index 0397d6c1..c982c2b4 100644 --- a/tests/test_app/config/TestsMigrations/20150826191400_create_letters_table.php +++ b/tests/test_app/config/TestsMigrations/20150826191400_create_letters_table.php @@ -6,7 +6,7 @@ class CreateLettersTable extends AbstractMigration public $autoId = false; - public function up() + public function change() { $table = $this->table('letters'); $table @@ -22,9 +22,4 @@ public function up() ]) ->create(); } - - public function down() - { - $this->dropTable('letters'); - } }