Fix foreign key violation (#331)
This commit is contained in:
parent
2cdae3f45c
commit
28975d4625
3 changed files with 24 additions and 4 deletions
|
@ -23,7 +23,7 @@
|
|||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for customcert"/>
|
||||
<KEY NAME="template" TYPE="foreign" FIELDS="templateid" REFTABLE="customcert_template" REFFIELDS="id"/>
|
||||
<KEY NAME="template" TYPE="foreign" FIELDS="templateid" REFTABLE="customcert_templates" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="customcert_templates" COMMENT="Stores each customcert template">
|
||||
|
@ -67,7 +67,7 @@
|
|||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for customcert_pages"/>
|
||||
<KEY NAME="template" TYPE="foreign" FIELDS="templateid" REFTABLE="customcert_template" REFFIELDS="id"/>
|
||||
<KEY NAME="template" TYPE="foreign" FIELDS="templateid" REFTABLE="customcert_templates" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="customcert_elements" COMMENT="Stores the elements for a given page">
|
||||
|
|
|
@ -146,5 +146,25 @@ function xmldb_customcert_upgrade($oldversion) {
|
|||
upgrade_mod_savepoint(true, 2018051705, 'customcert');
|
||||
}
|
||||
|
||||
if ($oldversion < 2019111803) {
|
||||
$table = new xmldb_table('customcert');
|
||||
$index = new xmldb_index('templateid', XMLDB_INDEX_UNIQUE, ['templateid']);
|
||||
if ($dbman->index_exists($table, $index)) {
|
||||
$dbman->drop_index($table, $index);
|
||||
}
|
||||
$key = new xmldb_key('templateid', XMLDB_KEY_FOREIGN, array('templateid'), 'customcert_templates', array('id'));
|
||||
$dbman->add_key($table, $key);
|
||||
|
||||
$table = new xmldb_table('customcert_pages');
|
||||
$index = new xmldb_index('templateid', XMLDB_INDEX_UNIQUE, ['templateid']);
|
||||
if ($dbman->index_exists($table, $index)) {
|
||||
$dbman->drop_index($table, $index);
|
||||
}
|
||||
$key = new xmldb_key('templateid', XMLDB_KEY_FOREIGN, array('templateid'), 'customcert_templates', array('id'));
|
||||
$dbman->add_key($table, $key);
|
||||
|
||||
upgrade_mod_savepoint(true, 2019111803, 'customcert');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue