make database migrations executable via Doctrine
This commit is contained in:
parent
1251095eb3
commit
be4990f7f7
@ -46,6 +46,10 @@ Activate the module in the admin area of the shop in "Extensions -> Modules".
|
||||
|
||||
The necessary configuration can be found in the same area in the "Settings" tab.
|
||||
|
||||
### Additional installation instructions
|
||||
|
||||
- [Customising the database structure](migration/README.en.md)
|
||||
|
||||
## Changelog
|
||||
|
||||
See [CHANGELOG](CHANGELOG.md) for further information.
|
||||
|
@ -46,6 +46,10 @@ Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module".
|
||||
|
||||
Die nötige Konfiguration finden Sie im selben Bereich im Tab "Einstell.".
|
||||
|
||||
### ergänzende Installationhinweise
|
||||
|
||||
- [Anpassen der Datenbankstruktur](migration/README.md)
|
||||
|
||||
## Changelog
|
||||
|
||||
Siehe [CHANGELOG](CHANGELOG.md) für weitere Informationen.
|
||||
|
30
migration/README.en.md
Normal file
30
migration/README.en.md
Normal file
@ -0,0 +1,30 @@
|
||||
# Working with [Doctrine Migrations](https://www.doctrine-project.org/projects/doctrine-migrations/en/3.4/reference/introduction.html)
|
||||
|
||||
Migrations map the changes to the database structure in programmed form. Each structural change is stored in a single (new) migration file, which is part of the module.
|
||||
|
||||
## Applying the migrations that have not yet been executed
|
||||
|
||||
Doctrine itself monitors which migrations have already been executed and thus prevents multiple executions of the same migration.
|
||||
|
||||
For this module, migrations can be executed in various ways:
|
||||
|
||||
- by activating the module in the shop backend or
|
||||
- by executing all shop migrations via the OXID migration wrapper with `./vendor/bin/oe-eshop-db_migrate migrations:migrate` or
|
||||
- by executing this module migration via the OXID Migration Wrapper with `./vendor/bin/oe-eshop-db_migrate migrations:migrate d3totp` or
|
||||
- by executing this module migration via the Doctrine Migrations with `./vendor/bin/doctrine-migrations migrate --configuration ./vendor/d3/oxid-twofactor-onetimepassword/migration/migrations.yml --db-configuration ./vendor/d3/oxid-twofactor-onetimepassword/migration/migrations-db.php`
|
||||
|
||||
## Create a skeleton for the first or additional migrations
|
||||
|
||||
Adapt the `migrations.yml` to your module.
|
||||
|
||||
```
|
||||
./vendor/bin/oe-eshop-doctrine_migration migrations:generate d3moduleid
|
||||
```
|
||||
|
||||
Edit the created file according to your requirements.
|
||||
|
||||
## Differences between Doctrine Migrations and the OXID Migration Wrapper
|
||||
|
||||
No suites can be specified in the original Doctrine Migrations. However, it is possible to specify the direction (up / down) and a target version.
|
||||
|
||||
With OXID, migrations can only be executed upwards (up) and always fixed up to the latest version.
|
@ -1,36 +1,28 @@
|
||||
# Arbeiten mit [Doctrine Migrations](https://www.doctrine-project.org/projects/doctrine-migrations/en/3.6/reference/introduction.html)
|
||||
# Arbeiten mit [Doctrine Migrations](https://www.doctrine-project.org/projects/doctrine-migrations/en/3.4/reference/introduction.html)
|
||||
|
||||
Migrations bilden die Veränderung der Datenbankstruktur in programmierter Form ab. Jede Strukturänderung wird in einer einzelnen (jeweils neuen) Migrationsdatei abgelegt, die Teil des Moduls ist.
|
||||
|
||||
Passe die `migrations.yml` an Dein Modul an.
|
||||
## Anwenden der noch nicht ausgeführten Migrations
|
||||
|
||||
Doctrine überwacht selbst, welche Migrationen schon ausgeführt wurden und verhindert damit mehrfache Ausführungen der selben Migration.
|
||||
|
||||
Für dieses Modul können Migrationen auf verschiedenen Arten ausgeführt werden:
|
||||
|
||||
- durch Aktivieren des Moduls im Shopbackend oder
|
||||
- durch Ausführen aller Shopmigrationen über den OXID Migration Wrapper mit `./vendor/bin/oe-eshop-db_migrate migrations:migrate` oder
|
||||
- durch Ausführen dieser Modulmigration über den OXID Migration Wrapper mit `./vendor/bin/oe-eshop-db_migrate migrations:migrate d3totp` oder
|
||||
- durch Ausführen dieser Modulmigration über die Doctrine Migrations mit `./vendor/bin/doctrine-migrations migrate --configuration ./vendor/d3/oxid-twofactor-onetimepassword/migration/migrations.yml --db-configuration ./vendor/d3/oxid-twofactor-onetimepassword/migration/migrations-db.php`
|
||||
|
||||
## Erstellen eines Skeletons für die erste oder zusätzliche Migrationen
|
||||
|
||||
Passe die `migrations.yml` an Dein Modul an.
|
||||
|
||||
```
|
||||
./vendor/bin/oe-eshop-doctrine_migration migrations:generate d3moduleid
|
||||
```
|
||||
|
||||
Arbeite die angelegte Datei entsprechend Deinen Anforderungen um.
|
||||
|
||||
## Ausführen der noch nicht ausgeführten Migrations
|
||||
|
||||
Doctrine überwacht selbst, welche Migrationen schon ausgeführt wurden und verhindert damit mehrfache Ausführungen der selben Migration.
|
||||
|
||||
Im OXID-Shop werden Migrations mit folgendem Befehl ausgeführt:
|
||||
|
||||
```
|
||||
./vendor/bin/oe-eshop-db_migrate migrations:migrate
|
||||
```
|
||||
|
||||
Als Argument kann noch die Suite mitgegeben werden, wenn nur bestimmte Migrations ausgeführt werden sollen. Mögliche Angaben sind:
|
||||
|
||||
- CE - für alle CE-Migrations
|
||||
- PE - für alle PE-Migrations
|
||||
- EE - für alle EE-Migrations
|
||||
- PR - für alle Projekt-Migrations
|
||||
- ModuleId - für alle Migrations des jeweiligen Moduls
|
||||
- ohne Angabe - werden die Migrations aller Suiten nacheinander ausgeführt
|
||||
|
||||
## Abweichungen zwischen Doctrine Migrations und dem OXID Migration Wrapper
|
||||
|
||||
In den originalen Doctrine Migrations können keine Suiten angegeben werden. Dafür gibt es die Möglichkeit, die Richtung (up / down) und eine Zielversion anzugeben.
|
||||
|
@ -41,6 +41,14 @@ final class Version20240905232017 extends AbstractMigration
|
||||
$this->addTotpBackupCodesTable($schema);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
|
||||
|
||||
$this->removeTotpTable($schema);
|
||||
$this->removeTotpBackupCodesTable($schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
* @return void
|
||||
@ -97,6 +105,18 @@ final class Version20240905232017 extends AbstractMigration
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeTotpTable(Schema $schema): void
|
||||
{
|
||||
if ($schema->hasTable('d3totp')) {
|
||||
$schema->dropTable('d3totp');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
* @return void
|
||||
@ -151,8 +171,15 @@ final class Version20240905232017 extends AbstractMigration
|
||||
}
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeTotpBackupCodesTable(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
if ($schema->hasTable('d3totp_backupcodes')) {
|
||||
$schema->dropTable('d3totp_backupcodes');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
23
migration/migrations-db.php
Normal file
23
migration/migrations-db.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use OxidEsales\ComposerPlugin\Installer\Package\ShopPackageInstaller;
|
||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionProviderInterface;
|
||||
|
||||
require_once(__DIR__.'/../../../autoload.php');
|
||||
require_once __DIR__.'/../../../../'. ShopPackageInstaller::SHOP_SOURCE_DIRECTORY .'/bootstrap.php';
|
||||
|
||||
return ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get();
|
Loading…
Reference in New Issue
Block a user