Skip to content

Commit

Permalink
[#issue-27] add tenant column to plutus accounts table
Browse files Browse the repository at this point in the history
  • Loading branch information
iffyuva committed Oct 27, 2014
1 parent 73c9754 commit 4d76b47
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class TenantPlutusTables < ActiveRecord::Migration
def change
# add a tenant column to plutus accounts table.
add_column :plutus_accounts, :tenant_id, :string, index: true
end
end
3 changes: 2 additions & 1 deletion fixture_rails_root/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20140224192409) do
ActiveRecord::Schema.define(:version => 20141027103120) do

create_table "plutus_accounts", :force => true do |t|
t.string "name"
t.string "type"
t.boolean "contra"
t.datetime "created_at"
t.datetime "updated_at"
t.string "tenant_id"
end

add_index "plutus_accounts", ["name", "type"], :name => "index_plutus_accounts_on_name_and_type"
Expand Down
6 changes: 6 additions & 0 deletions lib/generators/plutus/templates/tenant_migration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class TenantPlutusTables < ActiveRecord::Migration
def change
# add a tenant column to plutus accounts table.
add_column :plutus_accounts, :tenant_id, :string, index: true
end
end
27 changes: 27 additions & 0 deletions lib/generators/plutus/tenancy_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# lib/generators/plutus/plutus_generator.rb
require 'rails/generators'
require 'rails/generators/migration'

module Plutus
class TenancyGenerator < Rails::Generators::Base
include Rails::Generators::Migration

def self.source_root
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
end

# Implement the required interface for Rails::Generators::Migration.
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
def self.next_migration_number(dirname)
if ActiveRecord::Base.timestamped_migrations
Time.now.utc.strftime("%Y%m%d%H%M%S")
else
"%.3d" % (current_migration_number(dirname) + 1)
end
end

def create_migration_file
migration_template 'tenant_migration.rb', 'db/migrate/tenant_plutus_tables.rb'
end
end
end

0 comments on commit 4d76b47

Please sign in to comment.