mirror of https://github.com/sipwise/db-schema.git
This reverts commit 1631573453
.
The script is actually a one-time only script, no need to re-execute
it again, instead it fails to run due to:
| Applying revision script /usr/share/ngcp-db-schema/db_scripts/diff/15743.up: ERROR 1050 (42S01) at line 4: Table 'autoprov_firmwares_data' already exists
| failed. :(
Change-Id: I75ea1a0ce86064113032844a9ff4fc8a2b0af7cd
mr11.2
parent
1631573453
commit
32bdc69702
@ -1,58 +0,0 @@
|
||||
USE provisioning;
|
||||
SET autocommit=0;
|
||||
|
||||
CREATE TABLE `autoprov_firmwares_data` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
fw_id int(11) unsigned NOT NULL,
|
||||
`data` longblob NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `afd_fw_id_idx` (`fw_id`),
|
||||
CONSTRAINT `fk_fw_idx` FOREIGN KEY (`fw_id`) REFERENCES `autoprov_firmwares` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
DROP PROCEDURE split_autoprov_firmware_data;
|
||||
DELIMITER ;;
|
||||
CREATE PROCEDURE split_autoprov_firmware_data()
|
||||
BEGIN
|
||||
|
||||
DECLARE n_fw_id, chunk_size, off_set int;
|
||||
DECLARE chunk longblob;
|
||||
DECLARE done int DEFAULT FALSE;
|
||||
|
||||
DECLARE x CURSOR FOR SELECT id FROM autoprov_firmwares ORDER BY id ASC;
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
|
||||
|
||||
SET chunk_size = 10485760;
|
||||
SET off_set = 1;
|
||||
|
||||
OPEN x;
|
||||
x_main: LOOP
|
||||
FETCH x INTO n_fw_id;
|
||||
IF done THEN
|
||||
LEAVE x_main;
|
||||
END IF;
|
||||
SET off_set = 1;
|
||||
x_chunk: LOOP
|
||||
SELECT substr(data, off_set, chunk_size) INTO chunk
|
||||
FROM autoprov_firmwares
|
||||
WHERE id = n_fw_id;
|
||||
IF LENGTH(chunk) > 0 THEN
|
||||
INSERT INTO autoprov_firmwares_data (fw_id, data)
|
||||
VALUES (n_fw_id, chunk);
|
||||
SET off_set = off_set+chunk_size;
|
||||
ELSE
|
||||
LEAVE x_chunk;
|
||||
END IF;
|
||||
END LOOP;
|
||||
END LOOP;
|
||||
CLOSE x;
|
||||
|
||||
END;;
|
||||
DELIMITER ;
|
||||
|
||||
CALL split_autoprov_firmware_data;
|
||||
DROP PROCEDURE split_autoprov_firmware_data;
|
||||
|
||||
ALTER TABLE autoprov_firmwares DROP data;
|
||||
|
||||
COMMIT;
|
Loading…
Reference in new issue