Skip to content

Commit

Permalink
Repair the production_entities_enabled feature
Browse files Browse the repository at this point in the history
Prior to this change, the production_entities_enabled field could be deleted from the services table.
This change cleans up after the migration got retracted.
Also add the required param to the tests.
  • Loading branch information
johanib committed Oct 31, 2024
1 parent d1cb78a commit 3c9a726
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
43 changes: 43 additions & 0 deletions migrations/Version20240514071702.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* Copyright 2024 SURFnet B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

namespace Surfnet\ServiceProviderDashboard\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Drops the `production_entities_enabled` column from the `service` entity
*/
final class Version20240514071702 extends AbstractMigration
{
public function getDescription(): string
{
return 'This migration is preserved to keep the migration history intact. This migration was used to drop the `production_entities_enabled` field in the services table. However, the feature removal got dropped and we don\'t want to cause data loss.';
}

public function up(Schema $schema): void
{
}

public function down(Schema $schema): void
{
}
}
33 changes: 33 additions & 0 deletions migrations/Version20241031120000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Surfnet\ServiceProviderDashboard\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20241031120000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Restores the `production_entities_enabled` column to the `service` table if got removed by retracted migration Version20240514071702';
}

public function up(Schema $schema): void
{
// Check if the column exists
$columns = $this->connection->createSchemaManager()->listTableColumns('service');
$columnExists = false;
foreach ($columns as $column) {
if ($column->getName() === 'production_entities_enabled') {
$columnExists = true;
break;
}
}

if (!$columnExists) {
$this->addSql('ALTER TABLE service ADD production_entities_enabled TINYINT(1) NOT NULL DEFAULT 0');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function test_it_can_process_an_edit_service_command()
'Foobar',
'team-foobar',
false,
false,
true,
'institution',
'not-applicable',
Expand Down Expand Up @@ -115,6 +116,7 @@ public function test_it_rejects_non_existing_service()
'Foobar',
'team-foobar',
false,
false,
true,
'institution',
'not-applicable',
Expand Down Expand Up @@ -145,6 +147,7 @@ public function test_it_rejects_non_unique_edit_service_command()
'team-foobar',
false,
false,
false,
'institution',
'not-applicable',
'no',
Expand Down

0 comments on commit 3c9a726

Please sign in to comment.