mirror of
https://github.com/internetee/registry.git
synced 2025-07-29 22:16:19 +02:00
Fixed migrations and modified object data type of log_domains table
This commit is contained in:
parent
e8fa1711ed
commit
2714c262db
6 changed files with 43 additions and 13 deletions
|
@ -1,6 +1,6 @@
|
|||
class ModifyLogDomainsObjectChangesDataType < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
add_column :log_domains, :object_changes_jsonb, :jsonb, default: '{}'
|
||||
add_column :log_domains, :object_changes_jsonb, :jsonb
|
||||
|
||||
# Copy data from old column to the new one
|
||||
Version::DomainVersion.update_all('object_changes_jsonb = object_changes::jsonb')
|
||||
|
|
|
@ -2,14 +2,14 @@ class AddIndexesToLogDomains < ActiveRecord::Migration[6.1]
|
|||
disable_ddl_transaction!
|
||||
def up
|
||||
enable_extension 'btree_gin'
|
||||
add_index :log_domains, :event, algorithm: :concurrently
|
||||
add_index :log_domains, :object, using: :gin, algorithm: :concurrently
|
||||
add_index :log_domains, :object_changes, using: :gin, algorithm: :concurrently
|
||||
add_index :log_domains, :event, algorithm: :concurrently, if_not_exists: true
|
||||
# add_index :log_domains, :object, using: :gin, algorithm: :concurrently, if_not_exists: true
|
||||
add_index :log_domains, :object_changes, using: :gin, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :log_domains, :event
|
||||
remove_index :log_domains, :object
|
||||
# remove_index :log_domains, :object
|
||||
remove_index :log_domains, :object_changes
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
class ChangeLogDomainsObjectChangesDefaultValue < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
change_column_default :log_domains, :object_changes, nil
|
||||
end
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
class ModifyLogDomainsObjectDataType < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
add_column :log_domains, :object_jsonb, :jsonb
|
||||
|
||||
# Copy data from old column to the new one
|
||||
Version::DomainVersion.update_all('object_jsonb = object::jsonb')
|
||||
|
||||
# Rename columns instead of modify their type, it's way faster
|
||||
safety_assured do
|
||||
rename_column :log_domains, :object, :object_json
|
||||
rename_column :log_domains, :object_jsonb, :object
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
safety_assured do
|
||||
rename_column :log_domains, :object, :object_jsonb
|
||||
rename_column :log_domains, :object_json, :object
|
||||
end
|
||||
end
|
||||
end
|
11
db/migrate/20221214074252_add_index_to_log_domain_object.rb
Normal file
11
db/migrate/20221214074252_add_index_to_log_domain_object.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
class AddIndexToLogDomainObject < ActiveRecord::Migration[6.1]
|
||||
disable_ddl_transaction!
|
||||
def up
|
||||
enable_extension 'btree_gin'
|
||||
add_index :log_domains, :object, using: :gin, algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :log_domains, :object
|
||||
end
|
||||
end
|
|
@ -1670,13 +1670,14 @@ CREATE TABLE public.log_domains (
|
|||
item_id integer NOT NULL,
|
||||
event character varying NOT NULL,
|
||||
whodunnit character varying,
|
||||
object jsonb,
|
||||
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_changes jsonb,
|
||||
object jsonb
|
||||
);
|
||||
|
||||
|
||||
|
@ -5466,6 +5467,8 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20221206075912'),
|
||||
('20221206090120'),
|
||||
('20221206091556'),
|
||||
('20221207102831');
|
||||
('20221207102831'),
|
||||
('20221214073933'),
|
||||
('20221214074252');
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue