Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique index for code column #667

Open
wants to merge 1 commit into
base: MOODLE_404_STABLE
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
</KEYS>
<INDEXES>
<INDEX NAME="userid-customcertid" UNIQUE="false" FIELDS="userid, customcertid"/>
<INDEX NAME="code" UNIQUE="true" FIELDS="code"/>
</INDEXES>
</TABLE>
<TABLE NAME="customcert_pages" COMMENT="Stores each page of a custom cert">
Expand Down
13 changes: 13 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,18 @@ function xmldb_customcert_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2024042205, 'customcert');
}

// Define the new unique index for the 'code' column.
if ($oldversion < 2025030300) {
$table = new xmldb_table('customcert_issues');
$index = new xmldb_index('code', XMLDB_INDEX_UNIQUE, ['code']);

// Check if an index exists before adding.
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}

// Update the plugin version in the database.
upgrade_plugin_savepoint(true, 2025030300, 'mod', 'customcert');
}
return true;
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');

$plugin->version = 2024042208; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2025030300; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2024042200; // Requires this Moodle version (4.4).
$plugin->cron = 0; // Period for cron to check this module (secs).
$plugin->component = 'mod_customcert';
Expand Down