Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to generate multiple database migrations #6913

Draft
wants to merge 6 commits into
base: 3.0
Choose a base branch
from

Conversation

alexander-schranz
Copy link
Member

@alexander-schranz alexander-schranz commented Nov 22, 2022

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets fixes #4406
Related issues/PRs #
License MIT
Documentation PR sulu/sulu-docs#

What's in this PR?

Add command to generate multiple database migrations

Why?

To simplify the process of Sulu updates whatever database is used

After some discussion about the update process with @luca-rath I thought I hack together some prototype how we could easily generate doctrine migrations for different databases (postgresql, mysql, mariadb)..

Example Usage

cd src/Sulu/Bundle/MigrationBundle/Resources/docker/
docker compose up

bin/console sulu:migration:migration-diff

To Do

Even this is a feature for 2.6 all migration files between minor version jumps should be there own Version...php file so from whaterver 2.x version to 2.6 somebody is jumping they can directly use the doctrine migrations.

All migrations before 2.6 need first a check if they really need to be executed, as a project itself could already that field in a custom migration added.

@alexander-schranz alexander-schranz added the Feature New functionality not yet included in Sulu label Nov 22, 2022
Comment on lines +125 to +136
private function replaceAbortWithSkip(): void
{
$finder = new Finder();
$finder->files()->in(\dirname(__DIR__) . '/Migrations')->name('Version*.php');

foreach ($finder as $file) {
\file_put_contents(
$file->getPathname(),
\str_replace('abortIf', 'skipIf', $file->getContents())
);
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be required as we should make sure that PostgreSQL, MySQL and MariaDB migrations life each in an own directory. And only the directory which is relevant is really loaded for the migrations. As skipIf migrations will trigger are a warning message in the doctrine migration command always, which we should avoid.

Comment on lines +22 to +27
// this up() migration is auto-generated, please modify it to your needs
$this->skipIf(
!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySQL80Platform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySQL80Platform'."
);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just example migration file which should be replaced in future.

Comment on lines +22 to +26
// this up() migration is auto-generated, please modify it to your needs
$this->skipIf(
!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\PostgreSQL100Platform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\PostgreSQL100Platform'."
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just example migration file which should be replaced in future into more splitted files.

Comment on lines +22 to +26
// this up() migration is auto-generated, please modify it to your needs
$this->skipIf(
!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MariaDb1027Platform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MariaDb1027Platform'."
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just example migration file which should be replaced in future into more splitted files.

@stefantalen
Copy link

Any updates on this? 🙂

@alexander-schranz alexander-schranz changed the base branch from 2.4 to 3.0 May 2, 2024 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New functionality not yet included in Sulu
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants