Skip to content

Commit

Permalink
Migrate data from the old table to the new one
Browse files Browse the repository at this point in the history
  • Loading branch information
hellcp-work committed Jan 30, 2023
1 parent 02e1d3e commit 006d44d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 38 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gem 'sqlite3', '~> 1.6.0'
# gem 'mysql2', '~> 0.4.10'

# This can only be removed with Rails 7.0
gem 'mail', '< 2.8.0'
gem 'psych', '< 4.0'

# Use SCSS for stylesheets
Expand Down
17 changes: 2 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ GEM
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
date (3.3.1)
date_validator (0.12.0)
activemodel (>= 3)
activesupport (>= 3)
Expand Down Expand Up @@ -196,11 +195,8 @@ GEM
loofah (2.19.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.8.0)
mail (2.7.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
Expand All @@ -210,15 +206,6 @@ GEM
mini_racer (0.6.3)
libv8-node (~> 16.10.0.0)
minitest (5.17.0)
net-imap (0.3.2)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
timeout
net-smtp (0.3.3)
net-protocol
nio4r (2.5.8)
nokogiri (1.13.10)
mini_portile2 (~> 2.8.0)
Expand Down Expand Up @@ -385,7 +372,6 @@ GEM
thor (1.2.1)
thread_safe (0.3.6)
tilt (2.0.11)
timeout (0.3.1)
ttfunk (1.0.3)
tzinfo (1.2.10)
thread_safe (~> 0.1)
Expand Down Expand Up @@ -439,6 +425,7 @@ DEPENDENCIES
kaminari
letter_opener_web
listen
mail (< 2.8.0)
mini_racer
pdf-reader
prawn (~> 0.13.0)
Expand Down
8 changes: 4 additions & 4 deletions db/migrate/20221210104059_update_columns_in_audits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ def change
add_column :audits, :remote_address, :string
add_column :audits, :username, :string
add_column :audits, :request_uuid, :string
add_column :audits, :association_id, :integer
add_column :audits, :association_type, :string
add_column :audits, :associated_id, :integer
add_column :audits, :associated_type, :string

change_column_null :audits, :auditable_id, true
change_column_null :audits, :auditable_type, true
Expand All @@ -16,8 +16,8 @@ def change
remove_index :audits, name: :auditable_index

add_index :audits, :request_uuid
add_index :audits, [:auditable_type, :auditable_id, :version], name: :auditable_index
add_index :audits, [:associated_type, :associated_id], name: :associated_index
add_index :audits, %i[auditable_type auditable_id version], name: :auditable_index
add_index :audits, %i[associated_type associated_id], name: :associated_index

remove_column :audits, :owner_id, :integer
remove_column :audits, :owner_type, :string
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20230130095633_merge_audit_tables.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class MergeAuditTables < ActiveRecord::Migration[5.1]
def self.up
execute 'INSERT INTO audits(auditable_id, auditable_type, user_id, user_type, action, audited_changes, version, comment, remote_address, created_at) ' \
'SELECT auditable_id, auditable_type, user_id, user_type, action, audited_changes, version, comment, remote_address, created_at FROM espinita_audits;'
drop_table :espinita_audits
end

def self.down
raise IrreversibleMigration
end
end
23 changes: 4 additions & 19 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20221210104059) do
ActiveRecord::Schema.define(version: 20230130095633) do

create_table "audits", force: :cascade do |t|
t.integer "auditable_id"
Expand All @@ -25,8 +25,9 @@
t.string "remote_address"
t.string "username"
t.string "request_uuid"
t.integer "association_id"
t.string "association_type"
t.integer "associated_id"
t.string "associated_type"
t.index ["associated_type", "associated_id"], name: "associated_index"
t.index ["auditable_type", "auditable_id", "version"], name: "auditable_index"
t.index ["created_at"], name: "index_audits_on_created_at"
t.index ["request_uuid"], name: "index_audits_on_request_uuid"
Expand Down Expand Up @@ -84,22 +85,6 @@
t.index ["priority", "run_at"], name: "delayed_jobs_priority"
end

create_table "espinita_audits", force: :cascade do |t|
t.string "auditable_type"
t.integer "auditable_id"
t.string "user_type"
t.integer "user_id"
t.text "audited_changes"
t.string "comment"
t.integer "version"
t.string "action"
t.string "remote_address"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["auditable_type", "auditable_id"], name: "index_espinita_audits_on_auditable_type_and_auditable_id"
t.index ["user_type", "user_id"], name: "index_espinita_audits_on_user_type_and_user_id"
end

create_table "event_emails", force: :cascade do |t|
t.text "to"
t.string "subject"
Expand Down

0 comments on commit 006d44d

Please sign in to comment.