Skip to content

Commit

Permalink
Created migration files for log_domains table json columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergei Tsoganov authored and Sergei Tsoganov committed Jan 3, 2023
1 parent e2c6c9e commit b4429a5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class ReverseLogDomainsObjectChangesJson < ActiveRecord::Migration[6.1]
def up
safety_assured do
remove_column :log_domains, :object_changes_json if column_exists? :log_domains, :object_changes_json
add_column :log_domains, :object_changes_json, :json
Version::DomainVersion.update_all('object_changes_json = object_changes::json')
rename_column :log_domains, :object_changes, :object_changes_jsonb
rename_column :log_domains, :object_changes_json, :object_changes
end
end

def down
safety_assured do
rename_column :log_domains, :object_changes, :object_changes_json
rename_column :log_domains, :object_changes_jsonb, :object_changes
end
end
end
18 changes: 18 additions & 0 deletions db/migrate/20230103100621_reverse_log_domains_object_json.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class ReverseLogDomainsObjectJson < ActiveRecord::Migration[6.1]
def up
safety_assured do
remove_column :log_domains, :object_json if column_exists? :log_domains, :object_json
add_column :log_domains, :object_json, :json
Version::DomainVersion.update_all('object_json = object::json')
rename_column :log_domains, :object, :object_jsonb
rename_column :log_domains, :object_json, :object
end
end

def down
safety_assured do
rename_column :log_domains, :object, :object_json
rename_column :log_domains, :object_jsonb, :object
end
end
end
20 changes: 11 additions & 9 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1670,14 +1670,14 @@ CREATE TABLE public.log_domains (
item_id integer NOT NULL,
event character varying NOT NULL,
whodunnit character varying,
object_json jsonb,
object_changes_json json,
created_at timestamp without time zone,
session character varying,
children jsonb,
uuid character varying,
object_changes jsonb,
object jsonb
object_changes_jsonb jsonb,
object_jsonb jsonb,
object_changes json,
object json
);


Expand Down Expand Up @@ -4442,17 +4442,17 @@ CREATE INDEX index_log_domains_on_item_type_and_item_id ON public.log_domains US


--
-- Name: index_log_domains_on_object; Type: INDEX; Schema: public; Owner: -
-- Name: index_log_domains_on_object_changes_jsonb; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_log_domains_on_object ON public.log_domains USING gin (object);
CREATE INDEX index_log_domains_on_object_changes_jsonb ON public.log_domains USING gin (object_changes_jsonb);


--
-- Name: index_log_domains_on_object_changes; Type: INDEX; Schema: public; Owner: -
-- Name: index_log_domains_on_object_jsonb; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_log_domains_on_object_changes ON public.log_domains USING gin (object_changes);
CREATE INDEX index_log_domains_on_object_jsonb ON public.log_domains USING gin (object_jsonb);


--
Expand Down Expand Up @@ -5469,6 +5469,8 @@ INSERT INTO "schema_migrations" (version) VALUES
('20221206091556'),
('20221207102831'),
('20221214073933'),
('20221214074252');
('20221214074252'),
('20230103095457'),
('20230103100621');


0 comments on commit b4429a5

Please sign in to comment.