Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/bundle/Core/Resources/config/doctrine_migrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,19 @@ services:
$connection: '@ibexa.persistence.connection'
tags:
- { name: !php/const Ibexa\Contracts\DoctrineMigrations\Migrations\IbexaMigrationTag::TAG }

Ibexa\Bundle\RepositoryInstaller\Migration\RenamePostgreSqlPrimaryKeysMigration:
autowire: true
public: false
arguments:
$connection: '@ibexa.persistence.connection'
tags:
- { name: !php/const Ibexa\Contracts\DoctrineMigrations\Migrations\IbexaMigrationTag::TAG }

Ibexa\Bundle\RepositoryInstaller\Migration\RecreateMariaDbBookmarkForeignKeysMigration:
autowire: true
public: false
arguments:
$connection: '@ibexa.persistence.connection'
tags:
- { name: !php/const Ibexa\Contracts\DoctrineMigrations\Migrations\IbexaMigrationTag::TAG }
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\RepositoryInstaller\Migration;

use DateTimeImmutable;
use Doctrine\DBAL\Schema\Schema;
use Ibexa\Contracts\DoctrineMigrations\Migrations\AbstractSqlMigration;
use Ibexa\Contracts\DoctrineMigrations\Migrations\IbexaMigrationInterface;
use Ibexa\Contracts\DoctrineMigrations\Migrations\SqlPlatform;

/**
* Adds ON UPDATE NO ACTION to the "ibexa_content_bookmark" foreign keys on MariaDB, as a fresh 5.0
* install has them.
*
* The schema declares both with ON UPDATE NO ACTION, and {@see InstallSchemaMigration}'s SQL leaves
* it out, as it's the default. They behave the same, but MariaDB reports a foreign key without it
* as RESTRICT, so the two installs differ in information_schema and in Doctrine DBAL's schema
* comparison. MySQL and PostgreSQL report NO ACTION either way. MariaDB can't change a foreign key,
* so each is dropped and added again. Both always have the same rule, so only the first one is
* checked.
*/
final class RecreateMariaDbBookmarkForeignKeysMigration extends AbstractSqlMigration implements IbexaMigrationInterface
{
public function getDescription(): string
{
return 'Adds ON UPDATE NO ACTION to the core bookmark foreign keys on MariaDB';
}

public static function getTargetVersion(): string
{
return '5.0.0';
}

public static function getCreationDate(): DateTimeImmutable
{
return new DateTimeImmutable('2026-10-06 00:00:02');
}

public function up(Schema $schema): void
{
$this->abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE);

if (!$this->isMariaDB()) {
return;
}

$updateRule = $this->connection->fetchOne(
'SELECT UPDATE_RULE FROM information_schema.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = DATABASE()'
. " AND TABLE_NAME = 'ibexa_content_bookmark' AND CONSTRAINT_NAME = 'ibexa_content_bookmark_location_fk'"
);
if ($updateRule === 'RESTRICT') {
$this->addSqlFile(__DIR__ . '/sql/recreate-bookmark-foreign-keys-mariadb.sql');
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\RepositoryInstaller\Migration;

use DateTimeImmutable;
use Doctrine\DBAL\Schema\Schema;
use Ibexa\Contracts\DoctrineMigrations\Migrations\AbstractSqlMigration;
use Ibexa\Contracts\DoctrineMigrations\Migrations\IbexaMigrationInterface;
use Ibexa\Contracts\DoctrineMigrations\Migrations\SqlPlatform;

/**
* Renames the primary keys of the core tables on PostgreSQL after the tables, as a fresh 5.0
* install names them.
*
* PostgreSQL names a primary key "<table>_pkey" when it creates the table, and keeps that name when
* the table is renamed. {@see RenameSchemaTo5_0Migration} renames the tables, so their primary keys
* kept their 4.6 names, such as "ezcontentobject_pkey" on "ibexa_content". ibexa/installer's 4.6 to
* 5.0 upgrade script doesn't rename them either. MySQL and MariaDB name every primary key PRIMARY,
* and SQLite doesn't name them.
*
* A database has either all of the 4.6 names or none of them, so only the first one is checked. The
* statements are in sql/rename-primary-keys-postgresql.sql.
*/
final class RenamePostgreSqlPrimaryKeysMigration extends AbstractSqlMigration implements IbexaMigrationInterface
{
public function getDescription(): string
{
return 'Renames the PostgreSQL primary keys of the core tables after the tables';
}

public static function getTargetVersion(): string
{
return '5.0.0';
}

public static function getCreationDate(): DateTimeImmutable
{
return new DateTimeImmutable('2026-10-06 00:00:01');
}

public function up(Schema $schema): void
{
$this->abortIfUnsupportedPlatform(SqlPlatform::MYSQL, SqlPlatform::MARIADB, SqlPlatform::POSTGRESQL, SqlPlatform::SQLITE);

if (!$this->isPostgreSQL()) {
return;
}

$hasOldName = $this->connection->fetchOne(
"SELECT 1 FROM pg_constraint WHERE conrelid = to_regclass('ibexa_binary_file') AND conname = 'ezbinaryfile_pkey'"
) !== false;
if ($hasOldName) {
$this->addSqlFile(__DIR__ . '/sql/rename-primary-keys-postgresql.sql');
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ALTER TABLE ibexa_content_bookmark DROP FOREIGN KEY ibexa_content_bookmark_location_fk;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_bookmark
ADD CONSTRAINT ibexa_content_bookmark_location_fk FOREIGN KEY (node_id)
REFERENCES ibexa_content_tree (node_id) ON DELETE CASCADE ON UPDATE NO ACTION;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_bookmark DROP FOREIGN KEY ibexa_content_bookmark_user_fk;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_bookmark
ADD CONSTRAINT ibexa_content_bookmark_user_fk FOREIGN KEY (user_id)
REFERENCES ibexa_user (contentobject_id) ON DELETE CASCADE ON UPDATE NO ACTION;
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
ALTER TABLE ibexa_binary_file RENAME CONSTRAINT ezbinaryfile_pkey TO ibexa_binary_file_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content RENAME CONSTRAINT ezcontentobject_pkey TO ibexa_content_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_bookmark RENAME CONSTRAINT ezcontentbrowsebookmark_pkey TO ibexa_content_bookmark_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_field RENAME CONSTRAINT ezcontentobject_attribute_pkey TO ibexa_content_field_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_language RENAME CONSTRAINT ezcontent_language_pkey TO ibexa_content_language_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_name RENAME CONSTRAINT ezcontentobject_name_pkey TO ibexa_content_name_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_relation RENAME CONSTRAINT ezcontentobject_link_pkey TO ibexa_content_relation_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_trash RENAME CONSTRAINT ezcontentobject_trash_pkey TO ibexa_content_trash_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_tree RENAME CONSTRAINT ezcontentobject_tree_pkey TO ibexa_content_tree_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_type RENAME CONSTRAINT ezcontentclass_pkey TO ibexa_content_type_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_type_field_definition
RENAME CONSTRAINT ezcontentclass_attribute_pkey TO ibexa_content_type_field_definition_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_type_field_definition_ml
RENAME CONSTRAINT ezcontentclass_attribute_ml_pkey TO ibexa_content_type_field_definition_ml_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_type_group RENAME CONSTRAINT ezcontentclassgroup_pkey TO ibexa_content_type_group_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_type_group_assignment
RENAME CONSTRAINT ezcontentclass_classgroup_pkey TO ibexa_content_type_group_assignment_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_type_name RENAME CONSTRAINT ezcontentclass_name_pkey TO ibexa_content_type_name_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_content_version RENAME CONSTRAINT ezcontentobject_version_pkey TO ibexa_content_version_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_dfs_file RENAME CONSTRAINT ezdfsfile_pkey TO ibexa_dfs_file_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_image_file RENAME CONSTRAINT ezimagefile_pkey TO ibexa_image_file_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_keyword RENAME CONSTRAINT ezkeyword_pkey TO ibexa_keyword_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_keyword_field_link RENAME CONSTRAINT ezkeyword_attribute_link_pkey TO ibexa_keyword_field_link_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_map_location RENAME CONSTRAINT ezgmaplocation_pkey TO ibexa_map_location_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_media RENAME CONSTRAINT ezmedia_pkey TO ibexa_media_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_node_assignment RENAME CONSTRAINT eznode_assignment_pkey TO ibexa_node_assignment_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_notification RENAME CONSTRAINT eznotification_pkey TO ibexa_notification_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_object_state RENAME CONSTRAINT ezcobj_state_pkey TO ibexa_object_state_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_object_state_group RENAME CONSTRAINT ezcobj_state_group_pkey TO ibexa_object_state_group_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_object_state_group_language
RENAME CONSTRAINT ezcobj_state_group_language_pkey TO ibexa_object_state_group_language_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_object_state_language
RENAME CONSTRAINT ezcobj_state_language_pkey TO ibexa_object_state_language_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_object_state_link RENAME CONSTRAINT ezcobj_state_link_pkey TO ibexa_object_state_link_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_package RENAME CONSTRAINT ezpackage_pkey TO ibexa_package_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_policy RENAME CONSTRAINT ezpolicy_pkey TO ibexa_policy_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_policy_limitation RENAME CONSTRAINT ezpolicy_limitation_pkey TO ibexa_policy_limitation_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_policy_limitation_value
RENAME CONSTRAINT ezpolicy_limitation_value_pkey TO ibexa_policy_limitation_value_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_role RENAME CONSTRAINT ezrole_pkey TO ibexa_role_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_search_object_word_link
RENAME CONSTRAINT ezsearch_object_word_link_pkey TO ibexa_search_object_word_link_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_search_word RENAME CONSTRAINT ezsearch_word_pkey TO ibexa_search_word_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_section RENAME CONSTRAINT ezsection_pkey TO ibexa_section_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_site_data RENAME CONSTRAINT ezsite_data_pkey TO ibexa_site_data_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_url RENAME CONSTRAINT ezurl_pkey TO ibexa_url_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_url_alias RENAME CONSTRAINT ezurlalias_pkey TO ibexa_url_alias_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_url_alias_ml RENAME CONSTRAINT ezurlalias_ml_pkey TO ibexa_url_alias_ml_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_url_alias_ml_incr RENAME CONSTRAINT ezurlalias_ml_incr_pkey TO ibexa_url_alias_ml_incr_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_url_wildcard RENAME CONSTRAINT ezurlwildcard_pkey TO ibexa_url_wildcard_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_user RENAME CONSTRAINT ezuser_pkey TO ibexa_user_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_user_accountkey RENAME CONSTRAINT ezuser_accountkey_pkey TO ibexa_user_accountkey_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_user_preference RENAME CONSTRAINT ezpreferences_pkey TO ibexa_user_preference_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_user_role RENAME CONSTRAINT ezuser_role_pkey TO ibexa_user_role_pkey;
-- ibexa:sql-statement-separator
ALTER TABLE ibexa_user_setting RENAME CONSTRAINT ezuser_setting_pkey TO ibexa_user_setting_pkey;
Loading