Skip to content

Commit

Permalink
cleanup closed_day_excluded_stores foreign keys
Browse files Browse the repository at this point in the history
- when the original migration was moved from project-base to the framework package, the key names were changed
- see Version20231124121921 and deleted Version20230524064748 in shopsys/shopsys@1a99756
  • Loading branch information
vitek-rostislav committed Jun 14, 2024
1 parent 590282c commit 401988f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Migrations/Version20240613235059.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Shopsys\FrameworkBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration;

class Version20240613235059 extends AbstractMigration
{
/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function up(Schema $schema): void
{
$dropForeignKeysQueries = $this->sql(
'
SELECT string_agg(\'ALTER TABLE \' || quote_ident(c.relname) || \' DROP CONSTRAINT \' || quote_ident(con.conname), \'; \')
FROM pg_constraint con
JOIN pg_class c ON con.conrelid = c.oid
WHERE c.relname = \'closed_day_excluded_stores\' AND con.contype = \'f\';',
)->fetchOne();

foreach (explode('; ', $dropForeignKeysQueries) as $dropForeignKeyQuery) {
$this->sql($dropForeignKeyQuery);
}

$this->sql('ALTER TABLE closed_day_excluded_stores ADD CONSTRAINT FK_B4EC517608F9E8F FOREIGN KEY (closed_day_id) REFERENCES closed_days (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->sql('ALTER TABLE closed_day_excluded_stores ADD CONSTRAINT FK_B4EC517B092A811 FOREIGN KEY (store_id) REFERENCES stores (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
}

/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function down(Schema $schema): void
{
}
}

0 comments on commit 401988f

Please sign in to comment.