To prevent table bloat in your main tables, you can configure Logidze to store history data in a separate table instead of the log_data column in the origin table.
Steps to setup detached mode:
- Generate the shared
logidze_data table (run once per project):
bundle exec rails generate logidze:migration:logs - Generate your model with the
--detached option:
bundle exec rails generate logidze:model Post --detached
Global Configuration:
You can set all models to use detached mode by configuring the initializer:
# config/initializers/logidze.rb
Logidze.log_data_placement = :detached
Note: Using --detached mode may slightly decrease performance.
# 1. Create the shared logs table
bundle exec rails generate logidze:migration:logs
# 2. Create a model with detached storage
bundle exec rails generate logidze:model Post --detached
# config/initializers/logidze.rb
Logidze.log_data_placement = :detached