Skip to content

Commit

Permalink
Update active storage tables for rails 6.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed May 10, 2021
1 parent d317139 commit 98b118b
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This migration comes from active_storage (originally 20190112182829)
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
def up
unless column_exists?(:active_storage_blobs, :service_name)
add_column :active_storage_blobs, :service_name, :string

if (configured_service = ActiveStorage::Blob.service.name)
ActiveStorage::Blob.unscoped.update_all(:service_name => configured_service)
end

safety_assured { change_column :active_storage_blobs, :service_name, :string, :null => false }
end
end

def down
remove_column :active_storage_blobs, :service_name
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This migration comes from active_storage (originally 20191206030411)
class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
def change
create_table :active_storage_variant_records do |t|
t.belongs_to :blob, :null => false, :index => false
t.string :variation_digest, :null => false

t.index [:blob_id, :variation_digest], :name => "index_active_storage_variant_records_uniqueness", :unique => true
t.foreign_key :active_storage_blobs, :column => :blob_id
end
end
end
65 changes: 64 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ CREATE TABLE public.active_storage_blobs (
metadata text,
byte_size bigint NOT NULL,
checksum character varying NOT NULL,
created_at timestamp without time zone NOT NULL
created_at timestamp without time zone NOT NULL,
service_name character varying NOT NULL
);


Expand All @@ -289,6 +290,36 @@ CREATE SEQUENCE public.active_storage_blobs_id_seq
ALTER SEQUENCE public.active_storage_blobs_id_seq OWNED BY public.active_storage_blobs.id;


--
-- Name: active_storage_variant_records; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.active_storage_variant_records (
id bigint NOT NULL,
blob_id bigint NOT NULL,
variation_digest character varying NOT NULL
);


--
-- Name: active_storage_variant_records_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE public.active_storage_variant_records_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- Name: active_storage_variant_records_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE public.active_storage_variant_records_id_seq OWNED BY public.active_storage_variant_records.id;


--
-- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1470,6 +1501,13 @@ ALTER TABLE ONLY public.active_storage_attachments ALTER COLUMN id SET DEFAULT n
ALTER TABLE ONLY public.active_storage_blobs ALTER COLUMN id SET DEFAULT nextval('public.active_storage_blobs_id_seq'::regclass);


--
-- Name: active_storage_variant_records id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.active_storage_variant_records ALTER COLUMN id SET DEFAULT nextval('public.active_storage_variant_records_id_seq'::regclass);


--
-- Name: changeset_comments id; Type: DEFAULT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1669,6 +1707,14 @@ ALTER TABLE ONLY public.active_storage_blobs
ADD CONSTRAINT active_storage_blobs_pkey PRIMARY KEY (id);


--
-- Name: active_storage_variant_records active_storage_variant_records_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.active_storage_variant_records
ADD CONSTRAINT active_storage_variant_records_pkey PRIMARY KEY (id);


--
-- Name: ar_internal_metadata ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2230,6 +2276,13 @@ CREATE UNIQUE INDEX index_active_storage_attachments_uniqueness ON public.active
CREATE UNIQUE INDEX index_active_storage_blobs_on_key ON public.active_storage_blobs USING btree (key);


--
-- Name: index_active_storage_variant_records_uniqueness; Type: INDEX; Schema: public; Owner: -
--

CREATE UNIQUE INDEX index_active_storage_variant_records_uniqueness ON public.active_storage_variant_records USING btree (blob_id, variation_digest);


--
-- Name: index_changeset_comments_on_changeset_id_and_created_at; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2749,6 +2802,14 @@ ALTER TABLE ONLY public.diary_entry_subscriptions
ADD CONSTRAINT diary_entry_subscriptions_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);


--
-- Name: active_storage_variant_records fk_rails_993965df05; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.active_storage_variant_records
ADD CONSTRAINT fk_rails_993965df05 FOREIGN KEY (blob_id) REFERENCES public.active_storage_blobs(id);


--
-- Name: active_storage_attachments fk_rails_c3b3935057; Type: FK CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -3123,6 +3184,8 @@ INSERT INTO "schema_migrations" (version) VALUES
('20201006213836'),
('20201006220807'),
('20201214144017'),
('20210510083027'),
('20210510083028'),
('21'),
('22'),
('23'),
Expand Down

0 comments on commit 98b118b

Please sign in to comment.