From fb998667a77cd27a8ba611b85ad3e87c3fac9fe0 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Tue, 23 Feb 2021 18:12:44 -0500 Subject: [PATCH 1/4] Allow specifying migration_table setting for an adapter Signed-off-by: Matthew Peveler --- src/Phinx/Config/Config.php | 7 +++++-- src/Phinx/Db/Adapter/AbstractAdapter.php | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Phinx/Config/Config.php b/src/Phinx/Config/Config.php index d6b055a5a..04d647abc 100644 --- a/src/Phinx/Config/Config.php +++ b/src/Phinx/Config/Config.php @@ -168,8 +168,11 @@ public function getEnvironment($name) $environments = $this->getEnvironments(); if (isset($environments[$name])) { - if (isset($this->values['environments']['default_migration_table'])) { - $environments[$name]['default_migration_table'] = + if ( + isset($this->values['environments']['default_migration_table']) + && !isset($environments[$name]['migration_table']) + ) { + $environments[$name]['migration_table'] = $this->values['environments']['default_migration_table']; } diff --git a/src/Phinx/Db/Adapter/AbstractAdapter.php b/src/Phinx/Db/Adapter/AbstractAdapter.php index 247b6c1ff..9a958864f 100644 --- a/src/Phinx/Db/Adapter/AbstractAdapter.php +++ b/src/Phinx/Db/Adapter/AbstractAdapter.php @@ -77,7 +77,14 @@ public function setOptions(array $options) $this->options = $options; if (isset($options['default_migration_table'])) { - $this->setSchemaTableName($options['default_migration_table']); + trigger_error('The default_migration_table setting for adapter has been deprecated since 0.13.0. Use `migration_table` instead.', E_USER_DEPRECATED); + if (!isset($options['migration_table'])) { + $options['migration_table'] = $options['default_migration_table']; + } + } + + if (isset($options['migration_table'])) { + $this->setSchemaTableName($options['migration_table']); } if (isset($options['data_domain'])) { From a28ede3b51bece36c94d0ff6a710da0a077db6ff Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Tue, 23 Feb 2021 18:18:36 -0500 Subject: [PATCH 2/4] fix failing test Signed-off-by: Matthew Peveler --- tests/Phinx/Db/Adapter/PdoAdapterTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Phinx/Db/Adapter/PdoAdapterTest.php b/tests/Phinx/Db/Adapter/PdoAdapterTest.php index 5de3aa705..2aa6e25be 100644 --- a/tests/Phinx/Db/Adapter/PdoAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PdoAdapterTest.php @@ -69,6 +69,16 @@ public function testOptionsSetConnection() public function testOptionsSetSchemaTableName() { $this->assertEquals('phinxlog', $this->adapter->getSchemaTableName()); + $this->adapter->setOptions(['migration_table' => 'schema_table_test']); + $this->assertEquals('schema_table_test', $this->adapter->getSchemaTableName()); + } + + public function testOptionsSetDefaultMigrationTableThrowsDeprecation() + { + $this->assertEquals('phinxlog', $this->adapter->getSchemaTableName()); + + $this->expectDeprecation(); + $this->expectExceptionMessage('The default_migration_table setting for adapter has been deprecated since 0.13.0. Use `migration_table` instead.'); $this->adapter->setOptions(['default_migration_table' => 'schema_table_test']); $this->assertEquals('schema_table_test', $this->adapter->getSchemaTableName()); } From 0fd25b9cf2f14d95e668b45ca3fe1b7ccaba24a0 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Tue, 23 Feb 2021 19:01:01 -0500 Subject: [PATCH 3/4] add config testcase Signed-off-by: Matthew Peveler --- tests/Phinx/Config/ConfigTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Phinx/Config/ConfigTest.php b/tests/Phinx/Config/ConfigTest.php index 435c7b5ff..afd589dd1 100644 --- a/tests/Phinx/Config/ConfigTest.php +++ b/tests/Phinx/Config/ConfigTest.php @@ -134,6 +134,16 @@ public function testDefaultDatabaseThrowsDeprecatedNotice() $config->getDefaultEnvironment(); } + public function testEnvironmentHasMigrationTable() + { + $configArray = $this->getConfigArray(); + $configArray['environments']['production']['migration_table'] = 'test_table'; + $config = new Config($configArray); + + $this->assertSame('phinxlog', $config->getEnvironment('testing')['migration_table']); + $this->assertSame('test_table', $config->getEnvironment('production')['migration_table']); + } + /** * @covers \Phinx\Config\Config::offsetGet * @covers \Phinx\Config\Config::offsetSet From 31365ce6cb9c7e033d3bc8b8f700d48e43a4d585 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Tue, 23 Feb 2021 19:06:35 -0500 Subject: [PATCH 4/4] amend docs Signed-off-by: Matthew Peveler --- docs/en/configuration.rst | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/en/configuration.rst b/docs/en/configuration.rst index 9243a2641..85fb12c91 100644 --- a/docs/en/configuration.rst +++ b/docs/en/configuration.rst @@ -191,7 +191,8 @@ Migration Table To keep track of the migration statuses for an environment, phinx creates a table to store this information. You can customize where this table -is created by configuring ``default_migration_table``: +is created by configuring ``default_migration_table`` to be used as default +for all environments: .. code-block:: yaml @@ -204,6 +205,24 @@ with a period separator (``.``). For example, ``phinx.log`` will create the table ``log`` in the ``phinx`` schema instead of ``phinxlog`` in the ``public`` (default) schema. +You may also specify the ``migration_table`` on a per environment basis. +Any environment that does not have a ``migration_table`` specified will +fallback to using the ``default_migration_table`` that is defined at the +top level. An example of how you might use this is as follows: + +.. code-block:: yaml + + environment: + default_migration_table: phinxlog + development: + migration_table: phinxlog_dev + # rest of the development settings + production: + # rest of the production settings + +In the above example, ``development`` will look to the ``phinxlog_dev`` +table for migration statues while ``production`` will use ``phinxlog``. + Table Prefix and Suffix -----------------------