diff --git a/README.md b/README.md index 680886732..5b64f3290 100644 --- a/README.md +++ b/README.md @@ -31,14 +31,22 @@ Add the gem to your Gemfile: gem "audited", "~> 4.7" ``` -Then, from your Rails app directory, create the `audits` table: +Then, from your Rails app directory, create a migration that will add an `audits` table: ```bash $ rails generate audited:install -$ rake db:migrate ``` -If you're using PostgreSQL, then you can use `rails generate audited:install --audited-changes-column-type jsonb` (or `json`) to store audit changes natively with its JSON column types. If you're using something other than integer primary keys (e.g. UUID) for your User model, then you can use `rails generate audited:install --audited-user-id-column-type uuid` to customize the `audits` table `user_id` column type. +You can edit the generated migration and change some column types to better suit your database: + +* **id** columns (`auditable_id`, `associated_id`, `user_id`): their types must match those in the models you are going to audit +* `audited_changes`: the type can alternatively be set to `:json` or `:jsonb` (in PostgreSQL databases) + +After that, create the table by running the migration: + +```bash +$ rake db:migrate +``` #### Upgrading @@ -51,7 +59,6 @@ $ rake db:migrate Upgrading will only make changes if changes are needed. - ## Usage Simply call `audited` on your models: diff --git a/lib/generators/audited/install_generator.rb b/lib/generators/audited/install_generator.rb index bbc5c49c5..2162c0720 100644 --- a/lib/generators/audited/install_generator.rb +++ b/lib/generators/audited/install_generator.rb @@ -12,9 +12,6 @@ class InstallGenerator < Rails::Generators::Base include Audited::Generators::MigrationHelper extend Audited::Generators::Migration - class_option :audited_changes_column_type, type: :string, default: "text", required: false - class_option :audited_user_id_column_type, type: :string, default: "integer", required: false - source_root File.expand_path("../templates", __FILE__) def copy_migration diff --git a/lib/generators/audited/templates/install.rb b/lib/generators/audited/templates/install.rb index 1d43f093c..d29ff0dc6 100644 --- a/lib/generators/audited/templates/install.rb +++ b/lib/generators/audited/templates/install.rb @@ -5,11 +5,11 @@ def self.up t.column :auditable_type, :string t.column :associated_id, :integer t.column :associated_type, :string - t.column :user_id, :<%= options[:audited_user_id_column_type] %> + t.column :user_id, :integer t.column :user_type, :string t.column :username, :string t.column :action, :string - t.column :audited_changes, :<%= options[:audited_changes_column_type] %> + t.column :audited_changes, :text t.column :version, :integer, :default => 0 t.column :comment, :string t.column :remote_address, :string