feat: update area management to implement hard delete and adjust related references

This commit is contained in:
gabdevele
2026-06-15 15:50:12 +02:00 Unverified
parent bf85168914
commit 4f80d7f995
9 changed files with 30 additions and 24 deletions
+2 -3
View File
@@ -82,7 +82,6 @@ CREATE TABLE IF NOT EXISTS areas (
name VARCHAR(120) NOT NULL,
description TEXT NULL,
boundary_geojson JSON NOT NULL,
active BOOLEAN NOT NULL DEFAULT TRUE,
UNIQUE KEY areas_name_unique (name)
);
@@ -102,7 +101,7 @@ CREATE TABLE IF NOT EXISTS teams (
active BOOLEAN NOT NULL DEFAULT TRUE,
UNIQUE KEY teams_name_unique (name),
CONSTRAINT teams_category_fk FOREIGN KEY (team_category_id) REFERENCES team_categories(id),
CONSTRAINT teams_area_fk FOREIGN KEY (area_id) REFERENCES areas(id)
CONSTRAINT teams_area_fk FOREIGN KEY (area_id) REFERENCES areas(id) ON DELETE SET NULL
);
CREATE TABLE IF NOT EXISTS reports (
@@ -119,7 +118,7 @@ CREATE TABLE IF NOT EXISTS reports (
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT reports_user_fk FOREIGN KEY (user_id) REFERENCES users(id),
CONSTRAINT reports_category_fk FOREIGN KEY (category_id) REFERENCES report_categories(id),
CONSTRAINT reports_area_fk FOREIGN KEY (area_id) REFERENCES areas(id),
CONSTRAINT reports_area_fk FOREIGN KEY (area_id) REFERENCES areas(id) ON DELETE SET NULL,
KEY reports_status_idx (status),
KEY reports_category_idx (category_id),
KEY reports_area_idx (area_id)
@@ -0,0 +1,12 @@
ALTER TABLE teams DROP FOREIGN KEY teams_area_fk;
ALTER TABLE reports DROP FOREIGN KEY reports_area_fk;
ALTER TABLE areas DROP COLUMN active;
ALTER TABLE teams
ADD CONSTRAINT teams_area_fk
FOREIGN KEY (area_id) REFERENCES areas(id) ON DELETE SET NULL;
ALTER TABLE reports
ADD CONSTRAINT reports_area_fk
FOREIGN KEY (area_id) REFERENCES areas(id) ON DELETE SET NULL;