Dropping m_survey_scorecardsa and recreating it with correct foreign key relation
This commit is contained in:
+19
-30
@@ -17,33 +17,22 @@
|
|||||||
-- under the License.
|
-- under the License.
|
||||||
--
|
--
|
||||||
|
|
||||||
DROP PROCEDURE IF EXISTS remove_anonymous_fk;
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
DROP TABLE IF EXISTS `m_survey_scorecards`;
|
||||||
DELIMITER $$
|
CREATE TABLE `m_survey_scorecards` (
|
||||||
|
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
|
||||||
CREATE PROCEDURE remove_anonymous_fk (IN referencee VARCHAR(255), IN referenced VARCHAR(255))
|
`survey_id` BIGINT(20) NOT NULL,
|
||||||
BEGIN
|
`question_id` BIGINT(20) NOT NULL,
|
||||||
DECLARE fk2drop VARCHAR(255);
|
`response_id` BIGINT(20) NOT NULL,
|
||||||
|
`user_id` BIGINT(20) NOT NULL,
|
||||||
SELECT
|
`client_id` BIGINT(20) NOT NULL,
|
||||||
CONSTRAINT_NAME
|
`created_on` DATETIME NULL DEFAULT NULL,
|
||||||
FROM
|
`a_value` INT(4) NOT NULL,
|
||||||
INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
PRIMARY KEY (`id`),
|
||||||
WHERE
|
FOREIGN KEY (`survey_id`) REFERENCES `m_surveys` (`id`),
|
||||||
TABLE_NAME = referencee
|
FOREIGN KEY (`question_id`) REFERENCES `m_survey_questions` (`id`),
|
||||||
AND REFERENCED_TABLE_NAME = referenced
|
FOREIGN KEY (`response_id`) REFERENCES `m_survey_responses` (`id`),
|
||||||
INTO fk2drop;
|
FOREIGN KEY (`user_id`) REFERENCES `m_appuser` (`id`),
|
||||||
|
FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`)
|
||||||
SET @alter_stmt = concat('ALTER TABLE ',referencee,' DROP FOREIGN KEY ',fk2drop);
|
);
|
||||||
PREPARE pstmt FROM @alter_stmt;
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
EXECUTE pstmt;
|
|
||||||
DEALLOCATE PREPARE pstmt;
|
|
||||||
END $$
|
|
||||||
|
|
||||||
DELIMITER ;
|
|
||||||
|
|
||||||
CALL remove_anonymous_fk('m_survey_scorecards', 'm_appusers');
|
|
||||||
|
|
||||||
ALTER TABLE `m_survey_scorecards` ADD FOREIGN KEY `m_appuser` (`user_id`);
|
|
||||||
|
|
||||||
DROP PROCEDURE IF EXISTS remove_anonymous_fk;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user