| 
									
										
										
										
											2020-11-10 20:11:43 +01:00
										 |  |  | DELETE FROM shopping_list
 | 
					
						
							|  |  |  | WHERE shopping_list_id NOT IN (SELECT id FROM shopping_lists);
 | 
					
						
							| 
									
										
										
										
											2020-08-19 19:46:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-10 20:11:43 +01:00
										 |  |  | CREATE TRIGGER remove_items_from_deleted_shopping_list AFTER DELETE ON shopping_lists
 | 
					
						
							|  |  |  | BEGIN
 | 
					
						
							|  |  |  |     DELETE FROM shopping_list WHERE shopping_list_id = OLD.id;
 | 
					
						
							|  |  |  | END;
 | 
					
						
							| 
									
										
										
										
											2020-08-19 19:46:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-10 20:11:43 +01:00
										 |  |  | CREATE TRIGGER prevent_infinite_nested_recipes_INS BEFORE INSERT ON recipes_nestings
 | 
					
						
							|  |  |  | BEGIN
 | 
					
						
							|  |  |  |     SELECT CASE WHEN((
 | 
					
						
							|  |  |  |         SELECT 1
 | 
					
						
							|  |  |  |         FROM recipes_nestings_resolved rnr
 | 
					
						
							|  |  |  |         WHERE NEW.recipe_id = rnr.includes_recipe_id
 | 
					
						
							|  |  |  |             AND NEW.includes_recipe_id = rnr.recipe_id
 | 
					
						
							|  |  |  |     ) NOTNULL) THEN RAISE(ABORT, "Recursive nested recipe detected") END;
 | 
					
						
							|  |  |  | END;
 | 
					
						
							| 
									
										
										
										
											2020-08-19 19:46:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-10 20:11:43 +01:00
										 |  |  | CREATE TRIGGER prevent_infinite_nested_recipes_UPD BEFORE UPDATE ON recipes_nestings
 | 
					
						
							|  |  |  | BEGIN
 | 
					
						
							|  |  |  |     SELECT CASE WHEN((
 | 
					
						
							|  |  |  |         SELECT 1
 | 
					
						
							|  |  |  |         FROM recipes_nestings_resolved rnr
 | 
					
						
							|  |  |  |         WHERE NEW.recipe_id = rnr.includes_recipe_id
 | 
					
						
							|  |  |  |             AND NEW.includes_recipe_id = rnr.recipe_id
 | 
					
						
							|  |  |  |     ) NOTNULL) THEN RAISE(ABORT, "Recursive nested recipe detected") END;
 | 
					
						
							|  |  |  | END;
 |