mirror of
https://github.com/usetrmnl/terminus.git
synced 2026-08-13 14:29:27 -07:00
Added extension device migration
Necessary to allow extensions to have one to many associated devices. This is similar to how extensions can have multiple models and will be used in the same manner especially when needing to acquire sensor information associated with a device which isn't possible with models. Milestone: minor
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
ROM::SQL.migration do
|
||||
change do
|
||||
create_table :extension_device do
|
||||
primary_key :id
|
||||
|
||||
foreign_key :extension_id, :extension, null: false, on_delete: :cascade, on_update: :cascade
|
||||
foreign_key :device_id, :device, null: false, on_delete: :cascade, on_update: :cascade
|
||||
|
||||
column :created_at, :timestamp, null: false, default: Sequel::CURRENT_TIMESTAMP
|
||||
column :updated_at, :timestamp, null: false, default: Sequel::CURRENT_TIMESTAMP
|
||||
end
|
||||
|
||||
add_index :extension_device, %i[extension_id device_id], unique: true
|
||||
end
|
||||
end
|
||||
+60
-1
@@ -378,6 +378,33 @@ CREATE TABLE public.extension (
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: extension_device; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.extension_device (
|
||||
id integer NOT NULL,
|
||||
extension_id integer NOT NULL,
|
||||
device_id integer NOT NULL,
|
||||
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: extension_device_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE public.extension_device ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||||
SEQUENCE NAME public.extension_device_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: extension_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
@@ -806,6 +833,14 @@ ALTER TABLE ONLY public.device
|
||||
ADD CONSTRAINT devices_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: extension_device extension_device_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.extension_device
|
||||
ADD CONSTRAINT extension_device_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: extension extension_label_key; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -1076,6 +1111,13 @@ CREATE INDEX device_sensor_kind_index ON public.device_sensor USING btree (kind)
|
||||
CREATE INDEX device_sensor_source_index ON public.device_sensor USING btree (source);
|
||||
|
||||
|
||||
--
|
||||
-- Name: extension_device_extension_id_device_id_index; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX extension_device_extension_id_device_id_index ON public.extension_device USING btree (extension_id, device_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: extension_model_extension_id_model_id_index; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@@ -1241,6 +1283,22 @@ ALTER TABLE ONLY public.device
|
||||
ADD CONSTRAINT devices_playlist_id_fkey FOREIGN KEY (playlist_id) REFERENCES public.playlist(id) ON UPDATE CASCADE ON DELETE SET NULL;
|
||||
|
||||
|
||||
--
|
||||
-- Name: extension_device extension_device_device_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.extension_device
|
||||
ADD CONSTRAINT extension_device_device_id_fkey FOREIGN KEY (device_id) REFERENCES public.device(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: extension_device extension_device_extension_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.extension_device
|
||||
ADD CONSTRAINT extension_device_extension_id_fkey FOREIGN KEY (extension_id) REFERENCES public.extension(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: extension_model extension_model_extension_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -1411,4 +1469,5 @@ INSERT INTO schema_migrations (filename) VALUES
|
||||
('20260106144016_alter_firmware_kind.rb'),
|
||||
('20260126141642_alter_device_table_model_id_as_non_null.rb'),
|
||||
('20260209163817_add_model_palette_ids_and_css_columns.rb'),
|
||||
('20260217081447_create_device_sensor.rb');
|
||||
('20260217081447_create_device_sensor.rb'),
|
||||
('20260219103153_create_extension_device.rb');
|
||||
|
||||
Reference in New Issue
Block a user