Added short name to benchmarks

This commit is contained in:
ivan-pelly
2026-03-14 18:54:28 -07:00
parent f431fb3e94
commit 242b1bce27
21 changed files with 227 additions and 22 deletions
@@ -0,0 +1,94 @@
-- =====================================================================
-- Migration: Add short_name column to benchmark table and update
-- all benchmark stored procedures to support it.
-- Run in TablePlus against MySQL.
-- =====================================================================
-- 1. Add the column
ALTER TABLE `benchmark`
ADD COLUMN `short_name` VARCHAR(50) DEFAULT NULL AFTER `benchmark`;
-- 2. Recreate sp_Benchmark_GetByStudentId
DROP PROCEDURE IF EXISTS `sp_Benchmark_GetByStudentId`;
CREATE PROCEDURE `sp_Benchmark_GetByStudentId`(IN p_id_student CHAR(36))
BEGIN
SELECT
s.`identifier` AS `studentIdentifier`,
b.`id_benchmark` AS `benchmarkId`,
b.`id_goal` AS `goalId`,
g.`category` AS `goalCategory`,
b.`benchmark` AS `benchmark`,
b.`short_name` AS `shortName`,
u.`name` AS `createdByName`,
b.`created_at` AS `createdAt`,
b.`updated_at` AS `updatedAt`
FROM `benchmark` b
INNER JOIN `goal` g ON g.`id_goal` = b.`id_goal`
INNER JOIN `student` s ON s.`id_student` = g.`id_student`
LEFT JOIN `user` u ON u.`id_user` = b.`id_user_created`
WHERE g.`id_student` = p_id_student
ORDER BY b.`created_at` DESC;
END;
-- 3. Recreate sp_Benchmark_Insert
DROP PROCEDURE IF EXISTS `sp_Benchmark_Insert`;
CREATE PROCEDURE `sp_Benchmark_Insert`(
IN p_id_benchmark CHAR(36),
IN p_id_goal CHAR(36),
IN p_id_user_created CHAR(36),
IN p_benchmark TEXT,
IN p_short_name VARCHAR(50)
)
BEGIN
INSERT INTO benchmark
(
id_benchmark,
id_goal,
id_user_created,
benchmark,
short_name,
created_at,
updated_at
)
VALUES
(
p_id_benchmark,
p_id_goal,
p_id_user_created,
p_benchmark,
p_short_name,
UTC_TIMESTAMP(),
NULL
);
SELECT
id_benchmark,
id_goal,
id_user_created,
benchmark,
short_name,
created_at,
updated_at
FROM benchmark
WHERE id_benchmark = p_id_benchmark
LIMIT 1;
END;
-- 4. Recreate sp_Benchmark_Update
DROP PROCEDURE IF EXISTS `sp_Benchmark_Update`;
CREATE PROCEDURE `sp_Benchmark_Update`(
IN p_id_benchmark CHAR(36),
IN p_benchmark TEXT,
IN p_short_name VARCHAR(50)
)
BEGIN
UPDATE benchmark
SET
benchmark = p_benchmark,
short_name = p_short_name,
updated_at = UTC_TIMESTAMP()
WHERE id_benchmark = p_id_benchmark;
SELECT ROW_COUNT() AS rowsAffected;
END;
@@ -7,6 +7,7 @@ BEGIN
b.`id_goal` AS `goalId`,
g.`category` AS `goalCategory`,
b.`benchmark` AS `benchmark`,
b.`short_name` AS `shortName`,
u.`name` AS `createdByName`,
b.`created_at` AS `createdAt`,
b.`updated_at` AS `updatedAt`
@@ -3,7 +3,8 @@ CREATE DEFINER=`root`@`%` PROCEDURE `sp_Benchmark_Insert`(
IN p_id_benchmark CHAR(36),
IN p_id_goal CHAR(36),
IN p_id_user_created CHAR(36),
IN p_benchmark TEXT
IN p_benchmark TEXT,
IN p_short_name VARCHAR(50)
)
BEGIN
INSERT INTO benchmark
@@ -12,6 +13,7 @@ BEGIN
id_goal,
id_user_created,
benchmark,
short_name,
created_at,
updated_at
)
@@ -21,6 +23,7 @@ BEGIN
p_id_goal,
p_id_user_created,
p_benchmark,
p_short_name,
UTC_TIMESTAMP(),
NULL
);
@@ -29,6 +32,7 @@ BEGIN
id_goal,
id_user_created,
benchmark,
short_name,
created_at,
updated_at
FROM benchmark
@@ -1,12 +1,14 @@
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sp_Benchmark_Update`(
IN p_id_benchmark CHAR(36),
IN p_benchmark TEXT
IN p_benchmark TEXT,
IN p_short_name VARCHAR(50)
)
BEGIN
UPDATE benchmark
SET
benchmark = p_benchmark,
short_name = p_short_name,
updated_at = UTC_TIMESTAMP()
WHERE id_benchmark = p_id_benchmark;
SELECT ROW_COUNT() AS rowsAffected;
+1
View File
@@ -3,6 +3,7 @@ CREATE TABLE `benchmark` (
`id_goal` char(36) NOT NULL,
`id_user_created` char(36) NOT NULL,
`benchmark` text NOT NULL,
`short_name` varchar(50) DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id_benchmark`)
+5 -3
View File
@@ -1,7 +1,9 @@
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `winstudentgoaltracker`.`v_student_card` AS
select `s`.`id_student` AS `studentId`,`s`.`identifier` AS `identifier`,`s`.`next_iep_date` AS `nextIepDate`,max(`pe`.`created_at`) AS `lastEntryDate`,count(distinct `g`.`id_goal`) AS `goalCount`,count(distinct `pe`.`id_progress_event`) AS `progressEventCount`
from ((`winstudentgoaltracker`.`student` `s`
select `s`.`id_student` AS `studentId`,`s`.`identifier` AS `identifier`,`s`.`next_iep_date` AS `nextIepDate`,max(`pe`.`created_at`) AS `lastEntryDate`,count(distinct `g`.`id_goal`) AS `goalCount`,count(distinct `pe`.`id_progress_event`) AS `progressEventCount`,count(distinct `b`.`id_benchmark`) AS `benchmarkCount`
from (((`winstudentgoaltracker`.`student` `s`
left
join `winstudentgoaltracker`.`goal` `g` on((`g`.`id_student` = `s`.`id_student`)))
left
join `winstudentgoaltracker`.`progress_event` `pe` on((`pe`.`id_goal` = `g`.`id_goal`))) group by `s`.`id_student`,`s`.`identifier`,`s`.`next_iep_date`;
join `winstudentgoaltracker`.`progress_event` `pe` on((`pe`.`id_goal` = `g`.`id_goal`)))
left
join `winstudentgoaltracker`.`benchmark` `b` on((`b`.`id_goal` = `g`.`id_goal`))) group by `s`.`id_student`,`s`.`identifier`,`s`.`next_iep_date`;