mirror of
https://github.com/Dictionarry-Hub/schema.git
synced 2026-05-03 06:14:17 +02:00
fix: add cleanup triggers for orphaned conditions
When a regex or language is deleted, the FK cascade deletes the condition_patterns/condition_languages row but leaves the parent condition orphaned. These triggers clean up the parent condition.
This commit is contained in:
@@ -108,3 +108,10 @@ instead of an autoincrement id column.
|
|||||||
- `radarr_naming.name`, `sonarr_naming.name`, `radarr_media_settings.name`, `sonarr_media_settings.name`
|
- `radarr_naming.name`, `sonarr_naming.name`, `radarr_media_settings.name`, `sonarr_media_settings.name`
|
||||||
- SQLite PRIMARY KEY doesn't imply NOT NULL for non-INTEGER columns; explicit declaration needed for type generators
|
- SQLite PRIMARY KEY doesn't imply NOT NULL for non-INTEGER columns; explicit declaration needed for type generators
|
||||||
|
|
||||||
|
## 10-2-26
|
||||||
|
|
||||||
|
- Added cleanup triggers for orphaned conditions
|
||||||
|
- `trg_condition_patterns_cleanup`: when a `condition_patterns` row is cascade-deleted (e.g., referenced regex deleted upstream), the parent condition in `custom_format_conditions` is also deleted
|
||||||
|
- `trg_condition_languages_cleanup`: same for `condition_languages` when a referenced language is deleted
|
||||||
|
- Prevents orphaned conditions that exist without their type-specific data
|
||||||
|
|
||||||
|
|||||||
@@ -218,6 +218,16 @@ CREATE TABLE condition_patterns (
|
|||||||
FOREIGN KEY (regular_expression_name) REFERENCES regular_expressions(name) ON DELETE CASCADE ON UPDATE CASCADE
|
FOREIGN KEY (regular_expression_name) REFERENCES regular_expressions(name) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- Clean up orphaned conditions when their pattern reference is cascade-deleted
|
||||||
|
-- (e.g., when the referenced regex is deleted upstream)
|
||||||
|
CREATE TRIGGER trg_condition_patterns_cleanup
|
||||||
|
AFTER DELETE ON condition_patterns
|
||||||
|
BEGIN
|
||||||
|
DELETE FROM custom_format_conditions
|
||||||
|
WHERE custom_format_name = OLD.custom_format_name
|
||||||
|
AND name = OLD.condition_name;
|
||||||
|
END;
|
||||||
|
|
||||||
-- Language-based conditions
|
-- Language-based conditions
|
||||||
-- Uses stable keys: (custom_format_name, condition_name) and language_name
|
-- Uses stable keys: (custom_format_name, condition_name) and language_name
|
||||||
CREATE TABLE condition_languages (
|
CREATE TABLE condition_languages (
|
||||||
@@ -230,6 +240,15 @@ CREATE TABLE condition_languages (
|
|||||||
FOREIGN KEY (language_name) REFERENCES languages(name) ON DELETE CASCADE ON UPDATE CASCADE
|
FOREIGN KEY (language_name) REFERENCES languages(name) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- Clean up orphaned conditions when their language reference is cascade-deleted
|
||||||
|
CREATE TRIGGER trg_condition_languages_cleanup
|
||||||
|
AFTER DELETE ON condition_languages
|
||||||
|
BEGIN
|
||||||
|
DELETE FROM custom_format_conditions
|
||||||
|
WHERE custom_format_name = OLD.custom_format_name
|
||||||
|
AND name = OLD.condition_name;
|
||||||
|
END;
|
||||||
|
|
||||||
-- Indexer flag conditions (e.g., "Scene", "Freeleech")
|
-- Indexer flag conditions (e.g., "Scene", "Freeleech")
|
||||||
-- Uses stable key: (custom_format_name, condition_name)
|
-- Uses stable key: (custom_format_name, condition_name)
|
||||||
CREATE TABLE condition_indexer_flags (
|
CREATE TABLE condition_indexer_flags (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "schema",
|
"name": "schema",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"description": "Base schema for all Profilarr Compliant Databases - defines the structural foundation that all PCDs build upon",
|
"description": "Base schema for all Profilarr Compliant Databases - defines the structural foundation that all PCDs build upon",
|
||||||
"arr_types": ["radarr", "sonarr"],
|
"arr_types": ["radarr", "sonarr"],
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user