You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'Migration can only be executed safely on \'postgresql\'.'
36
35
);
37
36
38
-
//$this->addSql('CREATE SEQUENCE IF NOT EXISTS swp_article_extra_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
39
-
$this->addSql('CREATE SEQUENCE IF NOT EXISTS swp_article_extra_id_seq INCREMENT BY 1 MINVALUE 1 START WITH 1');
40
-
$this->addSql(
41
-
'CREATE TABLE IF NOT EXISTS swp_article_extra (id INT NOT NULL, article_id INT DEFAULT NULL, field_name VARCHAR(255) NOT NULL, discr VARCHAR(255) NOT NULL, value VARCHAR(255) DEFAULT NULL, embed VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'
42
-
);
43
-
$this->addSql('CREATE INDEX IF NOT EXISTS IDX_9E61B3177294869C ON swp_article_extra (article_id)');
44
-
$this->addSql(
45
-
'ALTER TABLE swp_article_extra DROP CONSTRAINT IF EXISTS FK_9E61B3177294869C'
46
-
);
47
-
$this->addSql(
48
-
'ALTER TABLE swp_article_extra ADD CONSTRAINT FK_9E61B3177294869C FOREIGN KEY (article_id) REFERENCES swp_article (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'
49
-
);
37
+
// Check if table already exists before creating
38
+
if (!$schema->hasTable('swp_article_extra')) {
39
+
$this->addSql('CREATE SEQUENCE swp_article_extra_id_seq INCREMENT BY 1 MINVALUE 1 START WITH 1');
40
+
$this->addSql(
41
+
'CREATE TABLE swp_article_extra (id INT NOT NULL DEFAULT nextval(\'swp_article_extra_id_seq\'), article_id INT DEFAULT NULL, field_name VARCHAR(255) NOT NULL, discr VARCHAR(255) NOT NULL, value VARCHAR(255) DEFAULT NULL, embed VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'
42
+
);
43
+
$this->addSql('CREATE INDEX IDX_9E61B3177294869C ON swp_article_extra (article_id)');
44
+
45
+
// Add constraint immediately after table creation
46
+
$this->addSql(
47
+
'ALTER TABLE swp_article_extra ADD CONSTRAINT FK_9E61B3177294869C FOREIGN KEY (article_id) REFERENCES swp_article (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'
48
+
);
49
+
} else {
50
+
// Table exists, just ensure constraint is in place
51
+
$this->addSql(
52
+
'ALTER TABLE swp_article_extra DROP CONSTRAINT IF EXISTS FK_9E61B3177294869C'
53
+
);
54
+
$this->addSql(
55
+
'ALTER TABLE swp_article_extra ADD CONSTRAINT FK_9E61B3177294869C FOREIGN KEY (article_id) REFERENCES swp_article (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'
56
+
);
57
+
}
50
58
}
51
59
52
60
publicfunctiondown(Schema$schema): void
53
61
{
54
-
// this down() migration is auto-generated, please modify it to your needs
0 commit comments