chore: complete update
This commit is contained in:
30
src/Domain/Media/Migrations/AddSizeToImageVariantsTable.php
Normal file
30
src/Domain/Media/Migrations/AddSizeToImageVariantsTable.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media\Migrations;
|
||||
|
||||
use App\Framework\Database\ConnectionInterface;
|
||||
use App\Framework\Database\Migration\Migration;
|
||||
|
||||
final readonly class AddSizeToImageVariantsTable implements Migration
|
||||
{
|
||||
|
||||
public function up(ConnectionInterface $connection): void
|
||||
{
|
||||
$connection->execute("ALTER TABLE image_variants ADD COLUMN size VARCHAR(25) NOT NULL DEFAULT ''");
|
||||
}
|
||||
|
||||
public function down(ConnectionInterface $connection): void
|
||||
{
|
||||
$connection->execute("ALTER TABLE image_variants DROP COLUMN size");
|
||||
}
|
||||
|
||||
public function getVersion(): string
|
||||
{
|
||||
return "005";
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return "Add Size to Image Slot Table";
|
||||
}
|
||||
}
|
||||
43
src/Domain/Media/Migrations/CreateImageSlotsTable.php
Normal file
43
src/Domain/Media/Migrations/CreateImageSlotsTable.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media\Migrations;
|
||||
|
||||
use App\Framework\Database\ConnectionInterface;
|
||||
use App\Framework\Database\Migration\Migration;
|
||||
|
||||
final readonly class CreateImageSlotsTable implements Migration
|
||||
{
|
||||
|
||||
public function up(ConnectionInterface $connection): void
|
||||
{
|
||||
$sql = <<<SQL
|
||||
CREATE TABLE IF NOT EXISTS image_slots (
|
||||
id INT AUTO_INCREMENT,
|
||||
image_id VARCHAR(26) NOT NULL,
|
||||
slot_name VARCHAR(50) NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NULL DEFAULT NULL,
|
||||
|
||||
PRIMARY KEY (id)
|
||||
)
|
||||
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
SQL;
|
||||
|
||||
$connection->query($sql);
|
||||
}
|
||||
|
||||
public function down(ConnectionInterface $connection): void
|
||||
{
|
||||
$connection->execute("DROP TABLE IF EXISTS image_slots");
|
||||
}
|
||||
|
||||
public function getVersion(): string
|
||||
{
|
||||
return "004";
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return "Create Image Slot Table";
|
||||
}
|
||||
}
|
||||
76
src/Domain/Media/Migrations/CreateImageVariantsTable.php
Normal file
76
src/Domain/Media/Migrations/CreateImageVariantsTable.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Domain\Media\Migrations;
|
||||
|
||||
use App\Framework\Database\ConnectionInterface;
|
||||
use App\Framework\Database\Migration\Migration;
|
||||
|
||||
final class CreateImageVariantsTable implements Migration
|
||||
{
|
||||
|
||||
public function up(ConnectionInterface $connection): void
|
||||
{
|
||||
$sql = <<<SQL
|
||||
CREATE TABLE IF NOT EXISTS image_variants (
|
||||
id INT AUTO_INCREMENT,
|
||||
image_id VARCHAR(26) NOT NULL,
|
||||
variant_type VARCHAR(50) NOT NULL,
|
||||
format VARCHAR(25) NOT NULL,
|
||||
mime_type VARCHAR(100) NOT NULL,
|
||||
width INT NOT NULL,
|
||||
height INT NOT NULL,
|
||||
file_size BIGINT NOT NULL,
|
||||
filename VARCHAR(500) NOT NULL,
|
||||
path VARCHAR(500) NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NULL DEFAULT NULL,
|
||||
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_image_variants_combination (image_id, variant_type, format),
|
||||
CONSTRAINT fk_image_variants_image_id
|
||||
FOREIGN KEY (image_id) REFERENCES images(ulid) ON DELETE CASCADE,
|
||||
INDEX idx_image_variants_lookup (image_id, variant_type)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
SQL;
|
||||
|
||||
$connection->query($sql);
|
||||
}
|
||||
|
||||
public function down(ConnectionInterface $connection): void
|
||||
{
|
||||
$this->dropExistingConstraints($connection);
|
||||
|
||||
$connection->execute("DROP TABLE IF EXISTS image_variants");
|
||||
}
|
||||
|
||||
public function getVersion(): string
|
||||
{
|
||||
return "003";
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return "Create Image Variant Table";
|
||||
}
|
||||
|
||||
private function dropExistingConstraints(ConnectionInterface $connection): void
|
||||
{
|
||||
try {
|
||||
// Alle bestehenden Foreign Key Constraints für diese Tabelle finden und entfernen
|
||||
$constraints = $connection->query("
|
||||
SELECT CONSTRAINT_NAME
|
||||
FROM information_schema.KEY_COLUMN_USAGE
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'image_variants'
|
||||
AND REFERENCED_TABLE_NAME IS NOT NULL
|
||||
")->fetchAll();
|
||||
|
||||
foreach ($constraints as $constraint) {
|
||||
$connection->execute('ALTER TABLE image_variants DROP FOREIGN KEY ' . $constraint['CONSTRAINT_NAME']);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Ignorieren wenn Tabelle nicht existiert oder keine Constraints vorhanden sind
|
||||
}
|
||||
}
|
||||
}
|
||||
52
src/Domain/Media/Migrations/CreateImagesTable.php
Normal file
52
src/Domain/Media/Migrations/CreateImagesTable.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Domain\Media\Migrations;
|
||||
|
||||
use App\Framework\Database\ConnectionInterface;
|
||||
use App\Framework\Database\Migration\Migration;
|
||||
|
||||
final class CreateImagesTable implements Migration
|
||||
{
|
||||
|
||||
public function up(ConnectionInterface $connection): void
|
||||
{
|
||||
$sql = <<<SQL
|
||||
CREATE TABLE IF NOT EXISTS images (
|
||||
ulid VARCHAR(26) NOT NULL,
|
||||
filename VARCHAR(255) NOT NULL,
|
||||
original_filename VARCHAR(255) NOT NULL,
|
||||
mime_type VARCHAR(100) NOT NULL,
|
||||
file_size BIGINT NOT NULL,
|
||||
width INT UNSIGNED NOT NULL,
|
||||
height INT UNSIGNED NOT NULL,
|
||||
hash VARCHAR(255) NOT NULL,
|
||||
path VARCHAR(500) NOT NULL,
|
||||
alt_text TEXT NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NULL DEFAULT NULL,
|
||||
|
||||
PRIMARY KEY (ulid),
|
||||
UNIQUE KEY uk_images_hash (hash),
|
||||
UNIQUE KEY uk_images_ulid (ulid)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
SQL;
|
||||
|
||||
$connection->query($sql);
|
||||
}
|
||||
|
||||
public function down(ConnectionInterface $connection): void
|
||||
{
|
||||
$connection->execute("DROP TABLE IF EXISTS images");
|
||||
}
|
||||
|
||||
public function getVersion(): string
|
||||
{
|
||||
return "002";
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return "Create Image Table";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media\Migrations;
|
||||
|
||||
use App\Framework\Database\ConnectionInterface;
|
||||
use App\Framework\Database\Migration\Migration;
|
||||
|
||||
final readonly class UpdateImageVariantsConstraint implements Migration
|
||||
{
|
||||
public function up(ConnectionInterface $connection): void
|
||||
{
|
||||
// Bestehenden Constraint entfernen
|
||||
$connection->execute("ALTER TABLE image_variants DROP INDEX uk_image_variants_combination");
|
||||
|
||||
// Neuen Constraint mit size-Spalte hinzufügen
|
||||
$connection->execute("ALTER TABLE image_variants ADD UNIQUE KEY uk_image_variants_combination (image_id, variant_type, size, format)");
|
||||
}
|
||||
|
||||
public function down(ConnectionInterface $connection): void
|
||||
{
|
||||
// Zurück zum ursprünglichen Constraint
|
||||
$connection->execute("ALTER TABLE image_variants DROP INDEX uk_image_variants_combination");
|
||||
$connection->execute("ALTER TABLE image_variants ADD UNIQUE KEY uk_image_variants_combination (image_id, variant_type, format)");
|
||||
}
|
||||
|
||||
public function getVersion(): string
|
||||
{
|
||||
return "006";
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return "Update unique constraint to include size column";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user