2020-08-07 01:14:14 +02:00
|
|
|
class CreateSupplierCategories < ActiveRecord::Migration[4.2]
|
2019-11-17 11:41:34 +01:00
|
|
|
class FinancialTransactionClass < ActiveRecord::Base; end
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2019-11-17 11:41:34 +01:00
|
|
|
class SupplierCategory < ActiveRecord::Base; end
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2019-11-17 11:41:34 +01:00
|
|
|
class Supplier < ActiveRecord::Base; end
|
|
|
|
|
|
|
|
def change
|
|
|
|
create_table :supplier_categories do |t|
|
|
|
|
t.string :name, null: false
|
|
|
|
t.string :description
|
|
|
|
t.references :financial_transaction_class, null: false
|
|
|
|
end
|
|
|
|
|
|
|
|
add_reference :suppliers, :supplier_category
|
|
|
|
|
|
|
|
reversible do |dir|
|
|
|
|
dir.up do
|
|
|
|
ftc = FinancialTransactionClass.first
|
|
|
|
sc = SupplierCategory.create name: 'Other', financial_transaction_class_id: ftc.id
|
|
|
|
Supplier.update_all supplier_category_id: sc.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
change_column_null :suppliers, :supplier_category_id, false
|
|
|
|
end
|
|
|
|
end
|