impfwarteliste angepasst
This commit is contained in:
@@ -17,6 +17,7 @@ FROM (
|
||||
UNION ALL SELECT 'impfstoff_wochenplan'
|
||||
UNION ALL SELECT 'impf_zeitraum'
|
||||
UNION ALL SELECT 'impf_zeitraum_impfstoff'
|
||||
UNION ALL SELECT 'warteliste_zeitraum'
|
||||
UNION ALL SELECT 'warteliste'
|
||||
) t
|
||||
LEFT JOIN information_schema.tables it
|
||||
@@ -51,6 +52,9 @@ FROM (
|
||||
UNION ALL SELECT 'impf_zeitraum', 'impfortid'
|
||||
UNION ALL SELECT 'impf_zeitraum_impfstoff', 'zeitraum_id'
|
||||
UNION ALL SELECT 'impf_zeitraum_impfstoff', 'impfstoff_id'
|
||||
UNION ALL SELECT 'warteliste_zeitraum', 'warteid'
|
||||
UNION ALL SELECT 'warteliste_zeitraum', 'zeitraum_id'
|
||||
UNION ALL SELECT 'warteliste_zeitraum', 'created_at'
|
||||
UNION ALL SELECT 'warteliste', 'warteid'
|
||||
UNION ALL SELECT 'warteliste', 'userid'
|
||||
UNION ALL SELECT 'warteliste', 'impfenzeitraum'
|
||||
@@ -71,6 +75,7 @@ SELECT
|
||||
END AS status
|
||||
FROM (
|
||||
SELECT 'warteliste' AS table_name, 'idx_warteliste_zeitraum' AS index_name
|
||||
UNION ALL SELECT 'warteliste_zeitraum', 'idx_warteliste_zeitraum_zeitraum'
|
||||
UNION ALL SELECT 'impfstoff_wochenplan', 'idx_impfstoff_wochenplan_impfstoff'
|
||||
UNION ALL SELECT 'impfstoff_wochenplan', 'idx_impfstoff_wochenplan_wochentag'
|
||||
UNION ALL SELECT 'impf_zeitraum', 'idx_impf_zeitraum_wochentag'
|
||||
@@ -102,6 +107,24 @@ SELECT
|
||||
ELSE 'TABLE_MISSING'
|
||||
END AS status;
|
||||
|
||||
SELECT
|
||||
'meta' AS check_type,
|
||||
'impf_workflow_meta.legacy_warteliste_zeitraeume_migrated' AS object_name,
|
||||
CASE
|
||||
WHEN EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = 'impf_workflow_meta'
|
||||
) THEN COALESCE((
|
||||
SELECT CONCAT('VALUE=', meta_value)
|
||||
FROM impf_workflow_meta
|
||||
WHERE meta_key = 'legacy_warteliste_zeitraeume_migrated'
|
||||
LIMIT 1
|
||||
), 'MISSING')
|
||||
ELSE 'TABLE_MISSING'
|
||||
END AS status;
|
||||
|
||||
SELECT
|
||||
'data' AS check_type,
|
||||
'impfstoff_wochenplan rows' AS object_name,
|
||||
@@ -154,3 +177,16 @@ SELECT
|
||||
) THEN CAST((SELECT COUNT(*) FROM warteliste WHERE zeitraum_id IS NOT NULL) AS CHAR)
|
||||
ELSE 'COLUMN_MISSING'
|
||||
END AS status;
|
||||
|
||||
SELECT
|
||||
'data' AS check_type,
|
||||
'warteliste_zeitraum rows' AS object_name,
|
||||
CASE
|
||||
WHEN EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = 'warteliste_zeitraum'
|
||||
) THEN CAST((SELECT COUNT(*) FROM warteliste_zeitraum) AS CHAR)
|
||||
ELSE 'TABLE_MISSING'
|
||||
END AS status;
|
||||
|
||||
@@ -51,6 +51,14 @@ CREATE TABLE IF NOT EXISTS `impf_zeitraum_impfstoff` (
|
||||
INDEX `idx_impf_zeitraum_impfstoff_impfstoff` (`impfstoff_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `warteliste_zeitraum` (
|
||||
`warteid` INT NOT NULL,
|
||||
`zeitraum_id` INT NOT NULL,
|
||||
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`warteid`, `zeitraum_id`),
|
||||
INDEX `idx_warteliste_zeitraum_zeitraum` (`zeitraum_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
DROP PROCEDURE IF EXISTS `migrate_praxis_schema_20260320`;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE `migrate_praxis_schema_20260320`()
|
||||
@@ -60,6 +68,8 @@ BEGIN
|
||||
DECLARE v_warteliste_exists INT DEFAULT 0;
|
||||
DECLARE v_zeitraum_id_exists INT DEFAULT 0;
|
||||
DECLARE v_warteliste_index_exists INT DEFAULT 0;
|
||||
DECLARE v_warteliste_zeitraum_exists INT DEFAULT 0;
|
||||
DECLARE v_warteliste_zeitraum_index_exists INT DEFAULT 0;
|
||||
DECLARE v_legacy_plan_exists INT DEFAULT 0;
|
||||
|
||||
SELECT COUNT(*)
|
||||
@@ -114,6 +124,35 @@ BEGIN
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*)
|
||||
INTO v_warteliste_zeitraum_exists
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = 'warteliste_zeitraum';
|
||||
|
||||
IF v_warteliste_zeitraum_exists = 0 THEN
|
||||
CREATE TABLE `warteliste_zeitraum` (
|
||||
`warteid` INT NOT NULL,
|
||||
`zeitraum_id` INT NOT NULL,
|
||||
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`warteid`, `zeitraum_id`),
|
||||
INDEX `idx_warteliste_zeitraum_zeitraum` (`zeitraum_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
SET v_warteliste_zeitraum_exists = 1;
|
||||
ELSE
|
||||
SELECT COUNT(*)
|
||||
INTO v_warteliste_zeitraum_index_exists
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = 'warteliste_zeitraum'
|
||||
AND index_name = 'idx_warteliste_zeitraum_zeitraum';
|
||||
|
||||
IF v_warteliste_zeitraum_index_exists = 0 THEN
|
||||
ALTER TABLE `warteliste_zeitraum`
|
||||
ADD INDEX `idx_warteliste_zeitraum_zeitraum` (`zeitraum_id`);
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*)
|
||||
INTO v_legacy_plan_exists
|
||||
FROM information_schema.tables
|
||||
@@ -159,6 +198,18 @@ BEGIN
|
||||
VALUES ('legacy_wochenplan_migrated', '1') AS `incoming`
|
||||
ON DUPLICATE KEY UPDATE `meta_value` = `incoming`.`meta_value`;
|
||||
END IF;
|
||||
|
||||
IF v_warteliste_exists > 0 AND v_warteliste_zeitraum_exists > 0 THEN
|
||||
INSERT IGNORE INTO `warteliste_zeitraum` (`warteid`, `zeitraum_id`)
|
||||
SELECT `warteid`, `zeitraum_id`
|
||||
FROM `warteliste`
|
||||
WHERE `zeitraum_id` IS NOT NULL
|
||||
AND `zeitraum_id` > 0;
|
||||
|
||||
INSERT INTO `impf_workflow_meta` (`meta_key`, `meta_value`)
|
||||
VALUES ('legacy_warteliste_zeitraeume_migrated', '1') AS `incoming`
|
||||
ON DUPLICATE KEY UPDATE `meta_value` = `incoming`.`meta_value`;
|
||||
END IF;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
-- Migration fuer Mehrfach-Zeitfenster in der Impfwarteliste.
|
||||
-- Idempotent: kann mehrfach ausgefuehrt werden.
|
||||
-- Bestehende Tabellen werden nicht neu aufgebaut, sondern nur erweitert.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `impf_workflow_meta` (
|
||||
`meta_key` VARCHAR(100) NOT NULL,
|
||||
`meta_value` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`meta_key`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
DROP PROCEDURE IF EXISTS `migrate_warteliste_multi_zeitfenster_20260322`;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE `migrate_warteliste_multi_zeitfenster_20260322`()
|
||||
BEGIN
|
||||
DECLARE v_warteliste_exists INT DEFAULT 0;
|
||||
DECLARE v_zeitraum_id_exists INT DEFAULT 0;
|
||||
DECLARE v_warteliste_index_exists INT DEFAULT 0;
|
||||
DECLARE v_warteliste_zeitraum_exists INT DEFAULT 0;
|
||||
DECLARE v_warteliste_zeitraum_index_exists INT DEFAULT 0;
|
||||
|
||||
SELECT COUNT(*)
|
||||
INTO v_warteliste_exists
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = 'warteliste';
|
||||
|
||||
IF v_warteliste_exists = 0 THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'Tabelle warteliste wurde nicht gefunden.';
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*)
|
||||
INTO v_zeitraum_id_exists
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = 'warteliste'
|
||||
AND column_name = 'zeitraum_id';
|
||||
|
||||
IF v_zeitraum_id_exists = 0 THEN
|
||||
ALTER TABLE `warteliste`
|
||||
ADD COLUMN `zeitraum_id` INT NULL AFTER `impfenzeitraum`;
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*)
|
||||
INTO v_warteliste_index_exists
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = 'warteliste'
|
||||
AND index_name = 'idx_warteliste_zeitraum';
|
||||
|
||||
IF v_warteliste_index_exists = 0 THEN
|
||||
ALTER TABLE `warteliste`
|
||||
ADD INDEX `idx_warteliste_zeitraum` (`zeitraum_id`);
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*)
|
||||
INTO v_warteliste_zeitraum_exists
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = 'warteliste_zeitraum';
|
||||
|
||||
IF v_warteliste_zeitraum_exists = 0 THEN
|
||||
CREATE TABLE `warteliste_zeitraum` (
|
||||
`warteid` INT NOT NULL,
|
||||
`zeitraum_id` INT NOT NULL,
|
||||
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`warteid`, `zeitraum_id`),
|
||||
INDEX `idx_warteliste_zeitraum_zeitraum` (`zeitraum_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
SET v_warteliste_zeitraum_exists = 1;
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*)
|
||||
INTO v_warteliste_zeitraum_index_exists
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = 'warteliste_zeitraum'
|
||||
AND index_name = 'idx_warteliste_zeitraum_zeitraum';
|
||||
|
||||
IF v_warteliste_zeitraum_index_exists = 0 THEN
|
||||
ALTER TABLE `warteliste_zeitraum`
|
||||
ADD INDEX `idx_warteliste_zeitraum_zeitraum` (`zeitraum_id`);
|
||||
END IF;
|
||||
|
||||
INSERT IGNORE INTO `warteliste_zeitraum` (`warteid`, `zeitraum_id`)
|
||||
SELECT `warteid`, `zeitraum_id`
|
||||
FROM `warteliste`
|
||||
WHERE `zeitraum_id` IS NOT NULL
|
||||
AND `zeitraum_id` > 0;
|
||||
|
||||
INSERT INTO `impf_workflow_meta` (`meta_key`, `meta_value`)
|
||||
VALUES ('legacy_warteliste_zeitraeume_migrated', '1') AS `incoming`
|
||||
ON DUPLICATE KEY UPDATE `meta_value` = `incoming`.`meta_value`;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
CALL `migrate_warteliste_multi_zeitfenster_20260322`();
|
||||
DROP PROCEDURE IF EXISTS `migrate_warteliste_multi_zeitfenster_20260322`;
|
||||
Reference in New Issue
Block a user