From 575dc79da0c621d61c019c7bf06a0fc6e738f904 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Tue, 19 Mar 2024 12:07:45 +0100 Subject: [PATCH] make executable via vanilla Doctrine migrations --- README.md | 1 + migration/data/Version20240318163727.php | 64 ++++++++++++++++++++++++ migration/data/Version20240319113842.php | 64 ++++++++++++++++++++++++ migration/migrations.yml | 32 ++++++++++-- migrations-db.php | 17 +++++++ 5 files changed, 174 insertions(+), 4 deletions(-) create mode 100644 README.md create mode 100644 migration/data/Version20240318163727.php create mode 100644 migration/data/Version20240319113842.php create mode 100644 migrations-db.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..c59872b --- /dev/null +++ b/README.md @@ -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 \ No newline at end of file diff --git a/migration/data/Version20240318163727.php b/migration/data/Version20240318163727.php new file mode 100644 index 0000000..b5b61ec --- /dev/null +++ b/migration/data/Version20240318163727.php @@ -0,0 +1,64 @@ +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; + } +} diff --git a/migration/data/Version20240319113842.php b/migration/data/Version20240319113842.php new file mode 100644 index 0000000..507c2e9 --- /dev/null +++ b/migration/data/Version20240319113842.php @@ -0,0 +1,64 @@ +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; + } +} diff --git a/migration/migrations.yml b/migration/migrations.yml index 646de26..8d7f368 100644 --- a/migration/migrations.yml +++ b/migration/migrations.yml @@ -1,4 +1,28 @@ -name: D3 Decode Migrations -migrations_namespace: D3\DecodeMigrations -table_name: d3decode_migrations -migrations_directory: data \ No newline at end of file +#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" \ No newline at end of file diff --git a/migrations-db.php b/migrations-db.php new file mode 100644 index 0000000..fd9bfba --- /dev/null +++ b/migrations-db.php @@ -0,0 +1,17 @@ +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);