384
370
CREATE TRIGGER testrun_insert_after_trigger
385
BEFORE INSERT ON testrun
371
AFTER INSERT ON testrun
387
373
EXECUTE PROCEDURE testrun_insert_after()
376
CREATE FUNCTION testrun_update_before() RETURNS TRIGGER
380
IF OLD.distro_series <> NEW.distro_series THEN
381
RAISE EXCEPTION 'Cannot update distro_series';
382
ELSIF OLD.project_series <> NEW.project_series THEN
383
RAISE EXCEPTION 'Cannot update project_series';
384
ELSIF OLD.date_created <> NEW.date_created THEN
385
RAISE EXCEPTION 'Cannot update project_series';
394
ON FUNCTION testrun_update_before()
398
CREATE TRIGGER testrun_update_before_trigger
399
BEFORE UPDATE ON testrun
401
EXECUTE PROCEDURE testrun_update_before()
404
CREATE FUNCTION testrun_delete_after() RETURNS TRIGGER
414
WHERE testrun.date_created > OLD.date_created
415
AND CASE WHEN OLD.distro_series IS NOT NULL THEN
416
testrun.distro_series = OLD.distro_series
418
testrun.project_series = OLD.project_series
420
ORDER BY testrun.date_created ASC LIMIT 1;
423
IF next_testrun.date_created IS NOT NULL THEN
424
UPDATE testresult tr1
425
SET date_deleted = tr2.date_deleted
426
FROM testresult tr2, testcase tc
427
WHERE tr1.test_case = tr2.test_case
428
AND tr1.status = tr2.status
429
AND decode(md5(tr1.output), 'hex') = decode(md5(tr2.output), 'hex')
430
AND tr1.date_deleted = OLD.date_created
431
AND tr2.date_created = next_testrun.date_created
432
AND tr1.test_case = tc.id
433
AND CASE WHEN OLD.distro_series IS NOT NULL THEN
434
tc.distro_series = OLD.distro_series
436
tc.project_series = OLD.project_series
439
DELETE FROM testresult tr2
440
USING testresult tr1, testcase tc
442
tr1.test_case = tr2.test_case
443
AND tr1.status = tr2.status
444
AND decode(md5(tr1.output), 'hex')
445
= decode(md5(tr2.output), 'hex')
446
AND tr2.date_created = next_testrun.date_created)
448
tr2.date_created = OLD.date_created
449
AND tr2.date_deleted = next_testrun.date_created)
450
AND tr1.test_case = tc.id
451
AND CASE WHEN OLD.distro_series IS NOT NULL THEN
452
tc.distro_series = OLD.distro_series
454
tc.project_series = OLD.project_series
457
DELETE FROM testresult tr
459
WHERE tr.date_created = OLD.date_created
460
AND tr.date_deleted = next_testrun.date_created
461
AND tr.test_case = tc.id
462
AND CASE WHEN OLD.distro_series IS NOT NULL THEN
463
tc.distro_series = OLD.distro_series
465
tc.project_series = OLD.project_series
471
SET date_created = next_testrun.date_created
473
WHERE tr.date_created = OLD.date_created
474
AND tr.test_case = testcase.id
475
AND CASE WHEN OLD.distro_series IS NOT NULL THEN
476
testcase.distro_series = OLD.distro_series
478
testcase.project_series = OLD.project_series
481
next_testrun.date_created = '3000-01-01';
482
DELETE FROM testresult tr
484
WHERE tr.date_created = OLD.date_created
485
AND tr.test_case = tc.id
486
AND CASE WHEN OLD.distro_series IS NOT NULL THEN
487
tc.distro_series = OLD.distro_series
489
tc.project_series = OLD.project_series
495
SET date_deleted = next_testrun.date_created
497
WHERE tr.date_deleted = OLD.date_created
498
AND tr.test_case = tc.id
499
AND CASE WHEN OLD.distro_series IS NOT NULL THEN
500
tc.distro_series = OLD.distro_series
502
tc.project_series = OLD.project_series
511
ON FUNCTION testrun_delete_after()
515
CREATE TRIGGER testrun_delete_after_trigger
516
AFTER DELETE ON testrun
518
EXECUTE PROCEDURE testrun_delete_after()
390
521
CREATE FUNCTION testresult_insert_before() RETURNS TRIGGER
391
522
LANGUAGE plpgsql AS
394
testresult_record RECORD;
525
next_date_created DATE;
527
previous_date_deleted DATE;
396
-- First, check for the most common case when
397
-- there is a test result in a backward dimension.
402
testresult.date_created
529
IF NEW.date_deleted < '3000-01-01' THEN
533
SELECT INTO next_testrun
534
CASE WHEN MIN(date_created) > NEW.date_created
535
THEN MIN(date_created)
536
ELSE MIN(date_deleted)
540
ON tr.test_case = tc1.id
542
ON tc1.distro_series IS NOT DISTINCT FROM tc2.distro_series
543
AND tc1.project_series IS NOT DISTINCT FROM tc2.project_series
544
WHERE date_deleted > NEW.date_created
545
AND tc2.id = NEW.test_case;
546
IF next_testrun < '3000-01-01' THEN
547
-- Set date created of next test result.
549
SET date_created = CASE
550
WHEN testresult.status = NEW.status
551
AND testresult.output = NEW.output
552
AND testresult.date_created <> NEW.date_created
553
THEN NEW.date_created
556
WHERE testresult.test_case = NEW.test_case
557
AND testresult.date_created <= next_testrun
558
AND testresult.date_created >= NEW.date_created
559
RETURNING date_created INTO next_date_created;
560
IF next_date_created != NEW.date_created THEN
561
next_date_created := next_testrun;
562
NEW.date_deleted := next_testrun;
565
next_date_created := '3000-01-01';
568
-- Set date deleted of previous test result.
570
SET date_deleted = CASE
571
WHEN testresult.status = NEW.status
572
AND testresult.output = NEW.output
573
THEN next_date_created
574
ELSE NEW.date_created
404
576
WHERE testresult.test_case = NEW.test_case
405
577
AND testresult.date_created <= NEW.date_created
406
AND testresult.date_deleted > NEW.date_created;
408
IF NEW.status = testresult_record.status
409
AND NEW.output = testresult_record.output THEN
410
-- No need to extend forward dimension
413
ELSIF NEW.date_created = testresult_record.date_created THEN
414
-- Update current dimension
415
UPDATE testresult SET status = NEW.status, output = NEW.output
416
WHERE testresult.test_case = NEW.test_case
417
AND testresult.date_created <= NEW.date_created
418
AND testresult.date_deleted > NEW.date_created;
422
-- Reducing backward dimension
423
UPDATE testresult SET date_deleted = NEW.date_created
424
WHERE testresult.test_case = NEW.test_case
425
AND testresult.date_created <= NEW.date_created
426
AND testresult.date_deleted > NEW.date_created;
430
-- Then, check when there is a test result in a forward dimension.
435
testresult.date_created
437
WHERE testresult.test_case = NEW.test_case
438
AND testresult.date_created > NEW.date_created
439
ORDER BY date_created LIMIT 1;
441
IF NEW.status = testresult_record.status
442
AND NEW.output = testresult_record.output THEN
443
-- Extending forward dimension
444
UPDATE testresult SET date_created = NEW.date_created
445
WHERE testresult.test_case = NEW.test_case
446
AND testresult.date_created = testresult_record.date_created;
450
-- Reducing forward dimension
451
NEW.date_deleted := testresult_record.date_created;
578
AND testresult.date_deleted >= NEW.date_created
579
RETURNING date_deleted INTO previous_date_deleted;
580
IF previous_date_deleted = next_date_created THEN
581
IF next_date_created = NEW.date_created THEN
582
DELETE FROM testresult
583
WHERE test_case = NEW.test_case
584
AND testresult.date_created = next_testrun;
587
ELSIF next_date_created = NEW.date_created
588
AND previous_date_deleted IS NOT NULL THEN
511
638
EXECUTE PROCEDURE testresult_update_before()
514
CREATE FUNCTION testresult_delete_after() RETURNS TRIGGER
518
testresult_record RECORD;
520
-- Check if there is a testresult between two equivalent dimensions
521
SELECT INTO testresult_record tr2.date_deleted FROM testresult tr1
523
ON tr1.test_case = tr2.test_case
524
AND tr1.status = tr2.status
525
AND decode(md5(tr1.output), 'hex') = decode(md5(tr2.output), 'hex')
526
AND tr1.date_deleted = OLD.date_created
527
AND tr2.date_created = OLD.date_deleted;
529
DELETE FROM testresult
530
WHERE testresult.test_case = OLD.test_case
531
AND testresult.date_created = OLD.date_deleted;
532
UPDATE testresult SET date_deleted = testresult_record.date_deleted
533
WHERE testresult.test_case = OLD.test_case
534
AND testresult.date_deleted = OLD.date_created;
537
-- Extend forward dimension
538
UPDATE testresult SET date_deleted = OLD.date_deleted
539
WHERE testresult.test_case = OLD.test_case
540
AND testresult.date_deleted = OLD.date_created;
542
-- Reduce backward dimension
543
UPDATE testresult set date_created = OLD.date_created
544
WHERE testresult.test_case = OLD.test_case
545
AND testresult.date_created = OLD.date_deleted;
555
ON FUNCTION testresult_delete_after()
559
CREATE TRIGGER testresult_delete_after_trigger
560
AFTER DELETE ON testresult
562
EXECUTE PROCEDURE testresult_delete_after()
565
641
ALTER TABLE ONLY testcase
566
642
ADD CONSTRAINT testcase__distro_series__fk
567
643
FOREIGN KEY (distro_series)