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

[REF] Mapping - Check FK on delete with SQL instead of PHP (dev/core#2757) #21198

Merged
merged 1 commit into from
Sep 10, 2021

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Aug 20, 2021

Overview

Part of an ongoing effort to clean up the DAO classes and use generic functions and events.

Before

For some reason, a php function was mimicking ON DELETE CASCADE in mySql.

After

Uses actual ON DELETE CASCADE in mySql.

Comments

The only reason I can fathom to do it in PHP rather than in SQL is to call pre and post hooks... which this wasn't.

@civibot
Copy link

civibot bot commented Aug 20, 2021

(Standard links)

@civibot civibot bot added the master label Aug 20, 2021
@colemanw colemanw changed the title Mapping - Check FK on delete with SQL instead of with PHP Mapping - Check FK on delete with SQL instead of PHP Aug 20, 2021
@colemanw colemanw changed the title Mapping - Check FK on delete with SQL instead of PHP [REF] Mapping - Check FK on delete with SQL instead of PHP (dev/core#2757) Aug 22, 2021
@@ -1 +1,5 @@
{* file to handle db changes in 5.42.alpha1 during upgrade *}

ALTER TABLE `civicrm_mapping_field` DROP FOREIGN KEY `FK_civicrm_mapping_field_mapping_id`;
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton Aug 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 I'm getting confused here - we use CRM_Core_BAO_SchemaHandler::safeRemoveFK(...) to drop the fk I think but ?? to add one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use this

public static function buildForeignKeySQL($params, $separator, $prefix, $tableName) {
but still not perfect

@colemanw
Copy link
Member Author

@eileenmcnaughton @seamuslee001 does this PR require a schema regen?

@seamuslee001
Copy link
Contributor

@colemanw whilst you looking at mapping I'm wondering if we need to modify this https://github.com/civicrm/civicrm-core/blob/master/xml/schema/Contact/SavedSearch.xml#L82 at all

@colemanw
Copy link
Member Author

@seamuslee001 why would we need to modify it?

@seamuslee001
Copy link
Contributor

@colemanw should it be cascade delete also rather than set null?

@eileenmcnaughton
Copy link
Contributor

@colemanw I've pushed up changes to the upgrade script as discussed above

I tested locally upgrading from 5.42 to 5.43 with this version of the upgrade script
I think deleted a Mapping using api explorer (v4) and checked the fields were deleted - all good IMHO

I think @seamuslee001's question about search kit fk on mapping_id is out of scope - from memory it is used in search builder context and I have a feeling there might be some complications in answering the question about whether it should delete on cascade so it's not something we could 'quickly do while we are at it'

This is mergeable now IMHO, Since I altered it I'm added 'merge-ready' not 'merge-on-pass'

@eileenmcnaughton eileenmcnaughton added the merge ready PR will be merged after a few days if there are no objections label Sep 6, 2021
@colemanw
Copy link
Member Author

colemanw commented Sep 6, 2021

Thanks @eileenmcnaughton - this looks good except is this one of those situations where regen.sh has to be run and new sql install files committed?

@eileenmcnaughton
Copy link
Contributor

I don't think it does

@colemanw colemanw added merge on pass and removed merge ready PR will be merged after a few days if there are no objections labels Sep 10, 2021
@colemanw
Copy link
Member Author

In that case this is good to go

@eileenmcnaughton eileenmcnaughton merged commit fa18817 into civicrm:master Sep 10, 2021
@colemanw colemanw deleted the fkConstraint branch September 10, 2021 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants