2020-08-07 01:14:14 +02:00
|
|
|
class CreateSuppliers < ActiveRecord::Migration[4.2]
|
2021-03-01 15:27:26 +01:00
|
|
|
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?
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
create_table :suppliers do |t|
|
2021-03-01 15:27:26 +01:00
|
|
|
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
|
2021-03-01 15:27:26 +01:00
|
|
|
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")
|
2021-03-01 15:27:26 +01:00
|
|
|
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
|