Skip to content

Questions: Create Unique Index Without MariaDB-Only Syntax - #12334

Open
chfsx wants to merge 1 commit into
ILIAS-eLearning:trunkfrom
srsolutionsag:fix-questions-mysql-unique-index
Open

chfsx wants to merge 1 commit into
ILIAS-eLearning:trunkfrom
srsolutionsag:fix-questions-mysql-unique-index

Conversation

@chfsx

@chfsx chfsx commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

The nightly installation check on trunk fails since the Questions component has been merged (last green run on 2026-10-27, failing since 2026-10-28), e.g.: https://github.com/ILIAS-eLearning/ILIAS/actions/runs/41098473993/job/124210302027

Database update steps in ILIAS\Questions\Setup\OverarchingQuestionTables....[FAILED]
[ERROR] An undefined Database Exception occured. SQLSTATE[42000]: Syntax error
        or access violation: 1064 You have an error in your SQL syntax; ...
        QUERY: CREATE UNIQUE INDEX IF NOT EXISTS apc_idx ON qsts_text_feedback_specific
        (`answer_form_id`, `parent_id`, `condition`)

CREATE INDEX IF NOT EXISTS is MariaDB-only syntax, MySQL does not support it (the workflow runs on MySQL).

Why no plain SQL for schema changes: ILIAS officially supports both MySQL (8.4 - 9.7) and MariaDB (11.4 - 12.3), see docs/configuration/install.md. The two have diverged in their DDL dialects, and CREATE INDEX IF NOT EXISTS is one of these differences. Schema changes in database update steps are therefore abstracted by ilDBInterface; the Database README states that "only the following $ilDB methods may be used, to create, modify and delete tables in the database update script" (createTable(), addPrimaryKey(), addIndex(), addUniqueConstraint(), ...). Besides keeping the statements portable, these methods quote identifiers (relevant here, since condition is a reserved word in MySQL and MariaDB) and apply ILIAS' naming conventions and checks for indices and constraints (_idx suffix, checkIndexName()).

This PR replaces the raw statement in OverarchingQuestionTables::step_7() with ilDBInterface::addUniqueConstraint(), which creates the same apc_idx with quoted identifiers. To keep the step repeatable, it first checks for an existing unique constraint on these fields via ilDBAnalyzer (passing the DB explicitly instead of relying on the global $DIC, which uniqueConstraintExists() would do). Installations that already ran the step on MariaDB are not affected.

The follow-up error in the same run (Add new admin node to tree (type=qsts;title=Questions)... Identifier "logging.config" is not defined.) is most likely a consequence of the failed update steps; this has to be confirmed by the next run of the installation check.

CREATE INDEX IF NOT EXISTS is not supported by MySQL and breaks the
installation (install-check-trunk-8.5). Use addUniqueConstraint() and
check for an existing constraint via ilDBAnalyzer instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants