Skip to content

Commit

Permalink
Merge pull request #1993 from MasterOdin/0.next-merge
Browse files Browse the repository at this point in the history
Merge branch 'master' into 0.next
  • Loading branch information
dereuromark authored Jun 17, 2021
2 parents b6ae3e2 + b1ef677 commit 986a355
Show file tree
Hide file tree
Showing 108 changed files with 549 additions and 810 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: composer
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
15 changes: 13 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,22 @@ jobs:
if: matrix.php-version == '7.4' && matrix.db-type == 'mysql'
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run PHPUnit
- name: Setup Database
run: |
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE phinx;'; fi
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then
n=0
until [ "$n" -ge 5 ]
do
mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE phinx;' && break || :
n=$((n+1))
sleep 2
done
mysql -h 127.0.0.1 -u root -proot -D phinx -e 'SELECT 1;'
fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then psql -c 'CREATE DATABASE phinx;' postgresql://postgres:postgres@127.0.0.1; fi
- name: Run PHPUnit
run: |
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export SQLITE_DSN='sqlite:///phinx'; fi
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export MYSQL_DSN='mysql://root:root@127.0.0.1/phinx'; fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export PGSQL_DSN='pgsql://postgres:postgres@127.0.0.1/phinx'; fi
Expand Down
4 changes: 2 additions & 2 deletions app/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
}

// Get the environment and target version parameters.
$env = isset($_GET['e']) ? $_GET['e'] : null;
$target = isset($_GET['t']) ? $_GET['t'] : null;
$env = $_GET['e'] ?? null;
$target = $_GET['t'] ?? null;

// Check if debugging is enabled.
$debug = !empty($_GET['debug']) && filter_var($_GET['debug'], FILTER_VALIDATE_BOOLEAN);
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"require": {
"php": ">=7.2",
"cakephp/database": "^4.0",
"psr/container": "^1.0",
"psr/container": "^1.0 || ^2.0",
"symfony/console": "^3.4|^4.0|^5.0",
"symfony/config": "^3.4|^4.0|^5.0"
},
Expand All @@ -36,7 +36,7 @@
"ext-pdo": "*",
"phpunit/phpunit": "^8.5|^9.3",
"sebastian/comparator": ">=1.2.3",
"cakephp/cakephp-codesniffer": "^3.0",
"cakephp/cakephp-codesniffer": "^4.0",
"symfony/yaml": "^3.4|^4.0|^5.0"
},
"autoload": {
Expand Down
10 changes: 10 additions & 0 deletions docs/en/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,16 @@ For example, to set the above example options:
By default, the only attribute that Phinx sets is ``\PDO::ATTR_ERRMODE`` to ``PDO::ERRMODE_EXCEPTION``. It is
not recommended to override this.

MySQL
`````````````````

The MySQL adapter has an unfortunate limitation in that it certain actions causes an
`implicit commit <https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html>`_ regardless of transaction
state. Notably this list includes ``CREATE TABLE``, ``ALTER TABLE``, and ``DROP TABLE``, which are the most
common operations that Phinx will run. This means that unlike other adapters which will attempt to gracefully
rollback a transaction on a failed migration, if a migration fails for MySQL, it may leave your DB in a partially
migrated state.

SQLite
`````````````````

Expand Down
15 changes: 12 additions & 3 deletions docs/en/migrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,12 @@ update set an action to be triggered when the row is updated (use with ``CURRE
timezone enable or disable the ``with time zone`` option for ``time`` and ``timestamp`` columns *(only applies to Postgres)*
======== ===========

You can add ``created_at`` and ``updated_at`` timestamps to a table using the ``addTimestamps()`` method. This method also
allows you to supply alternative names. The optional third argument allows you to change the ``timezone`` option for the
columns being added. Additionally, you can use the ``addTimestampsWithTimezone()`` method, which is an alias to
You can add ``created_at`` and ``updated_at`` timestamps to a table using the ``addTimestamps()`` method. This method accepts
three arguments, where the first two allow setting alternative names for the columns while the third argument allows you to
enable the ``timezone`` option for the columns. The defaults for these arguments are ``created_at``, ``updated_at``, and ``true``
respectively. For the first and second argument, if you provide ``null``, then the default name will be used, and if you provide
``false``, then that column will not be created. Please note that attempting to set both to ``false`` will throw a
``\RuntimeException``. Additionally, you can use the ``addTimestampsWithTimezone()`` method, which is an alias to
``addTimestamps()`` that will always set the third argument to ``true`` (see examples below). The ``created_at`` column will
have a default set to ``CURRENT_TIMESTAMP``. For MySQL only, ``update_at`` column will have update set to
``CURRENT_TIMESTAMP``.
Expand Down Expand Up @@ -842,6 +845,12 @@ have a default set to ``CURRENT_TIMESTAMP``. For MySQL only, ``update_at`` colum
// The two lines below do the same, the second one is simply cleaner.
$table = $this->table('books')->addTimestamps(null, 'amended_at', true)->create();
$table = $this->table('users')->addTimestampsWithTimezone(null, 'amended_at')->create();
// Only add the created_at column to the table
$table = $this->table('books')->addTimestamps(null, false);
// Only add the updated_at column to the table
$table = $this->table('users')->addTimestamps(false);
// Note, setting both false will throw a \RuntimeError
}
}
Expand Down
6 changes: 6 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer"/>

<rule ref="CakePHP"/>

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<severity>0</severity>
</rule>

<exclude-pattern>*_files*</exclude-pattern>
</ruleset>
33 changes: 8 additions & 25 deletions src/Phinx/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public function __construct(array $configArray, $configFilePath = null)
* Create a new instance of the config class using a Yaml file path.
*
* @param string $configFilePath Path to the Yaml File
*
* @throws \RuntimeException
*
* @return \Phinx\Config\Config
*/
public static function fromYaml($configFilePath)
Expand Down Expand Up @@ -89,16 +87,14 @@ public static function fromYaml($configFilePath)
* Create a new instance of the config class using a JSON file path.
*
* @param string $configFilePath Path to the JSON File
*
* @throws \RuntimeException
*
* @return \Phinx\Config\Config
*/
public static function fromJson($configFilePath)
{
if (!function_exists('json_decode')) {
// @codeCoverageIgnoreStart
throw new RuntimeException("Need to install JSON PHP extension to use JSON config");
throw new RuntimeException('Need to install JSON PHP extension to use JSON config');
// @codeCoverageIgnoreEnd
}

Expand All @@ -117,16 +113,14 @@ public static function fromJson($configFilePath)
* Create a new instance of the config class using a PHP file path.
*
* @param string $configFilePath Path to the PHP File
*
* @throws \RuntimeException
*
* @return \Phinx\Config\Config
*/
public static function fromPhp($configFilePath)
{
ob_start();
/** @noinspection PhpIncludeInspection */
$configArray = include($configFilePath);
$configArray = include $configFilePath;

// Hide console output
ob_end_clean();
Expand Down Expand Up @@ -195,7 +189,7 @@ public function getEnvironment($name)
*/
public function hasEnvironment($name)
{
return ($this->getEnvironment($name) !== null);
return $this->getEnvironment($name) !== null;
}

/**
Expand Down Expand Up @@ -271,7 +265,6 @@ public function getConfigFilePath()

/**
* @inheritDoc
*
* @throws \UnexpectedValueException
*/
public function getMigrationPaths()
Expand All @@ -291,7 +284,6 @@ public function getMigrationPaths()
* Gets the base class name for migrations.
*
* @param bool $dropNamespace Return the base migration class name without the namespace.
*
* @return string
*/
public function getMigrationBaseClassName($dropNamespace = true)
Expand All @@ -303,7 +295,6 @@ public function getMigrationBaseClassName($dropNamespace = true)

/**
* @inheritDoc
*
* @throws \UnexpectedValueException
*/
public function getSeedPaths()
Expand Down Expand Up @@ -428,7 +419,6 @@ public function getBootstrapFile()
* Replace tokens in the specified array.
*
* @param array $arr Array to replace
*
* @return array
*/
protected function replaceTokens(array $arr)
Expand Down Expand Up @@ -457,7 +447,6 @@ protected function replaceTokens(array $arr)
*
* @param array $arr Array to recurse
* @param string[] $tokens Array of tokens to search for
*
* @return array
*/
protected function recurseArrayForTokens($arr, $tokens)
Expand Down Expand Up @@ -485,7 +474,6 @@ protected function recurseArrayForTokens($arr, $tokens)
* Parse a database-agnostic DSN into individual options.
*
* @param array $options Options
*
* @return array
*/
protected function parseAgnosticDsn(array $options)
Expand All @@ -503,9 +491,8 @@ protected function parseAgnosticDsn(array $options)
/**
* {@inheritDoc}
*
* @param mixed $id
* @param mixed $value
*
* @param mixed $id ID
* @param mixed $value Value
* @return void
*/
public function offsetSet($id, $value)
Expand All @@ -516,10 +503,8 @@ public function offsetSet($id, $value)
/**
* {@inheritDoc}
*
* @param mixed $id
*
* @param mixed $id ID
* @throws \InvalidArgumentException
*
* @return mixed
*/
public function offsetGet($id)
Expand All @@ -534,8 +519,7 @@ public function offsetGet($id)
/**
* {@inheritDoc}
*
* @param mixed $id
*
* @param mixed $id ID
* @return bool
*/
public function offsetExists($id)
Expand All @@ -546,8 +530,7 @@ public function offsetExists($id)
/**
* {@inheritDoc}
*
* @param mixed $id
*
* @param mixed $id ID
* @return void
*/
public function offsetUnset($id)
Expand Down
5 changes: 0 additions & 5 deletions src/Phinx/Config/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function getEnvironments();
* doesn't exist.
*
* @param string $name Environment Name
*
* @return array|null
*/
public function getEnvironment($name);
Expand All @@ -42,7 +41,6 @@ public function getEnvironment($name);
* Does the specified environment exist in the configuration file?
*
* @param string $name Environment Name
*
* @return bool
*/
public function hasEnvironment($name);
Expand All @@ -51,7 +49,6 @@ public function hasEnvironment($name);
* Gets the default environment name.
*
* @throws \RuntimeException
*
* @return string
*/
public function getDefaultEnvironment();
Expand All @@ -60,7 +57,6 @@ public function getDefaultEnvironment();
* Get the aliased value from a supplied alias.
*
* @param string $alias Alias
*
* @return string|null
*/
public function getAlias($alias);
Expand Down Expand Up @@ -146,7 +142,6 @@ public function getBootstrapFile();
* Gets the base class name for migrations.
*
* @param bool $dropNamespace Return the base migration class name without the namespace.
*
* @return string
*/
public function getMigrationBaseClassName($dropNamespace = true);
Expand Down
2 changes: 0 additions & 2 deletions src/Phinx/Config/NamespaceAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ interface NamespaceAwareInterface
* Get Migration Namespace associated with path.
*
* @param string $path Path
*
* @return string|null
*/
public function getMigrationNamespaceByPath($path);
Expand All @@ -28,7 +27,6 @@ public function getMigrationNamespaceByPath($path);
* Get Seed Namespace associated with path.
*
* @param string $path Path
*
* @return string|null
*/
public function getSeedNamespaceByPath($path);
Expand Down
3 changes: 0 additions & 3 deletions src/Phinx/Config/NamespaceAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ abstract public function getSeedPaths();
*
* @param string $needle Needle
* @param string[] $haystack Haystack
*
* @return string|null
*/
protected function searchNamespace($needle, $haystack)
Expand All @@ -51,7 +50,6 @@ protected function searchNamespace($needle, $haystack)
* Get Migration Namespace associated with path.
*
* @param string $path Path
*
* @return string|null
*/
public function getMigrationNamespaceByPath($path)
Expand All @@ -65,7 +63,6 @@ public function getMigrationNamespaceByPath($path)
* Get Seed Namespace associated with path.
*
* @param string $path Path
*
* @return string|null
*/
public function getSeedNamespaceByPath($path)
Expand Down
Loading

0 comments on commit 986a355

Please sign in to comment.