Skip to content

Commit

Permalink
Audit score cards and score card answers so we can rollback if mistak…
Browse files Browse the repository at this point in the history
…es are made
  • Loading branch information
Ryan Jones committed Jul 21, 2017
1 parent 95bf9a2 commit 381328e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -233,6 +235,7 @@ PLATFORMS
ruby

DEPENDENCIES
audited (~> 4.5)
better_errors!
binding_of_caller
bootstrap-sass (~> 3.3.6)
Expand Down
2 changes: 2 additions & 0 deletions app/models/score_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ class ScoreCard < ApplicationRecord
has_many :questions, through: :score_card_answers

accepts_nested_attributes_for :score_card_answers

audited
end
1 change: 1 addition & 0 deletions app/models/score_card_answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ class ScoreCardAnswer < ApplicationRecord

enum score: { Red: 0, Yellow: 1, Green: 2 }

audited
end
30 changes: 30 additions & 0 deletions db/migrate/20170721031529_install_audited.rb
Original file line number Diff line number Diff line change
@@ -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
24 changes: 23 additions & 1 deletion 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: 20170711030128) do
ActiveRecord::Schema.define(version: 20170721031529) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -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
Expand Down

0 comments on commit 381328e

Please sign in to comment.