fix migration path
This commit is contained in:
38
migration/README.md
Normal file
38
migration/README.md
Normal file
@ -0,0 +1,38 @@
|
||||
# Arbeiten mit [Doctrine Migrations](https://www.doctrine-project.org/projects/doctrine-migrations/en/3.6/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.
|
||||
|
||||
## Erstellen eines Skeletons für die erste oder zusätzliche Migrationen
|
||||
|
||||
```
|
||||
./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.
|
||||
|
||||
Bei OXID können Migrations ausschließlich aufwärts (up) und immer fix bis zur aktuellsten Version ausgeführt werden.
|
147
migration/data/Version20240905232017.php
Normal file
147
migration/data/Version20240905232017.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\SchemaException;
|
||||
use Doctrine\DBAL\Types\BooleanType;
|
||||
use Doctrine\DBAL\Types\DateTimeType;
|
||||
use Doctrine\DBAL\Types\StringType;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20240905232017 extends AbstractMigration
|
||||
{
|
||||
public function getDescription() : string
|
||||
{
|
||||
return 'Extend Database by missing OTP tables and missing columns.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function up(Schema $schema) : void
|
||||
{
|
||||
$this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
|
||||
|
||||
$this->addTotpTable($schema);
|
||||
$this->addTotpBackupCodesTable($schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
* @return void
|
||||
* @throws SchemaException
|
||||
*/
|
||||
public function addTotpTable(Schema $schema): void
|
||||
{
|
||||
$table = !$schema->hasTable('d3totp') ?
|
||||
$schema->createTable('d3totp')->setComment('totp setting') :
|
||||
$schema->getTable('d3totp');
|
||||
|
||||
// OXID
|
||||
if (!$table->hasColumn('OXID')) {
|
||||
$table->addColumn('OXID', (new StringType())->getName())
|
||||
->setLength(32)
|
||||
->setFixed(true)
|
||||
->setNotnull(true);
|
||||
}
|
||||
|
||||
// OXUSERID
|
||||
if (!$table->hasColumn('OXUSERID')) {
|
||||
$table->addColumn('OXUSERID', (new StringType())->getName())
|
||||
->setLength(32)
|
||||
->setFixed(true)
|
||||
->setNotnull(true);
|
||||
}
|
||||
|
||||
// useTotp
|
||||
if (!$table->hasColumn('USETOTP')) {
|
||||
$table->addColumn('USETOTP', (new BooleanType())->getName())
|
||||
->setLength(1)
|
||||
->setDefault(0)
|
||||
->setNotnull(true);
|
||||
}
|
||||
|
||||
// Seed
|
||||
if (!$table->hasColumn('SEED')) {
|
||||
$table->addColumn('SEED', (new StringType())->getName())
|
||||
->setLength(256)
|
||||
->setNotnull(true);
|
||||
}
|
||||
|
||||
// oxtimestamp
|
||||
if (!$table->hasColumn('OXTIMESTAMP')) {
|
||||
$table->addColumn('OXTIMESTAMP', (new DateTimeType())->getName())
|
||||
->setNotnull(true)
|
||||
->setDefault('CURRENT_TIMESTAMP');
|
||||
}
|
||||
|
||||
$table->hasPrimaryKey() ?:$table->setPrimaryKey(['oxid']);
|
||||
|
||||
if($table->hasIndex('OXUSERID') === false){
|
||||
$table->addUniqueIndex(['OXUSERID'], 'OXUSERID');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
* @return void
|
||||
* @throws SchemaException
|
||||
*/
|
||||
public function addTotpBackupCodesTable(Schema $schema): void
|
||||
{
|
||||
$table = !$schema->hasTable('d3totp_backupcodes') ?
|
||||
$schema->createTable('d3totp_backupcodes')->setComment('totp backup codes') :
|
||||
$schema->getTable('d3totp_backupcodes');
|
||||
|
||||
// OXID
|
||||
if (!$table->hasColumn('OXID')) {
|
||||
$table->addColumn('OXID', (new StringType())->getName())
|
||||
->setLength(32)
|
||||
->setFixed(true)
|
||||
->setNotnull(true);
|
||||
}
|
||||
|
||||
// OXUSERID
|
||||
if (!$table->hasColumn('OXUSERID')) {
|
||||
$table->addColumn('OXUSERID', (new StringType())->getName())
|
||||
->setLength(32)
|
||||
->setFixed(true)
|
||||
->setNotnull(true)
|
||||
->setComment('User ID');
|
||||
}
|
||||
|
||||
// useTotp
|
||||
if (!$table->hasColumn('BACKUPCODE')) {
|
||||
$table->addColumn('BACKUPCODE', (new StringType())->getName())
|
||||
->setFixed(false)
|
||||
->setLength(64)
|
||||
->setNotnull(true);
|
||||
}
|
||||
|
||||
// oxtimestamp
|
||||
if (!$table->hasColumn('OXTIMESTAMP')) {
|
||||
$table->addColumn('OXTIMESTAMP', (new DateTimeType())->getName())
|
||||
->setNotnull(true)
|
||||
->setDefault('CURRENT_TIMESTAMP');
|
||||
}
|
||||
|
||||
$table->hasPrimaryKey() ?:$table->setPrimaryKey(['oxid']);
|
||||
|
||||
if($table->hasIndex('OXUSERID') === false){
|
||||
$table->addIndex(['OXUSERID'], 'OXUSERID');
|
||||
}
|
||||
|
||||
if($table->hasIndex('BACKUPCODE') === false){
|
||||
$table->addIndex(['BACKUPCODE'], 'BACKUPCODE');
|
||||
}
|
||||
}
|
||||
|
||||
public function down(Schema $schema) : void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
}
|
||||
}
|
4
migration/migrations.yml
Normal file
4
migration/migrations.yml
Normal file
@ -0,0 +1,4 @@
|
||||
table_storage:
|
||||
table_name: d3migrations_totp
|
||||
migrations_paths:
|
||||
'D3\Totp\Migrations': data
|
Verwijs in nieuw issue
Block a user