Skip to content

Commit

Permalink
add paper trail to cloud inits
Browse files Browse the repository at this point in the history
  • Loading branch information
p-wall committed Dec 13, 2024
1 parent 430492d commit fdb0a6c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ gem "jwt_authentication", github: "barsoom/jwt_authentication"
gem "logger" # Ruby 3.5.0 will no longer have this as a part of standard gems. Reason: activesupport 7.1.4
gem "mail"
gem "ostruct" # Ruby 3.5.0 will no longer have this as a part of standard gems. Reason: pry 0.14.2
gem "paper_trail"
gem "pg"
gem "puma"
gem "redis"
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ GEM
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
ostruct (0.6.0)
paper_trail (16.0.0)
activerecord (>= 6.1)
request_store (~> 1.4)
parallel (1.26.3)
parser (3.3.5.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -244,6 +247,8 @@ GEM
regexp_parser (2.9.2)
reline (0.5.10)
io-console (~> 0.5)
request_store (1.7.0)
rack (>= 1.4)
rspec-core (3.13.1)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
Expand Down Expand Up @@ -330,6 +335,7 @@ DEPENDENCIES
logger
mail
ostruct
paper_trail
pg
pry
puma
Expand Down
2 changes: 2 additions & 0 deletions app/models/cloud_init.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class CloudInit < ActiveRecord::Base
has_paper_trail

validates :name, :template, presence: true

before_validation :generate_password_salt, on: :create
Expand Down
1 change: 1 addition & 0 deletions config/initializers/paper_trail.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PaperTrail.serializer = PaperTrail::Serializers::JSON
14 changes: 14 additions & 0 deletions db/migrate/20241213122306_create_versions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateVersions < ActiveRecord::Migration[7.1]
def change
create_table :versions do |t|
t.string :whodunnit
t.datetime :created_at
t.bigint :item_id, null: false
t.string :item_type, null: false
t.string :event, null: false
t.json :object
t.json :object_changes
end
add_index :versions, %i[item_type item_id]
end
end
13 changes: 12 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[7.1].define(version: 2024_12_10_133507) do
ActiveRecord::Schema[7.1].define(version: 2024_12_13_122306) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -48,4 +48,15 @@
t.datetime "updated_at", null: false
end

create_table "versions", force: :cascade do |t|
t.string "whodunnit"
t.datetime "created_at"
t.bigint "item_id", null: false
t.string "item_type", null: false
t.string "event", null: false
t.json "object"
t.json "object_changes"
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
end

end

0 comments on commit fdb0a6c

Please sign in to comment.