Skip to content

Commit

Permalink
Added an index on media media type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Berthereau authored and Daniel Berthereau committed Feb 19, 2024
1 parent 84eedf4 commit 89a3864
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion application/data/install/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ CREATE TABLE `media` (
`renderer` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`data` longtext COLLATE utf8mb4_unicode_ci COMMENT '(DC2Type:json_array)',
`source` longtext COLLATE utf8mb4_unicode_ci,
`media_type` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`media_type` varchar(190) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`storage_id` varchar(190) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`extension` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`sha256` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
Expand All @@ -103,6 +103,7 @@ CREATE TABLE `media` (
UNIQUE KEY `UNIQ_6A2CA10C5CC5DB90` (`storage_id`),
KEY `IDX_6A2CA10C126F525E` (`item_id`),
KEY `item_position` (`item_id`,`position`),
KEY `media_type` (`media_type`),
CONSTRAINT `FK_6A2CA10C126F525E` FOREIGN KEY (`item_id`) REFERENCES `item` (`id`),
CONSTRAINT `FK_6A2CA10CBF396750` FOREIGN KEY (`id`) REFERENCES `resource` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Expand Down
19 changes: 19 additions & 0 deletions application/data/migrations/20240219000000_AddIndexMediaType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);

namespace Omeka\Db\Migrations;

use Doctrine\DBAL\Connection;
use Omeka\Db\Migration\MigrationInterface;

class AddIndexMediaType implements MigrationInterface
{
public function up(Connection $conn)
{
try {
$conn->executeStatement('ALTER TABLE `media` CHANGE `media_type` `media_type` varchar(190) COLLATE "utf8mb4_unicode_ci" NULL AFTER `source`;');
$conn->executeStatement('ALTER TABLE `media` ADD INDEX `media_type` (`media_type`);');
} catch (\Exception $e) {
// Index exists.
}
}
}
6 changes: 5 additions & 1 deletion application/src/Entity/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* @Index(
* name="item_position",
* columns={"item_id", "position"}
* ),
* @Index(
* name="media_type",
* columns={"media_type"}
* )
* }
* )
Expand Down Expand Up @@ -41,7 +45,7 @@ class Media extends Resource
protected $source;

/**
* @Column(nullable=true)
* @Column(nullable=true, length=190)
*/
protected $mediaType;

Expand Down

0 comments on commit 89a3864

Please sign in to comment.