38 lines
1.8 KiB
SQL
38 lines
1.8 KiB
SQL
CREATE TABLE IF NOT EXISTS report_category_team_categories (
|
|
report_category_id BIGINT UNSIGNED NOT NULL,
|
|
team_category_id BIGINT UNSIGNED NOT NULL,
|
|
PRIMARY KEY (report_category_id, team_category_id),
|
|
CONSTRAINT report_category_team_categories_report_fk
|
|
FOREIGN KEY (report_category_id) REFERENCES report_categories(id),
|
|
CONSTRAINT report_category_team_categories_team_fk
|
|
FOREIGN KEY (team_category_id) REFERENCES team_categories(id)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS intervention_access_links (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
report_id BIGINT UNSIGNED NOT NULL,
|
|
assignment_id BIGINT UNSIGNED NOT NULL,
|
|
token_hash VARCHAR(255) NOT NULL,
|
|
created_by_user_id BIGINT UNSIGNED NOT NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
expires_at DATETIME NOT NULL,
|
|
revoked_at DATETIME NULL,
|
|
last_accessed_at DATETIME NULL,
|
|
UNIQUE KEY intervention_access_links_token_hash_unique (token_hash),
|
|
KEY intervention_access_links_report_assignment_idx (report_id, assignment_id),
|
|
CONSTRAINT intervention_access_links_report_fk
|
|
FOREIGN KEY (report_id) REFERENCES reports(id),
|
|
CONSTRAINT intervention_access_links_assignment_fk
|
|
FOREIGN KEY (assignment_id) REFERENCES assignments(id),
|
|
CONSTRAINT intervention_access_links_user_fk
|
|
FOREIGN KEY (created_by_user_id) REFERENCES users(id)
|
|
);
|
|
|
|
INSERT IGNORE INTO report_category_team_categories (report_category_id, team_category_id)
|
|
SELECT rc.id, tc.id
|
|
FROM report_categories rc
|
|
JOIN team_categories tc ON
|
|
(rc.name = 'Buche stradali' AND tc.name = 'Manutenzione strade') OR
|
|
(rc.name = 'Illuminazione guasta' AND tc.name = 'Illuminazione pubblica') OR
|
|
(rc.name = 'Rifiuti abbandonati' AND tc.name = 'Igiene urbana');
|