Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dorneanu committed Nov 25, 2024
1 parent c38eae5 commit 27dda97
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
13 changes: 13 additions & 0 deletions charts/heureka/docker/maintenance/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
maintenance:
build:
context: .
dockerfile: Dockerfile
container_name: heureka_maintenance
environment:
DB_HOST: host.docker.internal
DB_NAME: ${DB_NAME}
DB_USER: ${DB_USER}
DB_PASSWORD: ${DB_PASSWORD}
volumes:
- ./scripts:/scripts
Empty file modified charts/heureka/docker/maintenance/scripts/entrypoint.sh
100644 → 100755
Empty file.
46 changes: 46 additions & 0 deletions charts/heureka/docker/maintenance/scripts/maintenance.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- Maintenance script for database truncation
-- Enable logging
SET @start_time = NOW();
SELECT CONCAT('Starting maintenance at ', @start_time) AS log_message;

-- Start transaction
START TRANSACTION;

-- Disable foreign key checks temporarily
SET FOREIGN_KEY_CHECKS = 0;

-- Truncate junction join tables first
TRUNCATE TABLE IssueMatchEvidence;
TRUNCATE TABLE ComponentVersionIssue;
TRUNCATE TABLE IssueRepositoryService;
TRUNCATE TABLE ActivityHasIssue;
TRUNCATE TABLE ActivityHasService;
TRUNCATE TABLE IssueMatchChange;
TRUNCATE TABLE SupportGroupService;
TRUNCATE TABLE SupportGroupUser;
TRUNCATE TABLE Owner;

-- Truncate dependent entity tables
TRUNCATE TABLE IssueMatch;
TRUNCATE TABLE Evidence;
TRUNCATE TABLE ComponentInstance;
TRUNCATE TABLE IssueVariant;
TRUNCATE TABLE ComponentVersion;
TRUNCATE TABLE Activity;

-- Truncate main entity tables
TRUNCATE TABLE Component;
TRUNCATE TABLE Service;
TRUNCATE TABLE SupportGroup;
TRUNCATE TABLE Issue;
TRUNCATE TABLE IssueRepository;

-- Re-enable foreign key checks
SET FOREIGN_KEY_CHECKS = 1;

-- Log completion
SELECT CONCAT('Maintenance completed at ', NOW(), '. Duration: ',
TIMESTAMPDIFF(SECOND, @start_time, NOW()), ' seconds') AS log_message;

-- Commit transaction
COMMIT;

0 comments on commit 27dda97

Please sign in to comment.