-
Notifications
You must be signed in to change notification settings - Fork 326
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
base: 3.0
Are you sure you want to change the base?
Add command to generate multiple database migrations #6913
Conversation
src/Sulu/Bundle/MigrationBundle/Command/MigrationDiffCommand.php
Outdated
Show resolved
Hide resolved
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()) | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
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.
// 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'." | ||
); | ||
|
There was a problem hiding this comment.
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.
// 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'." | ||
); |
There was a problem hiding this comment.
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.
// 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'." | ||
); |
There was a problem hiding this comment.
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.
Any updates on this? 🙂 |
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 ownVersion...php
file so from whaterver2.x
version to2.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.