Skip to content

Commit 5b45c87

Browse files
fulldecentmdjnelson
authored andcommitted
Add unique index for code column (#666)
1 parent 339e804 commit 5b45c87

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

db/install.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
</KEYS>
5858
<INDEXES>
5959
<INDEX NAME="userid-customcertid" UNIQUE="false" FIELDS="userid, customcertid"/>
60+
<INDEX NAME="code" UNIQUE="true" FIELDS="code"/>
6061
</INDEXES>
6162
</TABLE>
6263
<TABLE NAME="customcert_pages" COMMENT="Stores each page of a custom cert">

db/upgrade.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,5 +298,19 @@ function xmldb_customcert_upgrade($oldversion) {
298298
upgrade_mod_savepoint(true, 2024042205, 'customcert');
299299
}
300300

301+
// Define the new unique index for the 'code' column.
302+
if ($oldversion < 2024042209) {
303+
$table = new xmldb_table('customcert_issues');
304+
$index = new xmldb_index('code', XMLDB_INDEX_UNIQUE, ['code']);
305+
306+
// Check if an index exists before adding.
307+
if (!$dbman->index_exists($table, $index)) {
308+
$dbman->add_index($table, $index);
309+
}
310+
311+
// Update the plugin version in the database.
312+
upgrade_plugin_savepoint(true, 2024042209, 'mod', 'customcert');
313+
}
314+
301315
return true;
302316
}

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

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

27-
$plugin->version = 2024042208; // The current module version (Date: YYYYMMDDXX).
27+
$plugin->version = 2024042209; // The current module version (Date: YYYYMMDDXX).
2828
$plugin->requires = 2024042200; // Requires this Moodle version (4.4).
2929
$plugin->cron = 0; // Period for cron to check this module (secs).
3030
$plugin->component = 'mod_customcert';

0 commit comments

Comments
 (0)