foodsoft/db/migrate/006_create_articles.rb
Philipp Rothmann fb2b4d8a8a chore: rubocop
chore: fix api test conventions

chore: rubocop -A spec/

chore: more rubocop -A

fix failing test

rubocop fixes

removes helper methods that are in my opinion dead code

more rubocop fixes

rubocop -a --auto-gen-config
2023-06-09 17:35:05 +02:00

36 lines
1.4 KiB
Ruby

class CreateArticles < ActiveRecord::Migration[4.2]
SAMPLE_ARTICLE_NAMES = %w[banana kiwi strawberry]
def self.up
create_table :articles do |t|
t.column :name, :string, null: false
t.column :supplier_id, :integer, null: false
t.column :article_category_id, :integer, null: false
t.column :unit, :string, null: false
t.column :note, :string
t.column :availability, :boolean, default: true, null: false
t.column :current_price_id, :integer
end
add_index(:articles, :name, unique: true)
# Create 30 sample articles...
puts "Create 3 articles of the supplier '#{CreateSuppliers::SUPPLIER_SAMPLE}'..."
raise "Supplier '#{CreateSuppliers::SUPPLIER_SAMPLE}' not found!" unless supplier = Supplier.find_by_name(CreateSuppliers::SUPPLIER_SAMPLE)
raise "Category '#{CreateArticleMeta::CATEGORY_SAMPLE}' not found!" unless category = ArticleCategory.find_by_name(CreateArticleMeta::CATEGORY_SAMPLE)
SAMPLE_ARTICLE_NAMES.each do |a|
puts 'Create Article ' + a
Article.create(name: a,
supplier: supplier,
article_category: category,
unit: '500g',
note: 'delicious',
availability: true)
end
raise 'Failed!' unless Article.find(:all).length == SAMPLE_ARTICLE_NAMES.length
end
def self.down
drop_table :articles
end
end