From f7adce658ef8865aa4afd48d44c690a33a4b6c1a Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 9 Oct 2015 16:45:53 -0400 Subject: [PATCH] Install paper_trail and track all models --- Gemfile | 1 + Gemfile.lock | 6 ++++++ app/models/awaken_type.rb | 2 ++ app/models/card.rb | 2 ++ app/models/character.rb | 2 ++ app/models/leader_skill.rb | 2 ++ app/models/link.rb | 2 ++ app/models/passive_skill.rb | 2 ++ app/models/rarity.rb | 2 ++ app/models/super_attack.rb | 2 ++ app/models/type.rb | 2 ++ app/models/user.rb | 1 + db/migrate/20151009204428_create_versions.rb | 20 ++++++++++++++++++++ db/schema.rb | 13 ++++++++++++- 14 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20151009204428_create_versions.rb diff --git a/Gemfile b/Gemfile index cc61952..280e850 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,7 @@ gem 'simple_form' gem 'omniauth-reddit', :git => 'git://github.com/jackdempsey/omniauth-reddit.git' gem 'active_model_serializers' +gem 'paper_trail' # AUTHORIZATION gem 'pundit' diff --git a/Gemfile.lock b/Gemfile.lock index ef35c8a..6622a0d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -118,6 +118,10 @@ GEM omniauth-oauth2 (1.3.1) oauth2 (~> 1.0) omniauth (~> 1.2) + paper_trail (4.0.0) + activerecord (>= 3.0, < 6.0) + activesupport (>= 3.0, < 6.0) + request_store (~> 1.1) pg (0.18.3) puma (2.14.0) pundit (1.0.1) @@ -163,6 +167,7 @@ GEM thor (>= 0.18.1, < 2.0) rake (10.4.2) rdoc (4.2.0) + request_store (1.2.0) rolify (4.1.1) ruby-graphviz (1.2.2) sass (3.4.18) @@ -225,6 +230,7 @@ DEPENDENCIES jbuilder (~> 2.0) jquery-rails omniauth-reddit! + paper_trail pg puma pundit diff --git a/app/models/awaken_type.rb b/app/models/awaken_type.rb index 7862d09..3caf9cd 100644 --- a/app/models/awaken_type.rb +++ b/app/models/awaken_type.rb @@ -1,3 +1,5 @@ class AwakenType < ActiveRecord::Base + has_paper_trail + validates :name, presence: true end diff --git a/app/models/card.rb b/app/models/card.rb index 1791328..a69e539 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -1,4 +1,6 @@ class Card < ActiveRecord::Base + has_paper_trail + belongs_to :character belongs_to :rarity belongs_to :type diff --git a/app/models/character.rb b/app/models/character.rb index 2f5c3d1..10142fc 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -1,4 +1,6 @@ class Character < ActiveRecord::Base + has_paper_trail + validates :name, presence: true, uniqueness: { case_sensitive: false } diff --git a/app/models/leader_skill.rb b/app/models/leader_skill.rb index 36e8a22..3a493af 100644 --- a/app/models/leader_skill.rb +++ b/app/models/leader_skill.rb @@ -1,3 +1,5 @@ class LeaderSkill < ActiveRecord::Base + has_paper_trail + validates :description, presence: true end diff --git a/app/models/link.rb b/app/models/link.rb index 78cbc00..a3b5b50 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -1,4 +1,6 @@ class Link < ActiveRecord::Base + has_paper_trail + has_and_belongs_to_many :cards validates :name, presence: true, diff --git a/app/models/passive_skill.rb b/app/models/passive_skill.rb index 3a73da0..6eebdbc 100644 --- a/app/models/passive_skill.rb +++ b/app/models/passive_skill.rb @@ -1,4 +1,6 @@ class PassiveSkill < ActiveRecord::Base + has_paper_trail + validates :name, presence: true validates :description, presence: true diff --git a/app/models/rarity.rb b/app/models/rarity.rb index 39e9d46..bfe10ed 100644 --- a/app/models/rarity.rb +++ b/app/models/rarity.rb @@ -1,4 +1,6 @@ class Rarity < ActiveRecord::Base + has_paper_trail + validates :name, presence: true, uniqueness: { case_sensitive: false } validates :description, presence: true diff --git a/app/models/super_attack.rb b/app/models/super_attack.rb index b8cda47..332c480 100644 --- a/app/models/super_attack.rb +++ b/app/models/super_attack.rb @@ -1,4 +1,6 @@ class SuperAttack < ActiveRecord::Base + has_paper_trail + validates :name, presence: true validates :description, presence: true diff --git a/app/models/type.rb b/app/models/type.rb index bfc271d..a88c3e6 100644 --- a/app/models/type.rb +++ b/app/models/type.rb @@ -1,4 +1,6 @@ class Type < ActiveRecord::Base + has_paper_trail + validates :name, presence: true, uniqueness: { case_sensitive: false } validates :description, presence: true diff --git a/app/models/user.rb b/app/models/user.rb index d185b02..e80109e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ class User < ActiveRecord::Base + has_paper_trail rolify after_create :set_admin, if: :first_user? diff --git a/db/migrate/20151009204428_create_versions.rb b/db/migrate/20151009204428_create_versions.rb new file mode 100644 index 0000000..3876dfc --- /dev/null +++ b/db/migrate/20151009204428_create_versions.rb @@ -0,0 +1,20 @@ +class CreateVersions < ActiveRecord::Migration + + # The largest text column available in all supported RDBMS is + # 1024^3 - 1 bytes, roughly one gibibyte. We specify a size + # so that MySQL will use `longtext` instead of `text`. Otherwise, + # when serializing very large objects, `text` might not be big enough. + TEXT_BYTES = 1_073_741_823 + + def change + create_table :versions do |t| + t.string :item_type, :null => false + t.integer :item_id, :null => false + t.string :event, :null => false + t.string :whodunnit + t.text :object, :limit => TEXT_BYTES + t.datetime :created_at + end + add_index :versions, [:item_type, :item_id] + end +end diff --git a/db/schema.rb b/db/schema.rb index 8bd23fe..81bdf6a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151008192100) do +ActiveRecord::Schema.define(version: 20151009204428) do create_table "awaken_types", force: :cascade do |t| t.string "name" @@ -134,4 +134,15 @@ ActiveRecord::Schema.define(version: 20151008192100) do add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id" + create_table "versions", force: :cascade do |t| + t.string "item_type", null: false + t.integer "item_id", null: false + t.string "event", null: false + t.string "whodunnit" + t.text "object", limit: 1073741823 + t.datetime "created_at" + end + + add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id" + end