make executable via vanilla Doctrine migrations
This commit is contained in:
parent
6247cc0a57
commit
575dc79da0
1
README.md
Normal file
1
README.md
Normal file
@ -0,0 +1 @@
|
||||
./vendor/bin/doctrine-migrations migrations:migrate --configuration ./vendor/d3/decode_migrations/migration/migrations.yml --db-configuration vendor/d3/decode_migrations/migrations-db.php
|
64
migration/data/Version20240318163727.php
Normal file
64
migration/data/Version20240318163727.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\DecodeMigrations\migration\data;
|
||||
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20240318163727 extends AbstractMigration
|
||||
{
|
||||
public function getDescription() : string
|
||||
{
|
||||
return 'decode / encode configuration columns';
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function up(Schema $schema) : void
|
||||
{
|
||||
$this->skipIf($this->connection->getDatabasePlatform() instanceof MySQL80Platform, 'Config values can\'t decoded on MySQL 8');
|
||||
|
||||
$this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
|
||||
|
||||
$table = $schema->getTable('oxconfig');
|
||||
$column = $table->getColumn('oxvarvalue');
|
||||
|
||||
$this->skipIf(!$column->getType() instanceof BlobType, 'Config values are already decoded');
|
||||
|
||||
$this->addSql('ALTER TABLE oxconfig ADD COLUMN `OXVARVALUE_UNENC` text;');
|
||||
$this->addSql("UPDATE oxconfig SET `OXVARVALUE_UNENC` = DECODE(OXVARVALUE, '".Config::DEFAULT_CONFIG_KEY."') WHERE 1;");
|
||||
$this->addSql('ALTER TABLE oxconfig MODIFY COLUMN `OXVARVALUE` text;');
|
||||
$this->addSql("UPDATE oxconfig SET `OXVARVALUE` = `OXVARVALUE_UNENC` WHERE 1;");
|
||||
$this->addSql('ALTER TABLE oxconfig DROP COLUMN `OXVARVALUE_UNENC`;');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->skipIf($this->connection->getDatabasePlatform() instanceof MySQL80Platform, 'Config values can\'t encoded on MySQL 8');
|
||||
|
||||
$this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
|
||||
|
||||
$table = $schema->getTable('oxconfig');
|
||||
$column = $table->getColumn('oxvarvalue');
|
||||
|
||||
$this->skipIf($column->getType() instanceof BlobType, 'Config values are already encoded');
|
||||
|
||||
$this->addSql( 'ALTER TABLE oxconfig ADD COLUMN `OXVARVALUE_ENC` text;' );
|
||||
$this->addSql( "UPDATE oxconfig SET `OXVARVALUE_ENC` = ENCODE(OXVARVALUE, '" . Config::DEFAULT_CONFIG_KEY . "') WHERE 1;" );
|
||||
$this->addSql( 'ALTER TABLE oxconfig MODIFY COLUMN `OXVARVALUE` mediumblob;' );
|
||||
$this->addSql( "UPDATE oxconfig SET `OXVARVALUE` = `OXVARVALUE_ENC` WHERE 1;" );
|
||||
$this->addSql( 'ALTER TABLE oxconfig DROP COLUMN `OXVARVALUE_ENC`;' );
|
||||
}
|
||||
|
||||
public function isTransactional(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
64
migration/data/Version20240319113842.php
Normal file
64
migration/data/Version20240319113842.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\DecodeMigrations\migration\data;
|
||||
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20240319113842 extends AbstractMigration
|
||||
{
|
||||
public function getDescription() : string
|
||||
{
|
||||
return 'decode / encode user payment columns';
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function up(Schema $schema) : void
|
||||
{
|
||||
$this->skipIf($this->connection->getDatabasePlatform() instanceof MySQL80Platform, 'Userpayment values can\'t decoded on MySQL 8');
|
||||
|
||||
$this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
|
||||
|
||||
$table = $schema->getTable('oxuserpayments');
|
||||
$column = $table->getColumn('oxvalue');
|
||||
|
||||
$this->skipIf(!$column->getType() instanceof BlobType, 'Userpayment values are already decoded');
|
||||
|
||||
$this->addSql('ALTER TABLE oxuserpayments ADD COLUMN `OXVALUE_UNENC` text;');
|
||||
$this->addSql("UPDATE oxuserpayments SET `OXVALUE_UNENC` = DECODE(OXVALUE, '".Config::DEFAULT_CONFIG_KEY."') WHERE 1;");
|
||||
$this->addSql('ALTER TABLE oxuserpayments MODIFY COLUMN `OXVALUE` text;');
|
||||
$this->addSql("UPDATE oxuserpayments SET `OXVALUE` = `OXVALUE_UNENC` WHERE 1;");
|
||||
$this->addSql('ALTER TABLE oxuserpayments DROP COLUMN `OXVALUE_UNENC`;');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->skipIf($this->connection->getDatabasePlatform() instanceof MySQL80Platform, 'Userpayment values can\'t encoded on MySQL 8');
|
||||
|
||||
$this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
|
||||
|
||||
$table = $schema->getTable('oxuserpayments');
|
||||
$column = $table->getColumn('oxvalue');
|
||||
|
||||
$this->skipIf($column->getType() instanceof BlobType, 'Userpayment values are already encoded');
|
||||
|
||||
$this->addSql('ALTER TABLE oxuserpayments ADD COLUMN `OXVALUE_ENC` text;');
|
||||
$this->addSql("UPDATE oxuserpayments SET `OXVALUE_ENC` = ENCODE(OXVALUE, '".Config::DEFAULT_CONFIG_KEY."') WHERE 1;");
|
||||
$this->addSql('ALTER TABLE oxuserpayments MODIFY COLUMN `OXVALUE` blob;');
|
||||
$this->addSql("UPDATE oxuserpayments SET `OXVALUE` = `OXVALUE_ENC` WHERE 1;");
|
||||
$this->addSql('ALTER TABLE oxuserpayments DROP COLUMN `OXVALUE_ENC`;');
|
||||
}
|
||||
|
||||
public function isTransactional(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,4 +1,28 @@
|
||||
name: D3 Decode Migrations
|
||||
migrations_namespace: D3\DecodeMigrations
|
||||
table_name: d3decode_migrations
|
||||
migrations_directory: data
|
||||
#name: D3 Decode Migrations
|
||||
#migrations_namespace: D3\DecodeMigrations
|
||||
#table_name: d3decode_migrations
|
||||
#migrations_directory: data
|
||||
#
|
||||
#
|
||||
#table_storage:
|
||||
# table_name: d3decode_migrations
|
||||
# version_column_name: version
|
||||
# version_column_length: 191
|
||||
# executed_at_column_name: executed_at
|
||||
# execution_time_column_name: execution_time
|
||||
#
|
||||
#migrations_paths:
|
||||
# 'MyProject\Migrations': /data/doctrine/migrations/lib/MyProject/Migrations
|
||||
# 'MyProject\Component\Migrations': ./Component/MyProject/Migrations
|
||||
#
|
||||
#all_or_nothing: true
|
||||
#transactional: true
|
||||
#check_database_platform: true
|
||||
#organize_migrations: none
|
||||
#
|
||||
#connection: null
|
||||
#em: null
|
||||
#
|
||||
migrations:
|
||||
- "D3\\DecodeMigrations\\migration\\data\\Version20240318163727"
|
||||
- "D3\\DecodeMigrations\\migration\\data\\Version20240319113842"
|
17
migrations-db.php
Normal file
17
migrations-db.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
require_once './vendor/autoload.php';
|
||||
|
||||
/** @var \OxidEsales\Eshop\Core\DatabaseProvider $db */
|
||||
$dbprovider = new \OxidEsales\Eshop\Core\DatabaseProvider();
|
||||
$dbprovider->setConfigFile(new \OxidEsales\Eshop\Core\ConfigFile('./source/config.inc.php'));
|
||||
$method = new ReflectionMethod(get_class($dbprovider), "getConnectionParameters");
|
||||
$method->setAccessible(true);
|
||||
$connParameters = $method->invoke($dbprovider);
|
||||
|
||||
$database = new \OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database();
|
||||
$database->setConnectionParameters($connParameters);
|
||||
$method = new ReflectionMethod(get_class($database), "getConnectionParameters");
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invoke($database);
|
Loading…
Reference in New Issue
Block a user