Class: IronAdmin::Generators::InstallAuditGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- IronAdmin::Generators::InstallAuditGenerator
- Defined in:
- lib/generators/iron_admin/install_audit/install_audit_generator.rb
Overview
Generator for setting up database-backed audit logging.
Creates the migration for the audit_entries table, which stores a persistent log of all admin panel actions.
Instance Method Summary collapse
-
#create_migration ⇒ void
Writes the audit entries migration into
db/migrate/.
Instance Method Details
#create_migration ⇒ void
This method returns an undefined value.
Writes the audit entries migration into db/migrate/.
We deliberately avoid Rails::Generators::Migration#migration_template
here: that helper goes through ActiveRecord::Migration.current_version
which opens a DB connection to read the schema cache. On a clean
machine (DB doesn't exist yet) or during a deploy where the DB
is briefly unreachable, that crashes the generator with
ActiveRecord::ConnectionNotEstablished and the migration file
never gets written. Using plain template plus a timestamp-based
filename keeps the generator DB-free, so bin/rails db:create db:migrate (the natural bootstrap order) Just Works.
38 39 40 41 42 43 44 45 46 |
# File 'lib/generators/iron_admin/install_audit/install_audit_generator.rb', line 38 def create_migration = Time.now.utc.strftime("%Y%m%d%H%M%S") target = "db/migrate/#{}_create_iron_admin_audit_entries.rb" if existing_audit_migration? say_status :skip, "create_iron_admin_audit_entries migration already exists", :yellow return end template "create_iron_admin_audit_entries.rb.tt", target end |