Skip to content

Instantly share code, notes, and snippets.

View hashir-dhattiwala's full-sized avatar

Hashir hashir-dhattiwala

  • Perception
  • Ahmedabad
View GitHub Profile
@hashir-dhattiwala
hashir-dhattiwala / mage-constraints.sql
Created July 27, 2016 04:53 — forked from cgdangelo/mage-constraints.sql
Recreate foreign keys for a Magento installation, after you fire the idiot who deleted all of them.
# one-liner for generating this: mysqldump --no-data -uroot magento1600 | nawk '{if(match($0, /CREATE TABLE `(.*)`/, matchesT)) { the_table = matchesT[1]; } if(match($0, /(CONSTRAINT .*),?/, matchesK) && the_table) { the_key = gensub(/,?$/, "", matchesK[1]); the_key = gensub(/^ */, "", the_key); print "ALTER TABLE `" the_table "` ADD", the_key ";"; }}'
ALTER TABLE `admin_rule` ADD CONSTRAINT `FK_ADMIN_RULE_ROLE_ID_ADMIN_ROLE_ROLE_ID` FOREIGN KEY (`role_id`) REFERENCES `admin_role` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `api_rule` ADD CONSTRAINT `FK_API_RULE_ROLE_ID_API_ROLE_ROLE_ID` FOREIGN KEY (`role_id`) REFERENCES `api_role` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `api_session` ADD CONSTRAINT `FK_API_SESSION_USER_ID_API_USER_USER_ID` FOREIGN KEY (`user_id`) REFERENCES `api_user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `catalog_category_entity_datetime` ADD CONSTRAINT `FK_CAT_CTGR_ENTT_DTIME_ATTR_ID_EAV_ATTR_ATTR_ID` FOREIGN KEY (`attribute_id