Skip to content

Commit

Permalink
Remove CLI options in favor of manual migration editing
Browse files Browse the repository at this point in the history
  • Loading branch information
vassilevsky committed Apr 4, 2018
1 parent dc72762 commit 9a08f55
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -51,7 +59,6 @@ $ rake db:migrate

Upgrading will only make changes if changes are needed.


## Usage

Simply call `audited` on your models:
Expand Down
3 changes: 0 additions & 3 deletions lib/generators/audited/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/audited/templates/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9a08f55

Please sign in to comment.