Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DBUtil sample Usage
the DBUtil.create_history line shows that only some of the columns are going to have history kept for them. The other columns will be ignored in the user_history table, and the triggers that are created by DBUtil.rb
class CreateUsers < ActiveRecord::Migration
require File.expand_path('db/dbutil.rb')
def self.up
create_table :users do |t|
t.column :login, :string, :null => false
t.references :franchise, :null => false
t.string :first_name
t.string :last_name
t.string :mail
t.column :crypted_password, :string, :null => false
t.column :password_salt, :string, :null => false
t.boolean :active, :null => false, :default => true
t.string :persistence_token
t.integer :login_count
t.datetime :last_request_at
t.datetime :current_login_at
t.datetime :last_login_at
t.string :current_login_ip
t.string :last_login_ip
t.integer :updated_by
t.datetime :updated_at
t.integer :migrate_id
end
DBUtil.create_history('users', 'user_history', columns(:users), Array['franchise_id', 'login', 'first_name', 'last_name', 'mail', 'active'])
end
def self.down
drop_table :users
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment