diff --git a/Gemfile b/Gemfile index bc1a5f7..0c4b682 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index 91f459a..a5994a0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -330,6 +335,7 @@ DEPENDENCIES logger mail ostruct + paper_trail pg pry puma diff --git a/app/models/cloud_init.rb b/app/models/cloud_init.rb index b22372a..ad6b310 100644 --- a/app/models/cloud_init.rb +++ b/app/models/cloud_init.rb @@ -1,4 +1,6 @@ class CloudInit < ActiveRecord::Base + has_paper_trail + validates :name, :template, presence: true before_validation :generate_password_salt, on: :create diff --git a/config/initializers/paper_trail.rb b/config/initializers/paper_trail.rb new file mode 100644 index 0000000..30038ee --- /dev/null +++ b/config/initializers/paper_trail.rb @@ -0,0 +1 @@ +PaperTrail.serializer = PaperTrail::Serializers::JSON diff --git a/db/migrate/20241213122306_create_versions.rb b/db/migrate/20241213122306_create_versions.rb new file mode 100644 index 0000000..ba3f5e4 --- /dev/null +++ b/db/migrate/20241213122306_create_versions.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 329d38f..ff8634d 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[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" @@ -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