Added migration for screen extension ID foreign key

Necessary to improve referential integrity by associating extensions with screens.

Issue: 360
Milestone: minor
This commit is contained in:
Brooke Kuhlmann
2026-08-10 10:10:05 -06:00
parent ad1c5a18c2
commit 43832d67be
2 changed files with 21 additions and 2 deletions
@@ -0,0 +1,9 @@
# frozen_string_literal: true
ROM::SQL.migration do
change do
alter_table :screen do
add_foreign_key :extension_id, :extension, on_update: :cascade, on_delete: :set_null
end
end
end
+12 -2
View File
@@ -761,7 +761,8 @@ CREATE TABLE public.screen (
updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
device_id integer,
kind public.screen_kind_enum DEFAULT 'general'::public.screen_kind_enum NOT NULL,
template_id integer
template_id integer,
extension_id integer
);
@@ -1657,6 +1658,14 @@ ALTER TABLE ONLY public.screen
ADD CONSTRAINT screen_device_id_fkey FOREIGN KEY (device_id) REFERENCES public.device(id) ON UPDATE CASCADE ON DELETE SET NULL;
--
-- Name: screen screen_extension_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.screen
ADD CONSTRAINT screen_extension_id_fkey FOREIGN KEY (extension_id) REFERENCES public.extension(id) ON UPDATE CASCADE ON DELETE SET NULL;
--
-- Name: screen screen_model_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@@ -1806,4 +1815,5 @@ INSERT INTO schema_migrations (filename) VALUES
('20260714090149_add_device_api_key_column.rb'),
('20260721160734_add_device_command_column.rb'),
('20260721160742_rename_device_log_function_columan_as_command.rb'),
('20260805142625_alter_screen_device_id_constraint.rb');
('20260805142625_alter_screen_device_id_constraint.rb'),
('20260810100653_add_screen_extension_id_column.rb');