Skip to content

Commit

Permalink
Merge pull request #1474 from doctrine/3.8.x
Browse files Browse the repository at this point in the history
Merge 3.8.x up into 3.9.x
  • Loading branch information
greg0ire authored Nov 29, 2024
2 parents 610092c + 1065fbe commit 3592645
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 42 deletions.
6 changes: 6 additions & 0 deletions .doctrine-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"slug": "migrations",
"docsSlug": "doctrine-migrations",
"versions": [
{
"name": "4.0",
"branchName": "4.0.x",
"slug": "4.0",
"upcoming": true
},
{
"name": "3.9",
"branchName": "3.9.x",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ on:
jobs:
coding-standards:
name: "Coding Standards"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@5.0.1"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@6.0.0"
2 changes: 1 addition & 1 deletion .github/workflows/composer-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ on:
jobs:
composer-lint:
name: "Composer Lint"
uses: "doctrine/.github/.github/workflows/composer-lint.yml@5.0.1"
uses: "doctrine/.github/.github/workflows/composer-lint.yml@6.0.0"
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
path: "reports"

- name: "Upload to Codecov"
uses: "codecov/codecov-action@v4"
uses: "codecov/codecov-action@v5"
with:
directory: reports
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-on-milestone-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
release:
name: "Git tag, release & create merge-up PR"
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@5.0.1"
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@6.0.0"
secrets:
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
Expand Down
46 changes: 23 additions & 23 deletions docs/en/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,27 @@ Please note that if you want to use the YAML configuration option, you will need
Here are details about what each configuration option does:

+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
| Name | Required | Default | Description |
+============================+============+==============================+==================================================================================+
| migrations_paths<string, string> | yes | null | The PHP namespace your migration classes are located under and the path to a directory where to look for migration classes. |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
| table_storage | no | | Used by doctrine migrations to track the currently executed migrations |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
| all_or_nothing | no | false | Whether or not to wrap multiple migrations in a single transaction. |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
| transactional | no | true | Whether or not to wrap migrations in a single transaction. |
| | | | |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
| migrations | no | [] | Manually specify the array of migration versions instead of finding migrations. |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
| check_database_platform | no | true | Whether to add a database platform check at the beginning of the generated code. |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
| organize_migrations | no | ``none`` | Whether to organize migration classes under year (``year``) or year and month (``year_and_month``) subdirectories. |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
| connection | no | null | The named connection to use (available only when ConnectionRegistryConnection is used). |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
| em | no | null | The named entity manager to use (available only when ManagerRegistryEntityManager is used). |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
+----------------------------------+----------+----------+-----------------------------------------------------------------------------------------------------------------------------+
| Name | Required | Default | Description |
+==================================+==========+==========+=============================================================================================================================+
| migrations_paths<string, string> | yes | null | The PHP namespace your migration classes are located under and the path to a directory where to look for migration classes. |
+----------------------------------+----------+----------+-----------------------------------------------------------------------------------------------------------------------------+
| table_storage | no | | Used by doctrine migrations to track the currently executed migrations |
+----------------------------------+----------+----------+-----------------------------------------------------------------------------------------------------------------------------+
| all_or_nothing | no | false | Whether or not to wrap multiple migrations in a single transaction. |
+----------------------------------+----------+----------+-----------------------------------------------------------------------------------------------------------------------------+
| transactional | no | true | Whether or not to wrap migrations in a single transaction. |
+----------------------------------+----------+----------+-----------------------------------------------------------------------------------------------------------------------------+
| migrations | no | [] | Manually specify the array of migration versions instead of finding migrations. |
+----------------------------------+----------+----------+-----------------------------------------------------------------------------------------------------------------------------+
| check_database_platform | no | true | Whether to add a database platform check at the beginning of the generated code. |
+----------------------------------+----------+----------+-----------------------------------------------------------------------------------------------------------------------------+
| organize_migrations | no | ``none`` | Whether to organize migration classes under year (``year``) or year and month (``year_and_month``) subdirectories. |
+----------------------------------+----------+----------+-----------------------------------------------------------------------------------------------------------------------------+
| connection | no | null | The named connection to use (available only when ConnectionRegistryConnection is used). |
+----------------------------------+----------+----------+-----------------------------------------------------------------------------------------------------------------------------+
| em | no | null | The named entity manager to use (available only when ManagerRegistryEntityManager is used). |
+----------------------------------+----------+----------+-----------------------------------------------------------------------------------------------------------------------------+


Here the possible options for ``table_storage``:
Expand All @@ -164,7 +163,7 @@ Here the possible options for ``table_storage``:
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
| version_column_name | no | version | The name of the column which stores the version name. |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
| version_column_length | no | 191 | The length of the column which stores the version name. |
| version_column_length | no | 191 | The length of the column which stores the version name. |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
| executed_at_column_name | no | executed_at | The name of the column which stores the date that a migration was executed. |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
Expand Down Expand Up @@ -378,3 +377,4 @@ Make sure to create the directory where your ORM entities will be located:
$ mkdir lib/MyProject/Entities
:ref:`Next Chapter: Migration Classes <migration-classes>`

13 changes: 13 additions & 0 deletions src/Generator/DiffGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Doctrine\Migrations\Generator\Exception\NoChangesDetected;
use Doctrine\Migrations\Provider\SchemaProvider;

use function method_exists;
use function preg_match;
use function strpos;
use function substr;
Expand Down Expand Up @@ -63,6 +64,18 @@ static function ($assetName) use ($filterExpression) {

$toSchema = $this->createToSchema();

// prior to DBAL 4.0, the schema name was set to the first element in the search path,
// which is not necessarily the default schema name
if (
! method_exists($this->schemaManager, 'getSchemaSearchPaths')
&& $this->platform->supportsSchemas()
) {
$defaultNamespace = $toSchema->getName();
if ($defaultNamespace !== '') {
$toSchema->createNamespace($defaultNamespace);
}
}

$comparator = $this->schemaManager->createComparator();

$upSql = $this->platform->getAlterSchemaSQL($comparator->compareSchemas($fromSchema, $toSchema));
Expand Down
11 changes: 6 additions & 5 deletions src/Metadata/Storage/TableMetadataStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,11 @@ private function updateMigratedVersionsFromV1orV2toV3(): void

private function isAlreadyV3Format(AvailableMigration $availableMigration, ExecutedMigration $executedMigration): bool
{
return strpos(
(string) $availableMigration->getVersion(),
(string) $executedMigration->getVersion(),
) !== strlen((string) $availableMigration->getVersion()) -
strlen((string) $executedMigration->getVersion());
return (string) $availableMigration->getVersion() === (string) $executedMigration->getVersion()
|| strpos(
(string) $availableMigration->getVersion(),
(string) $executedMigration->getVersion(),
) !== strlen((string) $availableMigration->getVersion()) -
strlen((string) $executedMigration->getVersion());
}
}
7 changes: 3 additions & 4 deletions src/Tools/Console/Command/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ protected function execute(
return 3;
}

$fqcn = $this->getDependencyFactory()->getClassNameGenerator()->generateClassName($namespace);

$fqcn = $this->getDependencyFactory()->getClassNameGenerator()->generateClassName($namespace);
$diffGenerator = $this->getDependencyFactory()->getDiffGenerator();

try {
Expand All @@ -154,12 +153,12 @@ protected function execute(
sprintf('Generated new migration class to "<info>%s</info>"', $path),
'',
sprintf(
'To run just this migration for testing purposes, you can use <info>migrations:execute --up \'%s\'</info>',
'To run just this migration for testing purposes, you can use <info>migrations:execute --up "%s"</info>',
addslashes($fqcn),
),
'',
sprintf(
'To revert the migration you can use <info>migrations:execute --down \'%s\'</info>',
'To revert the migration you can use <info>migrations:execute --down "%s"</info>',
addslashes($fqcn),
),
'',
Expand Down
4 changes: 2 additions & 2 deletions src/Tools/Console/Command/DumpSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ public function execute(
sprintf('Dumped your schema to a new migration class at "<info>%s</info>"', $path),
'',
sprintf(
'To run just this migration for testing purposes, you can use <info>migrations:execute --up \'%s\'</info>',
'To run just this migration for testing purposes, you can use <info>migrations:execute --up "%s"</info>',
addslashes($fqcn),
),
'',
sprintf(
'To revert the migration you can use <info>migrations:execute --down \'%s\'</info>',
'To revert the migration you can use <info>migrations:execute --down "%s"</info>',
addslashes($fqcn),
),
'',
Expand Down
21 changes: 21 additions & 0 deletions tests/Metadata/Storage/TableMetadataStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
use Doctrine\DBAL\Types\IntegerType;
use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\Migrations\Exception\MetadataStorageError;
use Doctrine\Migrations\Metadata\AvailableMigration;
use Doctrine\Migrations\Metadata\ExecutedMigration;
use Doctrine\Migrations\Metadata\Storage\TableMetadataStorage;
use Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration;
use Doctrine\Migrations\Version\AlphabeticalComparator;
Expand All @@ -27,6 +30,7 @@
use Doctrine\Migrations\Version\Version;
use PHPUnit\Framework\TestCase;
use Psr\Log\Test\TestLogger;
use ReflectionClass;

use function sprintf;

Expand Down Expand Up @@ -400,4 +404,21 @@ public function testGetSql(): void

self::assertCount(0, $this->connection->fetchAllAssociative($sql));
}

public function testIsAlreadyV3FormatDoesntMissTheSameVersions(): void
{
$availableMigration = new AvailableMigration(
new Version('Foo\\Version1234'),
$this->createMock(AbstractMigration::class),
);
$executedMigrationV3 = new ExecutedMigration(new Version('Foo\\Version1234'));
$executedMigrationOlder = new ExecutedMigration(new Version('Version1234'));

$reflection = new ReflectionClass(TableMetadataStorage::class);
$method = $reflection->getMethod('isAlreadyV3Format');
$method->setAccessible(true);

self::assertTrue($method->invokeArgs($this->storage, [$availableMigration, $executedMigrationV3]));
self::assertFalse($method->invokeArgs($this->storage, [$availableMigration, $executedMigrationOlder]));
}
}
4 changes: 2 additions & 2 deletions tests/Tools/Console/Command/DiffCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public function testExecute(): void
self::assertSame([
'Generated new migration class to "/path/to/migration.php"',
'',
'To run just this migration for testing purposes, you can use migrations:execute --up \'FooNs\\\\Version1234\'',
'To run just this migration for testing purposes, you can use migrations:execute --up "FooNs\\\\Version1234"',
'',
'To revert the migration you can use migrations:execute --down \'FooNs\\\\Version1234\'',
'To revert the migration you can use migrations:execute --down "FooNs\\\\Version1234"',
], array_map(trim(...), explode("\n", trim($output))));
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Tools/Console/Command/DumpSchemaCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public function testExecute(): void
[
'Dumped your schema to a new migration class at ""',
'',
'To run just this migration for testing purposes, you can use migrations:execute --up \'FooNs\\\\Version1234\'',
'To run just this migration for testing purposes, you can use migrations:execute --up "FooNs\\\\Version1234"',
'',
'To revert the migration you can use migrations:execute --down \'FooNs\\\\Version1234\'',
'To revert the migration you can use migrations:execute --down "FooNs\\\\Version1234"',
'',
'To use this as a rollup migration you can use the migrations:rollup command.',
],
Expand Down

0 comments on commit 3592645

Please sign in to comment.