diff --git a/config/db/migrate/20260219103153_create_extension_device.rb b/config/db/migrate/20260219103153_create_extension_device.rb new file mode 100644 index 00000000..d5e1de9b --- /dev/null +++ b/config/db/migrate/20260219103153_create_extension_device.rb @@ -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 diff --git a/config/db/structure.sql b/config/db/structure.sql index eb032022..72d92b5f 100644 --- a/config/db/structure.sql +++ b/config/db/structure.sql @@ -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');