foodsoft/db/migrate/003_create_suppliers.rb

39 lines
1.5 KiB
Ruby
Raw Permalink Normal View History

class CreateSuppliers < ActiveRecord::Migration[4.2]
SUPPLIER_SAMPLE = 'Sample Supplier'
def self.up
2009-01-06 11:49:19 +01:00
add_column :groups, :role_suppliers, :boolean, :default => false, :null => false
Group.reset_column_information
puts "Give #{CreateGroups::GROUP_ADMIN} the role supplier .."
raise "Failed" unless Group.find_by_name(CreateGroups::GROUP_ADMIN).update_attribute(:role_suppliers, true)
raise "Cannot find admin user!" unless admin = User.find_by_nick(CreateUsers::USER_ADMIN)
raise "Failed to enable role_suppliers with admin user!" unless admin.role_suppliers?
2009-01-06 11:49:19 +01:00
create_table :suppliers do |t|
t.column :name, :string, :null => false
t.column :address, :string, :null => false
t.column :phone, :string, :null => false
2009-01-06 11:49:19 +01:00
t.column :phone2, :string
t.column :fax, :string
t.column :email, :string
t.column :url, :string
t.column :contact_person, :string
t.column :customer_number, :string
t.column :delivery_days, :string
t.column :order_howto, :string
t.column :note, :string
end
add_index(:suppliers, :name, :unique => true)
2009-01-06 11:49:19 +01:00
# Create sample supplier...
puts "Creating sample supplier '#{SUPPLIER_SAMPLE}'..."
Supplier.create(:name => SUPPLIER_SAMPLE, :address => "Organic City", :phone => "0123-555555")
raise "Failed!" unless supplier = Supplier.find_by_name(SUPPLIER_SAMPLE)
2009-01-06 11:49:19 +01:00
end
def self.down
remove_column :groups, :role_suppliers
drop_table :suppliers
end
end