From b472ae5c874bed0b332d07d93055f3475ac404d3 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 8 Nov 2022 23:39:01 -0600 Subject: [PATCH] replacements: add media_asset_id, old_media_asset_id columns. Add media_asset_id and old_media_asset_id columns for associating replacements with media assets. This way we can easily tell which replacements don't have a media asset (with the md5 alone we can't tell whether the media asset actually exists). --- ...add_media_asset_id_to_post_replacements.rb | 9 ++++ db/structure.sql | 51 ++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20221109052923_add_media_asset_id_to_post_replacements.rb diff --git a/db/migrate/20221109052923_add_media_asset_id_to_post_replacements.rb b/db/migrate/20221109052923_add_media_asset_id_to_post_replacements.rb new file mode 100644 index 000000000..af260d1b7 --- /dev/null +++ b/db/migrate/20221109052923_add_media_asset_id_to_post_replacements.rb @@ -0,0 +1,9 @@ +class AddMediaAssetIdToPostReplacements < ActiveRecord::Migration[7.0] + def change + add_reference :post_replacements, :media_asset, type: :integer, null: true, index: true, foreign_key: { to_table: :media_assets } + add_reference :post_replacements, :old_media_asset, type: :integer, null: true, index: true, foreign_key: { to_table: :media_assets } + + add_index :post_replacements, :md5 + add_index :post_replacements, :old_md5 + end +end diff --git a/db/structure.sql b/db/structure.sql index e9d7cbd8c..767ad13b3 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1434,7 +1434,9 @@ CREATE TABLE public.post_replacements ( file_size integer, image_width integer, image_height integer, - md5 character varying + md5 character varying, + media_asset_id integer, + old_media_asset_id integer ); @@ -4954,6 +4956,34 @@ CREATE INDEX index_post_replacements_on_creator_id ON public.post_replacements U CREATE INDEX index_post_replacements_on_creator_id_and_created_at ON public.post_replacements USING btree (creator_id, created_at); +-- +-- Name: index_post_replacements_on_md5; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_post_replacements_on_md5 ON public.post_replacements USING btree (md5); + + +-- +-- Name: index_post_replacements_on_media_asset_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_post_replacements_on_media_asset_id ON public.post_replacements USING btree (media_asset_id); + + +-- +-- Name: index_post_replacements_on_old_md5; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_post_replacements_on_old_md5 ON public.post_replacements USING btree (old_md5); + + +-- +-- Name: index_post_replacements_on_old_media_asset_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_post_replacements_on_old_media_asset_id ON public.post_replacements USING btree (old_media_asset_id); + + -- -- Name: index_post_replacements_on_post_id; Type: INDEX; Schema: public; Owner: - -- @@ -6045,6 +6075,14 @@ ALTER TABLE ONLY public.comments ADD CONSTRAINT fk_rails_2fd19c0db7 FOREIGN KEY (post_id) REFERENCES public.posts(id) DEFERRABLE INITIALLY DEFERRED; +-- +-- Name: post_replacements fk_rails_317818fc2f; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.post_replacements + ADD CONSTRAINT fk_rails_317818fc2f FOREIGN KEY (media_asset_id) REFERENCES public.media_assets(id); + + -- -- Name: api_keys fk_rails_32c28d0dc2; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -6165,6 +6203,14 @@ ALTER TABLE ONLY public.news_updates ADD CONSTRAINT fk_rails_502e0a41d1 FOREIGN KEY (updater_id) REFERENCES public.users(id) DEFERRABLE INITIALLY DEFERRED; +-- +-- Name: post_replacements fk_rails_5077102432; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.post_replacements + ADD CONSTRAINT fk_rails_5077102432 FOREIGN KEY (old_media_asset_id) REFERENCES public.media_assets(id); + + -- -- Name: forum_topics fk_rails_53d4e863cd; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -6910,6 +6956,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20221026084655'), ('20221026084656'), ('20221027000931'), -('20221106062419'); +('20221106062419'), +('20221109052923');