add HasAuxTable
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
class MigratePostFilesToHasAuxTable < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
mirai_tablespace!
|
||||
|
||||
create_aux_table :domain_post_files, :inkbunny do |t|
|
||||
t.integer :ib_id, index: true
|
||||
t.jsonb :ib_detail_raw, default: {}
|
||||
t.integer :file_order
|
||||
t.datetime :ib_created_at
|
||||
t.string :file_name
|
||||
t.string :md5_initial
|
||||
t.string :md5_full
|
||||
t.jsonb :md5s, default: []
|
||||
end
|
||||
|
||||
# `ib_created_at` string is in format like `2019-10-11T16:57:19.945Z` - aka iso8601 zulu time
|
||||
# so we need to convert it to utc time
|
||||
up_only { execute <<-SQL }
|
||||
INSERT INTO domain_post_files_inkbunny_aux (
|
||||
base_table_id,
|
||||
ib_id,
|
||||
ib_detail_raw,
|
||||
file_order, ib_created_at,
|
||||
file_name,
|
||||
md5_initial,
|
||||
md5_full,
|
||||
md5s
|
||||
)
|
||||
SELECT
|
||||
id as base_table_id,
|
||||
(json_attributes->>'ib_id')::integer as ib_id,
|
||||
(json_attributes->>'ib_detail_raw')::jsonb as ib_detail_raw,
|
||||
(json_attributes->>'file_order')::integer as file_order,
|
||||
(json_attributes->>'ib_created_at')::timestamp as ib_created_at,
|
||||
(json_attributes->>'file_name')::text as file_name,
|
||||
(json_attributes->>'md5_initial')::text as md5_initial,
|
||||
(json_attributes->>'md5_full')::text as md5_full,
|
||||
(json_attributes->>'md5s')::jsonb as md5s
|
||||
FROM domain_post_files
|
||||
WHERE type = 'Domain::PostFile::InkbunnyPostFile'
|
||||
SQL
|
||||
end
|
||||
end
|
||||
22
db/migrate/20250717204152_add_columns_to_post_files.rb
Normal file
22
db/migrate/20250717204152_add_columns_to_post_files.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
class AddColumnsToPostFiles < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
change_table :domain_post_files do |t|
|
||||
t.string :state
|
||||
t.string :url_str
|
||||
t.string :error_message
|
||||
t.integer :last_status_code
|
||||
t.integer :retry_count, default: 0
|
||||
end
|
||||
|
||||
up_only { execute <<-SQL }
|
||||
UPDATE domain_post_files
|
||||
SET state = json_attributes->>'state',
|
||||
url_str = json_attributes->>'url_str',
|
||||
error_message = json_attributes->>'error_message',
|
||||
last_status_code = (json_attributes->>'last_status_code')::integer,
|
||||
retry_count = COALESCE((json_attributes->>'retry_count')::integer, 0)
|
||||
SQL
|
||||
|
||||
change_column_null :domain_post_files, :state, false
|
||||
end
|
||||
end
|
||||
@@ -2823,7 +2823,12 @@ CREATE TABLE public.domain_post_files (
|
||||
blob_sha256 bytea,
|
||||
json_attributes jsonb DEFAULT '{}'::jsonb,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL
|
||||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
state character varying NOT NULL,
|
||||
url_str character varying,
|
||||
error_message character varying,
|
||||
last_status_code integer,
|
||||
retry_count integer DEFAULT 0
|
||||
);
|
||||
|
||||
|
||||
@@ -2846,6 +2851,42 @@ CREATE SEQUENCE public.domain_post_files_id_seq
|
||||
ALTER SEQUENCE public.domain_post_files_id_seq OWNED BY public.domain_post_files.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: domain_post_files_inkbunny_aux; Type: TABLE; Schema: public; Owner: -; Tablespace: mirai
|
||||
--
|
||||
|
||||
CREATE TABLE public.domain_post_files_inkbunny_aux (
|
||||
base_table_id bigint NOT NULL,
|
||||
ib_id integer,
|
||||
ib_detail_raw jsonb DEFAULT '{}'::jsonb,
|
||||
file_order integer,
|
||||
ib_created_at timestamp(6) without time zone,
|
||||
file_name character varying,
|
||||
md5_initial character varying,
|
||||
md5_full character varying,
|
||||
md5s jsonb DEFAULT '[]'::jsonb
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: domain_post_files_inkbunny_aux_base_table_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.domain_post_files_inkbunny_aux_base_table_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: domain_post_files_inkbunny_aux_base_table_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.domain_post_files_inkbunny_aux_base_table_id_seq OWNED BY public.domain_post_files_inkbunny_aux.base_table_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: domain_post_group_joins; Type: TABLE; Schema: public; Owner: -; Tablespace: mirai
|
||||
--
|
||||
@@ -4824,6 +4865,13 @@ ALTER TABLE ONLY public.domain_post_file_thumbnails ALTER COLUMN id SET DEFAULT
|
||||
ALTER TABLE ONLY public.domain_post_files ALTER COLUMN id SET DEFAULT nextval('public.domain_post_files_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: domain_post_files_inkbunny_aux base_table_id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.domain_post_files_inkbunny_aux ALTER COLUMN base_table_id SET DEFAULT nextval('public.domain_post_files_inkbunny_aux_base_table_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: domain_post_groups id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -5639,6 +5687,14 @@ ALTER TABLE ONLY public.domain_post_file_thumbnails
|
||||
|
||||
SET default_tablespace = mirai;
|
||||
|
||||
--
|
||||
-- Name: domain_post_files_inkbunny_aux domain_post_files_inkbunny_aux_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: mirai
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.domain_post_files_inkbunny_aux
|
||||
ADD CONSTRAINT domain_post_files_inkbunny_aux_pkey PRIMARY KEY (base_table_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: domain_post_files domain_post_files_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: mirai
|
||||
--
|
||||
@@ -7379,6 +7435,20 @@ CREATE INDEX index_domain_post_file_bit_fingerprints_on_fingerprint_value ON pub
|
||||
|
||||
SET default_tablespace = mirai;
|
||||
|
||||
--
|
||||
-- Name: index_domain_post_files_inkbunny_aux_on_base_table_id; Type: INDEX; Schema: public; Owner: -; Tablespace: mirai
|
||||
--
|
||||
|
||||
CREATE INDEX index_domain_post_files_inkbunny_aux_on_base_table_id ON public.domain_post_files_inkbunny_aux USING btree (base_table_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_domain_post_files_inkbunny_aux_on_ib_id; Type: INDEX; Schema: public; Owner: -; Tablespace: mirai
|
||||
--
|
||||
|
||||
CREATE INDEX index_domain_post_files_inkbunny_aux_on_ib_id ON public.domain_post_files_inkbunny_aux USING btree (ib_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_domain_post_files_on_blob_sha256; Type: INDEX; Schema: public; Owner: -; Tablespace: mirai
|
||||
--
|
||||
@@ -9138,6 +9208,14 @@ ALTER TABLE ONLY public.domain_user_user_follows
|
||||
ADD CONSTRAINT fk_rails_b45e6e3979 FOREIGN KEY (to_id) REFERENCES public.domain_users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: domain_post_files_inkbunny_aux fk_rails_b4f96e5241; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.domain_post_files_inkbunny_aux
|
||||
ADD CONSTRAINT fk_rails_b4f96e5241 FOREIGN KEY (base_table_id) REFERENCES public.domain_post_files(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: domain_inkbunny_posts fk_rails_c2d9f4b382; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -9273,6 +9351,8 @@ ALTER TABLE ONLY public.domain_twitter_tweets
|
||||
SET search_path TO "$user", public;
|
||||
|
||||
INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20250717204152'),
|
||||
('20250716164417'),
|
||||
('20250711014943'),
|
||||
('20250710204708'),
|
||||
('20250709235107'),
|
||||
|
||||
Reference in New Issue
Block a user