Skip to content

Commit 467d50b

Browse files
committed
Use slightly different migration method for attachment system migration
This maybe help with issue #871
1 parent 1935258 commit 467d50b

File tree

1 file changed

+6
-47
lines changed

1 file changed

+6
-47
lines changed

migrations/Version20250220215048.php

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44

55
namespace DoctrineMigrations;
66

7-
use App\Migration\AbstractMultiPlatformMigration;
87
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
99

10-
final class Version20250220215048 extends AbstractMultiPlatformMigration
10+
final class Version20250220215048 extends AbstractMigration
1111
{
1212
public function getDescription(): string
1313
{
1414
return 'Split $path property for attachments into $internal_path and $external_path';
1515
}
1616

17-
public function mySQLUp(Schema $schema): void
17+
public function up(Schema $schema): void
1818
{
1919
//Create the new columns as nullable (that is easier modifying them)
20-
$this->addSql('ALTER TABLE attachments ADD internal_path VARCHAR(255) DEFAULT NULL, ADD external_path VARCHAR(255) DEFAULT NULL');
20+
$this->addSql('ALTER TABLE attachments ADD internal_path VARCHAR(255) DEFAULT NULL');
21+
$this->addSql('ALTER TABLE attachments ADD external_path VARCHAR(255) DEFAULT NULL');
2122

2223
//Copy the data from path to external_path and remove the path column
2324
$this->addSql('UPDATE attachments SET external_path=path');
@@ -32,52 +33,10 @@ public function mySQLUp(Schema $schema): void
3233
$this->addSql('UPDATE attachments SET external_path=NULL WHERE internal_path IS NOT NULL');
3334
}
3435

35-
public function mySQLDown(Schema $schema): void
36+
public function down(Schema $schema): void
3637
{
3738
$this->addSql('UPDATE attachments SET external_path=internal_path WHERE internal_path IS NOT NULL');
3839
$this->addSql('ALTER TABLE attachments DROP internal_path');
3940
$this->addSql('ALTER TABLE attachments RENAME COLUMN external_path TO path');
4041
}
41-
42-
public function postgreSQLUp(Schema $schema): void
43-
{
44-
//We can use the same SQL for PostgreSQL as for MySQL
45-
$this->mySQLUp($schema);
46-
}
47-
48-
public function postgreSQLDown(Schema $schema): void
49-
{
50-
//We can use the same SQL for PostgreSQL as for MySQL
51-
$this->mySQLDown($schema);
52-
}
53-
54-
public function sqLiteUp(Schema $schema): void
55-
{
56-
$this->addSql('CREATE TEMPORARY TABLE __temp__attachments AS SELECT id, type_id, original_filename, show_in_table, name, last_modified, datetime_added, class_name, element_id, path FROM attachments');
57-
$this->addSql('DROP TABLE attachments');
58-
$this->addSql('CREATE TABLE attachments (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, type_id INTEGER NOT NULL, original_filename VARCHAR(255) DEFAULT NULL, show_in_table BOOLEAN NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, class_name VARCHAR(255) NOT NULL, element_id INTEGER NOT NULL, internal_path VARCHAR(255) DEFAULT NULL, external_path VARCHAR(255) DEFAULT NULL, CONSTRAINT FK_47C4FAD6C54C8C93 FOREIGN KEY (type_id) REFERENCES attachment_types (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE)');
59-
$this->addSql('INSERT INTO attachments (id, type_id, original_filename, show_in_table, name, last_modified, datetime_added, class_name, element_id, external_path) SELECT id, type_id, original_filename, show_in_table, name, last_modified, datetime_added, class_name, element_id, path FROM __temp__attachments');
60-
$this->addSql('DROP TABLE __temp__attachments');
61-
$this->addSql('CREATE INDEX attachment_element_idx ON attachments (class_name, element_id)');
62-
$this->addSql('CREATE INDEX attachment_name_idx ON attachments (name)');
63-
$this->addSql('CREATE INDEX attachments_idx_class_name_id ON attachments (class_name, id)');
64-
$this->addSql('CREATE INDEX attachments_idx_id_element_id_class_name ON attachments (id, element_id, class_name)');
65-
$this->addSql('CREATE INDEX IDX_47C4FAD6C54C8C93 ON attachments (type_id)');
66-
$this->addSql('CREATE INDEX IDX_47C4FAD61F1F2A24 ON attachments (element_id)');
67-
68-
$this->addSql('UPDATE attachments SET internal_path=external_path WHERE external_path LIKE \'#%MEDIA#%%\' ESCAPE \'#\'');
69-
$this->addSql('UPDATE attachments SET internal_path=external_path WHERE external_path LIKE \'#%BASE#%%\' ESCAPE \'#\'');
70-
$this->addSql('UPDATE attachments SET internal_path=external_path WHERE external_path LIKE \'#%SECURE#%%\' ESCAPE \'#\'');
71-
$this->addSql('UPDATE attachments SET internal_path=external_path WHERE external_path LIKE \'#%FOOTPRINTS#%%\' ESCAPE \'#\'');
72-
$this->addSql('UPDATE attachments SET internal_path=external_path WHERE external_path LIKE \'#%FOOTPRINTS3D#%%\' ESCAPE \'#\'');
73-
$this->addSql('UPDATE attachments SET external_path=NULL WHERE internal_path IS NOT NULL');
74-
}
75-
76-
public function sqLiteDown(Schema $schema): void
77-
{
78-
//Reuse the MySQL down migration:
79-
$this->mySQLDown($schema);
80-
}
81-
82-
8342
}

0 commit comments

Comments
 (0)