Skip to content

Commit

Permalink
update legacy migration
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Jul 29, 2023
1 parent 564f792 commit 5e4df59
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions src/Migrations/Version20230508210151.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Fusio\Impl\Installation\DataSyncronizer;
use Fusio\Impl\Installation\NewInstallation;
use Fusio\Impl\Table;
use PSX\Api\Model\Passthru;
Expand All @@ -16,6 +17,8 @@
*/
final class Version20230508210151 extends AbstractMigration
{
private bool $legacy = false;

public function getDescription() : string
{
return 'Setup initial tables';
Expand All @@ -39,6 +42,7 @@ public function up(Schema $schema) : void
} else {
$actionTable = $schema->getTable('fusio_action');
$actionTable->dropColumn('engine');
$this->legacy = true;
}

if (!$schema->hasTable('fusio_action_queue')) {
Expand Down Expand Up @@ -485,6 +489,7 @@ public function up(Schema $schema) : void
$userTable = $schema->getTable('fusio_user');
$userTable->addColumn('identity_id', 'integer', ['notnull' => false]);
$userTable->dropColumn('provider');
$this->legacy = true;
}

if (!$schema->hasTable('fusio_user_grant')) {
Expand Down Expand Up @@ -636,31 +641,17 @@ public function postUp(Schema $schema): void
}
}

// remove legacy internal actions and schemas
$this->connection->executeStatement('DELETE FROM fusio_action WHERE category_id IN (2, 3, 4, 5)');
$this->connection->executeStatement('DELETE FROM fusio_schema WHERE category_id IN (2, 3, 4, 5)');

// update schema class
$this->connection->update('fusio_schema', ['source' => Passthru::class], ['name' => 'Passthru']);
// upgrade legacy systems
if ($this->legacy) {
// remove legacy internal actions and schemas
$this->connection->executeStatement('DELETE FROM fusio_action WHERE category_id IN (2, 3, 4, 5)');
$this->connection->executeStatement('DELETE FROM fusio_schema WHERE category_id IN (2, 3, 4, 5)');

// add missing events
$eventNames = [
'fusio.operation.create',
'fusio.operation.update',
'fusio.operation.delete',
];
foreach ($eventNames as $eventName) {
$count = (int) $this->connection->fetchOne('SELECT COUNT(*) AS cnt FROM fusio_event WHERE name = :name', ['name' => $eventName]);
if ($count > 0) {
continue;
}
// update schema class
$this->connection->update('fusio_schema', ['source' => Passthru::class], ['name' => 'Passthru']);

$this->connection->insert('fusio_event', [
'category_id' => 2,
'status' => 1,
'name' => $eventName,
'description' => '',
]);
// sync data
DataSyncronizer::sync($this->connection);
}
}
}

0 comments on commit 5e4df59

Please sign in to comment.