Skip to content

Commit 5cdab1c

Browse files
committed
Add Migration for address change identifiers
Add a migration as a followup for commit 82fbafd In that commit we changed how we store the address change identifiers and made the columns non-nullable, but forgot to migrate old address change entries where the `previous_identifier` defaulted to NULL.
1 parent 05b1ca6 commit 5cdab1c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare( strict_types=1 );
4+
5+
namespace WMDE\Fundraising\AddressChangeContext\DataAccess\Migrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* This migration is a followup for commit 82fbafd0df529ba9604b35ef805174d1a4c390fa
12+
* where we changed how we store the address change identifiers and made the columns non-nullable,
13+
* but forgot to migrate old address change entries where the `previous_identifier` defaulted to NULL.
14+
*/
15+
final class Version20241113164504 extends AbstractMigration {
16+
public function getDescription(): string {
17+
return 'Make address change identifiers non-nullable';
18+
}
19+
20+
public function up( Schema $schema ): void {
21+
$this->addSql( "UPDATE address_change SET previous_identifier=current_identifier WHERE previous_identifier IS NULL AND current_identifier IS NOT NULL" );
22+
// We can't use $schema here to modify the columns because `addSQL` appends to the SQL generated by $schema calls.
23+
// We would fail the migration when trying to set a column to non-nullable if it already contains NULL values
24+
$this->addSql( "ALTER TABLE address_change MODIFY current_identifier VARCHAR(36) NOT NULL, MODIFY previous_identifier VARCHAR(36) NOT NULL " );
25+
}
26+
27+
public function down( Schema $schema ): void {
28+
$addressChange = $schema->getTable( 'address_change' );
29+
$addressChange->modifyColumn( 'current_identifier', [ 'notnull' => false ] );
30+
$addressChange->modifyColumn( 'previous_identifier', [ 'notnull' => false ] );
31+
}
32+
}

0 commit comments

Comments
 (0)