diff --git a/Gemfile b/Gemfile index 269d2f0..26e6025 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,7 @@ gem 'devise' gem 'devise-bootstrap-views' gem 'pg' gem 'simple_form' +gem "audited", "~> 4.5" group :development, :test do gem 'rspec-rails' diff --git a/Gemfile.lock b/Gemfile.lock index dc60ee1..9d5349c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -51,6 +51,8 @@ GEM addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) arel (8.0.0) + audited (4.5.0) + activerecord (>= 4.0, < 5.2) autoprefixer-rails (7.1.1.2) execjs bcrypt (3.1.11) @@ -233,6 +235,7 @@ PLATFORMS ruby DEPENDENCIES + audited (~> 4.5) better_errors! binding_of_caller bootstrap-sass (~> 3.3.6) diff --git a/app/models/score_card.rb b/app/models/score_card.rb index 8423034..cef8273 100644 --- a/app/models/score_card.rb +++ b/app/models/score_card.rb @@ -4,4 +4,6 @@ class ScoreCard < ApplicationRecord has_many :questions, through: :score_card_answers accepts_nested_attributes_for :score_card_answers + + audited end diff --git a/app/models/score_card_answer.rb b/app/models/score_card_answer.rb index cda2c0b..6b2c106 100644 --- a/app/models/score_card_answer.rb +++ b/app/models/score_card_answer.rb @@ -4,4 +4,5 @@ class ScoreCardAnswer < ApplicationRecord enum score: { Red: 0, Yellow: 1, Green: 2 } + audited end diff --git a/db/migrate/20170721031529_install_audited.rb b/db/migrate/20170721031529_install_audited.rb new file mode 100644 index 0000000..97bea3c --- /dev/null +++ b/db/migrate/20170721031529_install_audited.rb @@ -0,0 +1,30 @@ +class InstallAudited < ActiveRecord::Migration[5.1] + def self.up + create_table :audits, :force => true do |t| + t.column :auditable_id, :uuid + t.column :auditable_type, :string + t.column :associated_id, :uuid + t.column :associated_type, :string + t.column :user_id, :integer + t.column :user_type, :string + t.column :username, :string + t.column :action, :string + t.column :audited_changes, :text + t.column :version, :integer, :default => 0 + t.column :comment, :string + t.column :remote_address, :string + t.column :request_uuid, :string + t.column :created_at, :datetime + end + + add_index :audits, [:auditable_id, :auditable_type], :name => 'auditable_index' + add_index :audits, [:associated_id, :associated_type], :name => 'associated_index' + add_index :audits, [:user_id, :user_type], :name => 'user_index' + add_index :audits, :request_uuid + add_index :audits, :created_at + end + + def self.down + drop_table :audits + end +end diff --git a/db/schema.rb b/db/schema.rb index 97be3c2..def0730 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170711030128) do +ActiveRecord::Schema.define(version: 20170721031529) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -23,6 +23,28 @@ t.integer "kind", default: 0 end + create_table "audits", force: :cascade do |t| + t.uuid "auditable_id" + t.string "auditable_type" + t.uuid "associated_id" + t.string "associated_type" + t.integer "user_id" + t.string "user_type" + t.string "username" + t.string "action" + t.text "audited_changes" + t.integer "version", default: 0 + t.string "comment" + t.string "remote_address" + t.string "request_uuid" + t.datetime "created_at" + t.index ["associated_id", "associated_type"], name: "associated_index" + t.index ["auditable_id", "auditable_type"], name: "auditable_index" + t.index ["created_at"], name: "index_audits_on_created_at" + t.index ["request_uuid"], name: "index_audits_on_request_uuid" + t.index ["user_id", "user_type"], name: "user_index" + end + create_table "questions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.integer "kind", default: 0 t.datetime "created_at", null: false