Skip to content

Commit

Permalink
update with changes to generated migration scripts, move data populat…
Browse files Browse the repository at this point in the history
…ion to db/seeds.b
  • Loading branch information
Eric Hansen committed Aug 5, 2010
1 parent 1eb3df2 commit 95c6612
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 50 deletions.
11 changes: 9 additions & 2 deletions Gemfile
Expand Up @@ -23,7 +23,11 @@ gem 'faker', '>=0.3.1'
gem "formtastic", :git => "http://github.com/justinfrench/formtastic.git", :branch => "rails3"
gem 'jsmin', '>= 1.0.1'

gem "sqlite3-ruby", :require => "sqlite3"
gem 'fastercsv', '>= 1.5.3'

gem 'thin', '>= 1.2.7'
gem 'rcov'

# Use unicorn as the web server
# gem 'unicorn'
Expand All @@ -35,13 +39,16 @@ gem 'jsmin', '>= 1.0.1'
# gem 'ruby-debug'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri', '1.4.1'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for certain environments:
# gem 'rspec', :group => :test
# group :test do
# gem 'webrat'
# end

if RUBY_VERSION < '1.9'
gem "ruby-debug", ">= 0.10.3"
end

2 changes: 2 additions & 0 deletions db/migrate/20100708230707_fluxx_crm_create_geo_countries.rb
Expand Up @@ -5,6 +5,7 @@ def self.up
t.string :name, :limit => 90, :null => false
t.string :fips104, :iso2, :iso3, :ison, :internet, :capital, :map_reference, :nationality_singular, :nationality_plural, :currency, :currency_code, :population, :title, :limit => 90, :null => true
t.text :comment, :null => true
t.integer :original_id, :limit => 12, :null => false # The original record ID supplied by maxmind
end
add_index :geo_countries, :name, :name => 'country_name_index'
add_index :geo_countries, :iso2, :name => 'country_iso2_index'
Expand All @@ -14,3 +15,4 @@ def self.down
drop_table :geo_countries
end
end

3 changes: 3 additions & 0 deletions db/migrate/20100708230710_fluxx_crm_create_model_documents.rb
Expand Up @@ -9,7 +9,10 @@ def self.up
t.datetime :document_updated_at
t.string :documentable_type, :null => false
t.integer :documentable_id, :null => false, :limit => 12
t.datetime :locked_until, :null => true
t.integer :locked_by_id, :null => true
end
add_index :model_documents, [:documentable_type, :documentable_id]
end

def self.down
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20100708230711_fluxx_crm_create_organizations.rb
Expand Up @@ -22,6 +22,8 @@ def self.up
t.boolean :delta, :null => :false, :default => true
t.datetime :deleted_at, :null => true
t.integer :parent_org_id, :limit => 12, :null => true
t.datetime :locked_until, :null => true
t.integer :locked_by_id, :null => true
end
add_index :organizations, :name, :unique => false
add_index :organizations, :parent_org_id, :unique => false
Expand Down
Expand Up @@ -10,8 +10,12 @@ def self.up
t.string :email, :limit => 400, :null => true
t.string :phone, :limit => 400, :null => true
t.datetime :deleted_at, :null => true
t.datetime :locked_until, :null => true
t.integer :locked_by_id, :null => true
end

add_index :user_organizations, :user_id
add_index :user_organizations, :organization_id
execute "alter table user_organizations add constraint user_org_org_id foreign key (organization_id) references organizations(id)" unless connection.adapter_name =~ /SQLite/i
end

Expand Down
4 changes: 3 additions & 1 deletion db/migrate/20100708230713_fluxx_crm_create_users.rb
Expand Up @@ -3,7 +3,6 @@ def self.up
create_table "users", :force => true do |t|
t.timestamps
t.integer :created_by_id, :updated_by_id, :null => true, :limit => 12
t.text :roles_text
t.string :login, :limit => 40, :null => true
t.string :first_name, :limit => 400, :null => true, :default => ''
t.string :last_name, :limit => 400, :null => true, :default => ''
Expand Down Expand Up @@ -37,9 +36,12 @@ def self.up
t.integer :primary_user_organization_id, :limit => 12, :null => true
t.datetime :last_logged_in_at, :null => true
t.string :time_zone, :limit => 40, :null => :false, :default => (ActiveSupport::TimeZone.us_zones.select{|tz| tz.utc_offset == -28800}).first.name
t.datetime :locked_until, :null => true
t.integer :locked_by_id, :null => true
end
add_index :users, :login, :unique => true
add_index :users, :email, :unique => true

execute "alter table users add constraint users_personal_country_id foreign key (personal_geo_country_id) references geo_countries(id)" unless connection.adapter_name =~ /SQLite/i
execute "alter table users add constraint users_personal_geo_state_id foreign key (personal_geo_state_id) references geo_states(id)" unless connection.adapter_name =~ /SQLite/i
execute "alter table users add constraint users_primary_user_org_id foreign key (primary_user_organization_id) references user_organizations(id)" unless connection.adapter_name =~ /SQLite/i
Expand Down
3 changes: 3 additions & 0 deletions db/migrate/20100708230714_fluxx_crm_create_notes.rb
Expand Up @@ -8,7 +8,10 @@ def self.up
t.integer :notable_id, :null => false, :limit => 12
t.boolean :delta, :null => :false, :default => true
t.datetime :deleted_at, :null => true
t.datetime :locked_until, :null => true
t.integer :locked_by_id, :null => true
end
add_index :notes, [:notable_type, :notable_id]
execute "alter table notes add constraint notes_created_by_id foreign key (created_by_id) references users(id)" unless connection.adapter_name =~ /SQLite/i
execute "alter table notes add constraint notes_updated_by_id foreign key (updated_by_id) references users(id)" unless connection.adapter_name =~ /SQLite/i
end
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20100708230715_fluxx_crm_create_favorites.rb
Expand Up @@ -8,6 +8,7 @@ def self.up
end

execute "alter table favorites add constraint favorites_user_id foreign key (user_id) references users(id)" unless connection.adapter_name =~ /SQLite/i
add_index :favorites, [:favorable_type, :favorable_id]
end

def self.down
Expand Down
9 changes: 0 additions & 9 deletions db/migrate/20100722044543_create_deals.rb
Expand Up @@ -15,19 +15,10 @@ def self.up
t.boolean :delta, :null => :false, :default => true
end

category_group = MultiElementGroup.create :name => 'deal_categories', :description => 'Deal Categories', :target_class_name => 'Deal'
MultiElementValue.create :multi_element_group_id => category_group.id, :value => 'Red'
MultiElementValue.create :multi_element_group_id => category_group.id, :value => 'Yellow'
MultiElementValue.create :multi_element_group_id => category_group.id, :value => 'Green'
MultiElementValue.create :multi_element_group_id => category_group.id, :value => 'Brown'

execute "alter table deals add constraint deals_categories foreign key (category_id) references multi_element_values(id)" unless connection.adapter_name =~ /SQLite/i
end

def self.down
drop_table :deals
group = MultiElementGroup.where(:name => 'deal_categories').first
MultiElementValue.delete_all :multi_element_group_id => group.id
group.destroy
end
end
27 changes: 0 additions & 27 deletions db/migrate/20100723041728_extend_organization.rb
Expand Up @@ -4,39 +4,12 @@ def self.up
add_column :organizations, :num_grants, :integer
add_column :organizations, :assets, :integer
add_column :organizations, :annual_revenue, :integer

software_group = MultiElementGroup.create :name => 'software_types', :description => 'Software', :target_class_name => 'Organization'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'Altum EasyGrants'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'Altum proposalCENTRAL'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'Bromelkamp Pearl (First Pearl, Corporate Pearl, Community Pearl)'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'CloserWare Grantmaker'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'CyberGrants'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'Dulles Technology Partners WebGrants'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'Grantium'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'Foundant Technologies Grant Lifecycle Manager (GLM)'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'Foundation Source'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'Fusion Labs GrantedGE'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'JK Group Grants Management'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'MicroEdge GIFTS'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'MicroEdge FIMS'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'MicroEdge FoundationPower'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'NPower Foundation Grants Manager'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'PhilanTech PhilanTrack'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'Salesforce'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'Stellar Technology Solutions iphi Core'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'Other commercial'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'Custom developed in-house'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'None at this time'
MultiElementValue.create :multi_element_group_id => software_group.id, :value => 'Planned within the next 18 months'
end

def self.down
remove_column :organizations, :num_employees
remove_column :organizations, :num_grants
remove_column :organizations, :assets
remove_column :organizations, :annual_revenue
group = MultiElementGroup.where(:name => 'software_types').first
MultiElementValue.delete_all :multi_element_group_id => group.id
group.destroy
end
end
21 changes: 21 additions & 0 deletions db/migrate/20100804140811_fluxx_crm_create_role_users.rb
@@ -0,0 +1,21 @@
class FluxxCrmCreateRoleUsers < ActiveRecord::Migration
def self.up
create_table :role_users do |t|
t.timestamps
t.integer :created_by_id, :updated_by_id, :null => true, :limit => 12
t.string :name, :null => false
t.integer :user_id, :null => true, :limit => 12
t.string :roleable_type, :null => true
t.integer :roleable_id, :null => true, :limit => 12
end
add_index :role_users, [:name, :roleable_type, :roleable_id]
add_index :role_users, :user_id
execute "alter table role_users add constraint role_users_created_by_id foreign key (created_by_id) references users(id)" unless connection.adapter_name =~ /SQLite/i
execute "alter table role_users add constraint role_users_updated_by_id foreign key (updated_by_id) references users(id)" unless connection.adapter_name =~ /SQLite/i
execute "alter table role_users add constraint role_users_user_id foreign key (user_id) references users(id)" unless connection.adapter_name =~ /SQLite/i
end

def self.down
drop_table :role_users
end
end
53 changes: 42 additions & 11 deletions db/schema.rb
@@ -1,15 +1,16 @@
# This file is auto-generated from the current state of the database. Instead of editing this file,
# please use the migrations feature of Active Record to incrementally modify your database, and
# then regenerate this schema definition.
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
# to create the application database on another system, you should be using db:schema:load, not running
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20100726130632) do
ActiveRecord::Schema.define(:version => 20100804140811) do

create_table "audits", :force => true do |t|
t.datetime "created_at"
Expand Down Expand Up @@ -91,6 +92,7 @@
t.integer "favorable_id", :null => false
end

add_index "favorites", ["favorable_type", "favorable_id"], :name => "index_favorites_on_favorable_type_and_favorable_id"
add_index "favorites", ["user_id"], :name => "favorites_user_id"

create_table "geo_cities", :force => true do |t|
Expand Down Expand Up @@ -129,6 +131,7 @@
t.string "population", :limit => 90
t.string "title", :limit => 90
t.text "comment"
t.integer "original_id", :null => false
end

add_index "geo_countries", ["iso2"], :name => "country_iso2_index"
Expand Down Expand Up @@ -182,8 +185,12 @@
t.datetime "document_updated_at"
t.string "documentable_type", :null => false
t.integer "documentable_id", :null => false
t.datetime "locked_until"
t.integer "locked_by_id"
end

add_index "model_documents", ["documentable_type", "documentable_id"], :name => "index_model_documents_on_documentable_type_and_documentable_id"

create_table "multi_element_choices", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
Expand Down Expand Up @@ -222,9 +229,12 @@
t.integer "notable_id", :null => false
t.boolean "delta", :default => true
t.datetime "deleted_at"
t.datetime "locked_until"
t.integer "locked_by_id"
end

add_index "notes", ["created_by_id"], :name => "notes_created_by_id"
add_index "notes", ["notable_type", "notable_id"], :name => "index_notes_on_notable_type_and_notable_id"
add_index "notes", ["updated_by_id"], :name => "notes_updated_by_id"

create_table "organizations", :force => true do |t|
Expand All @@ -251,6 +261,8 @@
t.boolean "delta", :default => true
t.datetime "deleted_at"
t.integer "parent_org_id"
t.datetime "locked_until"
t.integer "locked_by_id"
t.integer "num_employees"
t.integer "num_grants"
t.integer "assets"
Expand All @@ -260,7 +272,7 @@
add_index "organizations", ["created_by_id"], :name => "organizations_created_by_id"
add_index "organizations", ["geo_country_id"], :name => "organizations_geo_country_id"
add_index "organizations", ["geo_state_id"], :name => "organizations_geo_state_id"
add_index "organizations", ["name"], :name => "index_organizations_on_name", :length => {"name"=>"255"}
add_index "organizations", ["name"], :name => "index_organizations_on_name", :length => {"name"=>"767"}
add_index "organizations", ["parent_org_id"], :name => "index_organizations_on_parent_org_id"
add_index "organizations", ["updated_by_id"], :name => "organizations_updated_by_id"

Expand All @@ -275,6 +287,22 @@
t.text "delta_attributes", :null => false
end

create_table "role_users", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.integer "created_by_id"
t.integer "updated_by_id"
t.string "name", :null => false
t.integer "user_id"
t.string "roleable_type"
t.integer "roleable_id"
end

add_index "role_users", ["created_by_id"], :name => "role_users_created_by_id"
add_index "role_users", ["name", "roleable_type", "roleable_id"], :name => "index_role_users_on_name_and_roleable_type_and_roleable_id"
add_index "role_users", ["updated_by_id"], :name => "role_users_updated_by_id"
add_index "role_users", ["user_id"], :name => "index_role_users_on_user_id"

create_table "user_organizations", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
Expand All @@ -287,19 +315,20 @@
t.string "email", :limit => 400
t.string "phone", :limit => 400
t.datetime "deleted_at"
t.datetime "locked_until"
t.integer "locked_by_id"
end

add_index "user_organizations", ["created_by_id"], :name => "user_organizations_created_by_id"
add_index "user_organizations", ["organization_id"], :name => "user_org_org_id"
add_index "user_organizations", ["organization_id"], :name => "index_user_organizations_on_organization_id"
add_index "user_organizations", ["updated_by_id"], :name => "user_organizations_updated_by_id"
add_index "user_organizations", ["user_id"], :name => "user_org_user_id"
add_index "user_organizations", ["user_id"], :name => "index_user_organizations_on_user_id"

create_table "users", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.integer "created_by_id"
t.integer "updated_by_id"
t.text "roles_text"
t.string "login", :limit => 40
t.string "first_name", :limit => 400, :default => ""
t.string "last_name", :limit => 400, :default => ""
Expand Down Expand Up @@ -333,6 +362,8 @@
t.integer "primary_user_organization_id"
t.datetime "last_logged_in_at"
t.string "time_zone", :limit => 40, :default => "Pacific Time (US & Canada)"
t.datetime "locked_until"
t.integer "locked_by_id"
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "confirmation_token"
Expand Down

0 comments on commit 95c6612

Please sign in to comment.