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
This commit is contained in:
Philipp Rothmann 2023-05-12 13:01:12 +02:00 committed by Philipp Rothmann
parent f6fb804bbe
commit fb2b4d8a8a
331 changed files with 4263 additions and 4507 deletions

View file

@ -4,30 +4,31 @@ class CreateUsers < ActiveRecord::Migration[4.2]
def self.up
create_table :users do |t|
t.column :nick, :string, :null => false
t.column :password_hash, :string, :null => false
t.column :password_salt, :string, :null => false
t.column :first_name, :string, :null => false
t.column :last_name, :string, :null => false
t.column :email, :string, :null => false
t.column :nick, :string, null: false
t.column :password_hash, :string, null: false
t.column :password_salt, :string, null: false
t.column :first_name, :string, null: false
t.column :last_name, :string, null: false
t.column :email, :string, null: false
t.column :phone, :string
t.column :address, :string
t.column :created_on, :timestamp, :null => false
t.column :created_on, :timestamp, null: false
end
add_index(:users, :nick, :unique => true)
add_index(:users, :email, :unique => true)
add_index(:users, :nick, unique: true)
add_index(:users, :email, unique: true)
# Create the default admin user...
puts "Creating user #{USER_ADMIN} with password 'secret'..."
user = User.new(:nick => USER_ADMIN, :first_name => "Anton", :last_name => "Administrator", :email => "admin@foo.test")
user.password = "secret"
raise "Failed!" unless user.save && User.find_by_nick(USER_ADMIN).has_password("secret")
user = User.new(nick: USER_ADMIN, first_name: 'Anton', last_name: 'Administrator',
email: 'admin@foo.test')
user.password = 'secret'
raise 'Failed!' unless user.save && User.find_by_nick(USER_ADMIN).has_password('secret')
# Create a normal user...
puts "Creating user #{USER_TEST} with password 'foobar'..."
user = User.new(:nick => USER_TEST, :first_name => "Tim", :last_name => "Tester", :email => "test@foo.test")
user.password = "foobar"
raise "Failed!" unless user.save && User.find_by_nick(USER_TEST).has_password("foobar")
user = User.new(nick: USER_TEST, first_name: 'Tim', last_name: 'Tester', email: 'test@foo.test')
user.password = 'foobar'
raise 'Failed!' unless user.save && User.find_by_nick(USER_TEST).has_password('foobar')
end
def self.down

View file

@ -4,47 +4,48 @@ class CreateGroups < ActiveRecord::Migration[4.2]
def self.up
create_table :groups do |t|
t.column :type, :string, :null => false # inheritance, types: Group, OrderGroup
t.column :name, :string, :null => false
t.column :type, :string, null: false # inheritance, types: Group, OrderGroup
t.column :name, :string, null: false
t.column :description, :string
t.column :actual_size, :integer # OrderGroup column
t.column :account_balance, :decimal, :precision => 8, :scale => 2, :null => false, :default => 0 # OrderGroup column
t.column :account_balance, :decimal, precision: 8, scale: 2, null: false, default: 0 # OrderGroup column
t.column :account_updated, :timestamp # OrderGroup column
t.column :created_on, :timestamp, :null => false
t.column :role_admin, :boolean, :default => false, :null => false
t.column :created_on, :timestamp, null: false
t.column :role_admin, :boolean, default: false, null: false
end
add_index(:groups, :name, :unique => true)
add_index(:groups, :name, unique: true)
create_table :memberships do |t|
t.column :group_id, :integer, :null => false
t.column :user_id, :integer, :null => false
t.column :group_id, :integer, null: false
t.column :user_id, :integer, null: false
end
add_index(:memberships, [:user_id, :group_id], :unique => true)
add_index(:memberships, %i[user_id group_id], unique: true)
# Create the default "Administrators" group...
puts "Creating group #{GROUP_ADMIN}..."
Group.create(:name => GROUP_ADMIN, :description => "System administrators.", :role_admin => true)
Group.create(name: GROUP_ADMIN, description: 'System administrators.', role_admin: true)
raise 'Failed!' unless administrators = Group.find_by_name(GROUP_ADMIN)
# Create a sample order group...
puts "Creating order group #{GROUP_ORDER}..."
ordergroup = OrderGroup.create!(:name => GROUP_ORDER, :description => "A sample order group created by the migration.", :actual_size => 1, :account_updated => Time.now)
raise "Wrong type created!" unless ordergroup.is_a?(OrderGroup)
ordergroup = OrderGroup.create!(name: GROUP_ORDER,
description: 'A sample order group created by the migration.', actual_size: 1, account_updated: Time.now)
raise 'Wrong type created!' unless ordergroup.is_a?(OrderGroup)
# Get the admin user and join the admin group...
raise "User #{CreateUsers::USER_ADMIN} not found, cannot join group '#{administrators.name}'!" unless admin = User.find_by_nick(CreateUsers::USER_ADMIN)
puts "Joining #{CreateUsers::USER_ADMIN} user to new '#{administrators.name}' group as a group admin..."
membership = Membership.create(:group => administrators, :user => admin)
raise "Failed!" unless admin.memberships.first == membership
membership = Membership.create(group: administrators, user: admin)
raise 'Failed!' unless admin.memberships.first == membership
raise "User #{CreateUsers::USER_ADMIN} has no admin_roles" unless admin.role_admin?
# Get the test user and join the order group...
raise "User #{CreateUsers::USER_TEST} not found, cannot join group '#{ordergroup.name}'!" unless test = User.find_by_nick(CreateUsers::USER_TEST)
puts "Joining #{CreateUsers::USER_TEST} user to new '#{ordergroup.name}' group as a group admin..."
membership = Membership.create(:group => ordergroup, :user => test)
raise "Failed!" unless test.memberships.first == membership
membership = Membership.create(group: ordergroup, user: test)
raise 'Failed!' unless test.memberships.first == membership
end
def self.down

View file

@ -2,17 +2,17 @@ class CreateSuppliers < ActiveRecord::Migration[4.2]
SUPPLIER_SAMPLE = 'Sample Supplier'
def self.up
add_column :groups, :role_suppliers, :boolean, :default => false, :null => false
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?
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?
create_table :suppliers do |t|
t.column :name, :string, :null => false
t.column :address, :string, :null => false
t.column :phone, :string, :null => false
t.column :name, :string, null: false
t.column :address, :string, null: false
t.column :phone, :string, null: false
t.column :phone2, :string
t.column :fax, :string
t.column :email, :string
@ -23,12 +23,12 @@ class CreateSuppliers < ActiveRecord::Migration[4.2]
t.column :order_howto, :string
t.column :note, :string
end
add_index(:suppliers, :name, :unique => true)
add_index(:suppliers, :name, unique: true)
# 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)
Supplier.create(name: SUPPLIER_SAMPLE, address: 'Organic City', phone: '0123-555555')
raise 'Failed!' unless supplier = Supplier.find_by_name(SUPPLIER_SAMPLE)
end
def self.down

View file

@ -5,24 +5,24 @@ class CreateArticleMeta < ActiveRecord::Migration[4.2]
def self.up
# Add user roles...
add_column :groups, :role_article_meta, :boolean, :default => false, :null => false
add_column :groups, :role_article_meta, :boolean, default: false, null: false
Group.reset_column_information
puts "Give #{CreateGroups::GROUP_ADMIN} the role article_meta .."
raise "Failed" unless Group.find_by_name(CreateGroups::GROUP_ADMIN).update_attribute(:role_article_meta, true)
raise 'Failed' unless Group.find_by_name(CreateGroups::GROUP_ADMIN).update_attribute(:role_article_meta, true)
raise 'Cannot find admin user!' unless admin = User.find_by_nick(CreateUsers::USER_ADMIN)
raise 'Failed to enable role_article_meta with admin user!' unless admin.role_article_meta?
# ArticleCategories
create_table :article_categories do |t|
t.column :name, :string, :null => false
t.column :name, :string, null: false
t.column :description, :string
end
add_index(:article_categories, :name, :unique => true)
add_index(:article_categories, :name, unique: true)
# Create sample category...
puts "Creating sample article category '#{CATEGORY_SAMPLE}'..."
ArticleCategory.create(:name => CATEGORY_SAMPLE, :description => "This is just a sample article category.")
raise "Failed!" unless category = ArticleCategory.find_by_name(CATEGORY_SAMPLE)
ArticleCategory.create(name: CATEGORY_SAMPLE, description: 'This is just a sample article category.')
raise 'Failed!' unless category = ArticleCategory.find_by_name(CATEGORY_SAMPLE)
end
def self.down

View file

@ -2,19 +2,19 @@ class CreateFinancialTransactions < ActiveRecord::Migration[4.2]
def self.up
# Create Financial Transactions
create_table :financial_transactions do |t|
t.column :order_group_id, :integer, :null => false
t.column :amount, :decimal, :precision => 8, :scale => 2, :null => false
t.column :note, :text, :null => false
t.column :user_id, :integer, :null => false
t.column :created_on, :datetime, :null => false
t.column :order_group_id, :integer, null: false
t.column :amount, :decimal, precision: 8, scale: 2, null: false
t.column :note, :text, null: false
t.column :user_id, :integer, null: false
t.column :created_on, :datetime, null: false
end
# add column for the finance role
puts 'add column in "groups" for the finance role'
add_column :groups, :role_finance, :boolean, :default => false, :null => false
add_column :groups, :role_finance, :boolean, default: false, null: false
Group.reset_column_information
puts "Give #{CreateGroups::GROUP_ADMIN} the role finance .."
raise "Failed" unless Group.find_by_name(CreateGroups::GROUP_ADMIN).update_attribute(:role_finance, true)
raise 'Failed' unless Group.find_by_name(CreateGroups::GROUP_ADMIN).update_attribute(:role_finance, true)
raise 'Cannot find admin user!' unless admin = User.find_by_nick(CreateUsers::USER_ADMIN)
raise 'Failed to enable role_finance with admin user!' unless admin.role_finance?
@ -27,8 +27,8 @@ class CreateFinancialTransactions < ActiveRecord::Migration[4.2]
ordergroup.addFinancialTransaction(i, "Sample Transaction Nr. #{i}", admin)
balance += i
end
raise "Failed!" unless financial_transaction = FinancialTransaction.find_by_note('Sample Transaction Nr. 1')
raise "Failed to update account_balance!" unless OrderGroup.find(ordergroup.id).account_balance == balance
raise 'Failed!' unless financial_transaction = FinancialTransaction.find_by_note('Sample Transaction Nr. 1')
raise 'Failed to update account_balance!' unless OrderGroup.find(ordergroup.id).account_balance == balance
end
def self.down

View file

@ -1,17 +1,17 @@
class CreateArticles < ActiveRecord::Migration[4.2]
SAMPLE_ARTICLE_NAMES = ['banana', 'kiwi', 'strawberry']
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 :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 :availability, :boolean, default: true, null: false
t.column :current_price_id, :integer
end
add_index(:articles, :name, :unique => true)
add_index(:articles, :name, unique: true)
# Create 30 sample articles...
puts "Create 3 articles of the supplier '#{CreateSuppliers::SUPPLIER_SAMPLE}'..."
@ -20,14 +20,14 @@ class CreateArticles < ActiveRecord::Migration[4.2]
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)
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
raise 'Failed!' unless Article.find(:all).length == SAMPLE_ARTICLE_NAMES.length
end
def self.down

View file

@ -1,13 +1,13 @@
class CreateArticlePrices < ActiveRecord::Migration[4.2]
def self.up
create_table :article_prices do |t|
t.column :article_id, :int, :null => false
t.column :clear_price, :decimal, :precision => 8, :scale => 2, :null => false
t.column :gross_price, :decimal, :precision => 8, :scale => 2, :null => false # gross price, incl. vat, refund and price markup
t.column :tax, :float, :null => false, :default => 0
t.column :refund, :decimal, :precision => 8, :scale => 2, :null => false, :default => 0
t.column :article_id, :int, null: false
t.column :clear_price, :decimal, precision: 8, scale: 2, null: false
t.column :gross_price, :decimal, precision: 8, scale: 2, null: false # gross price, incl. vat, refund and price markup
t.column :tax, :float, null: false, default: 0
t.column :refund, :decimal, precision: 8, scale: 2, null: false, default: 0
t.column :updated_on, :datetime
t.column :unit_quantity, :int, :default => 1, :null => false
t.column :unit_quantity, :int, default: 1, null: false
t.column :order_number, :string
end
add_index(:article_prices, :article_id)
@ -18,11 +18,11 @@ class CreateArticlePrices < ActiveRecord::Migration[4.2]
puts 'Create Price for article ' + a
raise "article #{a} not found!" unless article = Article.find_by_name(a)
new_price = ArticlePrice.new(:clear_price => rand(4) + 1,
:tax => 7.0,
:refund => 0,
:unit_quantity => rand(10) + 1,
:order_number => rand(9999))
new_price = ArticlePrice.new(clear_price: rand(1..4),
tax: 7.0,
refund: 0,
unit_quantity: rand(1..10),
order_number: rand(9999))
article.add_price(new_price)
raise 'Failed!' unless ArticlePrice.find_by_article_id(article.id)
end

View file

@ -4,28 +4,28 @@ class CreateOrders < ActiveRecord::Migration[4.2]
def self.up
# Order role
add_column :groups, :role_orders, :boolean, :default => false, :null => false
add_column :groups, :role_orders, :boolean, default: false, null: false
Group.reset_column_information
puts "Give #{CreateGroups::GROUP_ADMIN} the role finance .."
raise "Failed" unless Group.find_by_name(CreateGroups::GROUP_ADMIN).update_attribute(:role_orders, true)
raise 'Failed' unless Group.find_by_name(CreateGroups::GROUP_ADMIN).update_attribute(:role_orders, true)
raise 'Cannot find admin user!' unless admin = User.find_by_nick(CreateUsers::USER_ADMIN)
raise 'Failed to enable role_orders with admin user!' unless admin.role_orders?
# Create the default "Order" group...
puts 'Creating group "Orders"...'
Group.create(:name => GROUP_ORDER, :description => "working group for managing orders", :role_orders => true)
raise "Failed!" unless Group.find_by_name(GROUP_ORDER)
Group.create(name: GROUP_ORDER, description: 'working group for managing orders', role_orders: true)
raise 'Failed!' unless Group.find_by_name(GROUP_ORDER)
# Order
create_table :orders do |t|
t.column :name, :string, :null => false
t.column :supplier_id, :integer, :null => false
t.column :starts, :datetime, :null => false
t.column :name, :string, null: false
t.column :supplier_id, :integer, null: false
t.column :starts, :datetime, null: false
t.column :ends, :datetime
t.column :note, :string
t.column :finished, :boolean, :default => false, :null => false
t.column :booked, :boolean, :null => false, :default => false
t.column :lock_version, :integer, :null => false, :default => 0
t.column :finished, :boolean, default: false, null: false
t.column :booked, :boolean, null: false, default: false
t.column :lock_version, :integer, null: false, default: 0
t.column :updated_by_user_id, :integer
end
add_index(:orders, :starts)
@ -35,74 +35,77 @@ class CreateOrders < ActiveRecord::Migration[4.2]
puts "Creating order '#{ORDER_TEST}'..."
raise "Supplier '#{CreateSuppliers::SUPPLIER_SAMPLE}' not found!" unless supplier = Supplier.find_by_name(CreateSuppliers::SUPPLIER_SAMPLE)
Order.create(:name => ORDER_TEST, :supplier => supplier, :starts => Time.now)
Order.create(name: ORDER_TEST, supplier: supplier, starts: Time.now)
raise 'Creating test order failed!' unless order = Order.find_by_name(ORDER_TEST)
# OrderArticle
create_table :order_articles do |t|
t.column :order_id, :integer, :null => false
t.column :article_id, :integer, :null => false
t.column :quantity, :integer, :null => false, :default => 0
t.column :tolerance, :integer, :null => false, :default => 0
t.column :units_to_order, :integer, :null => false, :default => 0
t.column :lock_version, :integer, :null => false, :default => 0
t.column :order_id, :integer, null: false
t.column :article_id, :integer, null: false
t.column :quantity, :integer, null: false, default: 0
t.column :tolerance, :integer, null: false, default: 0
t.column :units_to_order, :integer, null: false, default: 0
t.column :lock_version, :integer, null: false, default: 0
end
add_index(:order_articles, [:order_id, :article_id], :unique => true)
add_index(:order_articles, %i[order_id article_id], unique: true)
puts 'Adding articles to the order...'
CreateArticles::SAMPLE_ARTICLE_NAMES.each { |a|
CreateArticles::SAMPLE_ARTICLE_NAMES.each do |a|
puts "Article #{a}..."
raise 'Article not found!' unless article = Article.find_by_name(a)
raise 'No price found for article!' unless price = article.current_price
OrderArticle.create(:order => order, :article => article)
OrderArticle.create(order: order, article: article)
raise 'Creating OrderArticle failed!' unless OrderArticle.find_by_order_id_and_article_id(order.id, article.id)
}
end
raise 'Creating OrderArticles failed!' unless order.articles.size == CreateArticles::SAMPLE_ARTICLE_NAMES.length
# GroupOrder
create_table :group_orders do |t|
t.column :order_group_id, :integer, :null => false
t.column :order_id, :integer, :null => false
t.column :price, :decimal, :precision => 8, :scale => 2, :null => false, :default => 0
t.column :lock_version, :integer, :null => false, :default => 0
t.column :updated_on, :timestamp, :null => false
t.column :updated_by_user_id, :integer, :null => false
t.column :order_group_id, :integer, null: false
t.column :order_id, :integer, null: false
t.column :price, :decimal, precision: 8, scale: 2, null: false, default: 0
t.column :lock_version, :integer, null: false, default: 0
t.column :updated_on, :timestamp, null: false
t.column :updated_by_user_id, :integer, null: false
end
add_index(:group_orders, [:order_group_id, :order_id], :unique => true)
add_index(:group_orders, %i[order_group_id order_id], unique: true)
puts 'Adding group order...'
raise "Cannot find user #{CreateUsers::USER_TEST}" unless user = User.find_by_nick(CreateUsers::USER_TEST)
raise "Cannot find OrderGroup '#{CreateGroups::GROUP_ORDER}'!" unless orderGroup = OrderGroup.find_by_name(CreateGroups::GROUP_ORDER)
GroupOrder.create(:order_group => orderGroup, :order => order, :price => 0, :updated_by => user)
raise 'Retrieving group order failed!' unless groupOrder = orderGroup.group_orders.find(:first, :conditions => "order_id = #{order.id}")
GroupOrder.create(order_group: orderGroup, order: order, price: 0, updated_by: user)
raise 'Retrieving group order failed!' unless groupOrder = orderGroup.group_orders.find(:first,
conditions: "order_id = #{order.id}")
# GroupOrderArticles
create_table :group_order_articles do |t|
t.column :group_order_id, :integer, :null => false
t.column :order_article_id, :integer, :null => false
t.column :quantity, :integer, :null => false
t.column :tolerance, :integer, :null => false
t.column :updated_on, :timestamp, :null => false
t.column :group_order_id, :integer, null: false
t.column :order_article_id, :integer, null: false
t.column :quantity, :integer, null: false
t.column :tolerance, :integer, null: false
t.column :updated_on, :timestamp, null: false
end
add_index(:group_order_articles, [:group_order_id, :order_article_id], :unique => true, :name => "goa_index")
add_index(:group_order_articles, %i[group_order_id order_article_id], unique: true, name: 'goa_index')
# GroupOrderArticleQuantity
create_table :group_order_article_quantities do |t|
t.column :group_order_article_id, :int, :null => false
t.column :quantity, :int, :default => 0
t.column :tolerance, :int, :default => 0
t.column :created_on, :timestamp, :null => false
t.column :group_order_article_id, :int, null: false
t.column :quantity, :int, default: 0
t.column :tolerance, :int, default: 0
t.column :created_on, :timestamp, null: false
end
puts 'Adding articles to group order...'
order.order_articles.each { |orderArticle|
order.order_articles.each do |orderArticle|
puts "Article #{orderArticle.article.name}..."
GroupOrderArticle.create(:group_order => groupOrder, :order_article => orderArticle, :quantity => 0, :tolerance => 0)
raise 'Failed to create order!' unless article = GroupOrderArticle.find(:first, :conditions => "group_order_id = #{groupOrder.id} AND order_article_id = #{orderArticle.id}")
GroupOrderArticle.create(group_order: groupOrder, order_article: orderArticle, quantity: 0,
tolerance: 0)
raise 'Failed to create order!' unless article = GroupOrderArticle.find(:first,
conditions: "group_order_id = #{groupOrder.id} AND order_article_id = #{orderArticle.id}")
article.updateQuantities(rand(6) + 1, rand(4) + 1)
}
article.updateQuantities(rand(1..6), rand(1..4))
end
raise 'Failed to create orders!' unless groupOrder.order_articles.size == order.order_articles.size
groupOrder.updatePrice

View file

@ -1,32 +1,32 @@
class CreateOrderResults < ActiveRecord::Migration[4.2]
def self.up
create_table :group_order_results do |t|
t.column :order_id, :int, :null => false
t.column :group_name, :string, :null => false
t.column :price, :decimal, :precision => 8, :scale => 2, :null => false, :default => 0
t.column :order_id, :int, null: false
t.column :group_name, :string, null: false
t.column :price, :decimal, precision: 8, scale: 2, null: false, default: 0
end
add_index(:group_order_results, [:group_name, :order_id], :unique => true)
add_index(:group_order_results, %i[group_name order_id], unique: true)
create_table :order_article_results do |t|
t.column :order_id, :int, :null => false
t.column :name, :string, :null => false
t.column :unit, :string, :null => false
t.column :order_id, :int, null: false
t.column :name, :string, null: false
t.column :unit, :string, null: false
t.column :note, :string
t.column :clear_price, :decimal, :precision => 8, :scale => 2, :null => false
t.column :gross_price, :decimal, :precision => 8, :scale => 2, :null => false
t.column :tax, :float, :null => false, :default => 0
t.column :refund, :decimal, :precision => 8, :scale => 2
t.column :fc_markup, :float, :null => false
t.column :clear_price, :decimal, precision: 8, scale: 2, null: false
t.column :gross_price, :decimal, precision: 8, scale: 2, null: false
t.column :tax, :float, null: false, default: 0
t.column :refund, :decimal, precision: 8, scale: 2
t.column :fc_markup, :float, null: false
t.column :order_number, :string
t.column :unit_quantity, :int, :null => false
t.column :units_to_order, :int, :null => false
t.column :unit_quantity, :int, null: false
t.column :units_to_order, :int, null: false
end
add_index(:order_article_results, :order_id)
create_table :group_order_article_results do |t|
t.column :order_article_result_id, :int, :null => false
t.column :group_order_result_id, :int, :null => false
t.column :quantity, :int, :null => false
t.column :order_article_result_id, :int, null: false
t.column :group_order_result_id, :int, null: false
t.column :quantity, :int, null: false
t.column :tolerance, :int
end
add_index(:group_order_article_results, :order_article_result_id)

View file

@ -1,16 +1,16 @@
class CreateComments < ActiveRecord::Migration[4.2]
def self.up
create_table :comments, :force => true do |t|
t.column :title, :string, :limit => 50, :default => ""
t.column :comment, :string, :default => ""
t.column :created_at, :datetime, :null => false
t.column :commentable_id, :integer, :default => 0, :null => false
t.column :commentable_type, :string, :limit => 15,
:default => "", :null => false
t.column :user_id, :integer, :default => 0, :null => false
create_table :comments, force: true do |t|
t.column :title, :string, limit: 50, default: ''
t.column :comment, :string, default: ''
t.column :created_at, :datetime, null: false
t.column :commentable_id, :integer, default: 0, null: false
t.column :commentable_type, :string, limit: 15,
default: '', null: false
t.column :user_id, :integer, default: 0, null: false
end
add_index :comments, ["user_id"], :name => "fk_comments_user"
add_index :comments, ['user_id'], name: 'fk_comments_user'
end
def self.down

View file

@ -1,8 +1,8 @@
class CreateOrderClearing < ActiveRecord::Migration[4.2]
def self.up
add_column :orders, :invoice_amount, :decimal, :precision => 8, :scale => 2, :null => false, :default => 0
add_column :orders, :refund, :decimal, :precision => 8, :scale => 2, :null => false, :default => 0
add_column :orders, :refund_credit, :decimal, :precision => 8, :scale => 2, :null => false, :default => 0
add_column :orders, :invoice_amount, :decimal, precision: 8, scale: 2, null: false, default: 0
add_column :orders, :refund, :decimal, precision: 8, scale: 2, null: false, default: 0
add_column :orders, :refund_credit, :decimal, precision: 8, scale: 2, null: false, default: 0
add_column :orders, :invoice_number, :string
add_column :orders, :invoice_date, :string
end

View file

@ -3,13 +3,13 @@ class AddMessaging < ActiveRecord::Migration[4.2]
# Table that holds the messages:
create_table :messages do |t|
t.column :sender_id, :integer
t.column :recipient_id, :integer, :null => false
t.column :recipients, :string, :null => false
t.column :subject, :string, :null => false
t.column :body, :text, :null => false
t.column :read, :boolean, :null => false, :default => false
t.column :email_state, :integer, :null => false
t.column :created_on, :timestamp, :null => false
t.column :recipient_id, :integer, null: false
t.column :recipients, :string, null: false
t.column :subject, :string, null: false
t.column :body, :text, null: false
t.column :read, :boolean, null: false, default: false
t.column :email_state, :integer, null: false
t.column :created_on, :timestamp, null: false
end
add_index(:messages, :sender_id)
add_index(:messages, :recipient_id)

View file

@ -1,26 +1,26 @@
class CreateTasks < ActiveRecord::Migration[4.2]
def self.up
create_table :tasks do |t|
t.column :name, :string, :null => false
t.column :name, :string, null: false
t.column :description, :string
t.column :due_date, :date
t.column :done, :boolean, :default => false
t.column :done, :boolean, default: false
t.column :group_id, :integer
t.column :assigned, :boolean, :default => false
t.column :created_on, :datetime, :null => false
t.column :updated_on, :datetime, :null => false
t.column :assigned, :boolean, default: false
t.column :created_on, :datetime, null: false
t.column :updated_on, :datetime, null: false
end
add_index :tasks, :name
add_index :tasks, :due_date
create_table :assignments do |t|
t.column :user_id, :integer, :null => false
t.column :task_id, :integer, :null => false
t.column :accepted, :boolean, :default => false
t.column :user_id, :integer, null: false
t.column :task_id, :integer, null: false
t.column :accepted, :boolean, default: false
end
add_index :assignments, [:user_id, :task_id], :unique => true
add_index :assignments, %i[user_id task_id], unique: true
add_column :groups, :weekly_task, :boolean, :default => false # if group has an job for every week
add_column :groups, :weekly_task, :boolean, default: false # if group has an job for every week
add_column :groups, :weekday, :integer # e.g. 1 means monday, 2 = tuesday an so on
add_column :groups, :task_name, :string # the name of the weekly task
add_column :groups, :task_description, :string

View file

@ -1,11 +1,11 @@
class ChangeResultQuantities < ActiveRecord::Migration[4.2]
def self.up
change_column :group_order_article_results, :quantity, :decimal, :precision => 6, :scale => 3
change_column :order_article_results, :units_to_order, :decimal, :precision => 6, :scale => 3, :null => false
change_column :group_order_article_results, :quantity, :decimal, precision: 6, scale: 3
change_column :order_article_results, :units_to_order, :decimal, precision: 6, scale: 3, null: false
end
def self.down
change_column :group_order_article_results, :quantity, :integer, :null => false
change_column :order_article_results, :units_to_order, :integer, :default => 0, :null => false
change_column :group_order_article_results, :quantity, :integer, null: false
change_column :order_article_results, :units_to_order, :integer, default: 0, null: false
end
end

View file

@ -1,11 +1,11 @@
class CreateInvites < ActiveRecord::Migration[4.2]
def self.up
create_table :invites do |t|
t.column :token, :string, :null => false
t.column :expires_at, :timestamp, :null => false
t.column :group_id, :integer, :null => false
t.column :user_id, :integer, :null => false
t.column :email, :string, :null => false
t.column :token, :string, null: false
t.column :expires_at, :timestamp, null: false
t.column :group_id, :integer, null: false
t.column :user_id, :integer, null: false
t.column :email, :string, null: false
end
add_index :invites, :token
end

View file

@ -1,11 +1,11 @@
class RemoveUniquenessOfArticleName < ActiveRecord::Migration[4.2]
def self.up
remove_index :articles, :name
add_index :articles, [:name, :supplier_id]
add_index :articles, %i[name supplier_id]
end
def self.down
remove_index :articles, [:name, :supplier_id]
add_index :articles, :name, :unique => true
remove_index :articles, %i[name supplier_id]
add_index :articles, :name, unique: true
end
end

View file

@ -1,19 +1,19 @@
class RemoveTableArticlePrices < ActiveRecord::Migration[4.2]
def self.up
puts "create columns in articles ..."
add_column "articles", "clear_price", :decimal, :precision => 8, :scale => 2, :default => 0.0, :null => false
add_column "articles", "gross_price", :decimal, :precision => 8, :scale => 2, :default => 0.0, :null => false
add_column "articles", "tax", :float
add_column "articles", "refund", :decimal, :precision => 8, :scale => 2, :default => 0.0, :null => false
add_column "articles", "unit_quantity", :integer, :default => 1, :null => false
add_column "articles", "order_number", :string
add_column "articles", "created_at", :datetime
add_column "articles", "updated_at", :datetime
puts 'create columns in articles ...'
add_column 'articles', 'clear_price', :decimal, precision: 8, scale: 2, default: 0.0, null: false
add_column 'articles', 'gross_price', :decimal, precision: 8, scale: 2, default: 0.0, null: false
add_column 'articles', 'tax', :float
add_column 'articles', 'refund', :decimal, precision: 8, scale: 2, default: 0.0, null: false
add_column 'articles', 'unit_quantity', :integer, default: 1, null: false
add_column 'articles', 'order_number', :string
add_column 'articles', 'created_at', :datetime
add_column 'articles', 'updated_at', :datetime
# stop auto-updating the timestamps to make the data-copy safe!
Article.record_timestamps = false
puts "now copy values of article_prices into new articles-columns..."
puts 'now copy values of article_prices into new articles-columns...'
Article.find(:all).each do |article|
price = article.current_price
article.update!(clear_price: price.clear_price,
@ -26,46 +26,46 @@ class RemoveTableArticlePrices < ActiveRecord::Migration[4.2]
created_at: price.updated_on)
end
puts "delete article_prices, current_price attribute"
puts 'delete article_prices, current_price attribute'
drop_table :article_prices
remove_column :articles, :current_price_id
end
def self.down
add_column :articles, :current_price_id, :integer
create_table "article_prices", :force => true do |t|
t.integer "article_id", :default => 0, :null => false
t.decimal "clear_price", :precision => 8, :scale => 2, :default => 0.0, :null => false
t.decimal "gross_price", :precision => 8, :scale => 2, :default => 0.0, :null => false
t.float "tax", :default => 0.0, :null => false
t.decimal "refund", :precision => 8, :scale => 2, :default => 0.0, :null => false
t.datetime "updated_on"
t.integer "unit_quantity", :default => 1, :null => false
t.string "order_number"
create_table 'article_prices', force: true do |t|
t.integer 'article_id', default: 0, null: false
t.decimal 'clear_price', precision: 8, scale: 2, default: 0.0, null: false
t.decimal 'gross_price', precision: 8, scale: 2, default: 0.0, null: false
t.float 'tax', default: 0.0, null: false
t.decimal 'refund', precision: 8, scale: 2, default: 0.0, null: false
t.datetime 'updated_on'
t.integer 'unit_quantity', default: 1, null: false
t.string 'order_number'
end
# copy data from article now into old ArticlePrice-object
Article.find(:all).each do |article|
price = ArticlePrice.create(:clear_price => article.clear_price,
:gross_price => article.gross_price,
:tax => article.tax,
:refund => article.refund,
:unit_quantity => article.unit_quantity,
:order_number => article.order_number.blank? ? nil : article.order_number,
:updated_on => article.updated_at)
price = ArticlePrice.create(clear_price: article.clear_price,
gross_price: article.gross_price,
tax: article.tax,
refund: article.refund,
unit_quantity: article.unit_quantity,
order_number: article.order_number.presence,
updated_on: article.updated_at)
article.update_attribute(:current_price, price)
price.update_attribute(:article, article)
end
# remove new columns
remove_column "articles", "clear_price"
remove_column "articles", "gross_price"
remove_column "articles", "tax"
remove_column "articles", "refund"
remove_column "articles", "unit_quantity"
remove_column "articles", "order_number"
remove_column "articles", "created_at"
remove_column "articles", "updated_at"
remove_column 'articles', 'clear_price'
remove_column 'articles', 'gross_price'
remove_column 'articles', 'tax'
remove_column 'articles', 'refund'
remove_column 'articles', 'unit_quantity'
remove_column 'articles', 'order_number'
remove_column 'articles', 'created_at'
remove_column 'articles', 'updated_at'
end
end

View file

@ -1,7 +1,7 @@
class AddRequiredUserForTask < ActiveRecord::Migration[4.2]
def self.up
add_column :tasks, :required_users, :integer, :default => 1
add_column :groups, :task_required_users, :integer, :default => 1
add_column :tasks, :required_users, :integer, default: 1
add_column :groups, :task_required_users, :integer, default: 1
# add default values to every task and group
Task.find(:all).each { |task| task.update_attribute :required_users, 1 }
Group.workgroups.each { |group| group.update_attribute :task_required_users, 1 }

View file

@ -7,6 +7,5 @@ class AddDepositDefaults < ActiveRecord::Migration[4.2]
change_column_default :orders, :deposit_credit, 0.0
end
def self.down
end
def self.down; end
end

View file

@ -1,9 +1,9 @@
class ExtendComments < ActiveRecord::Migration[4.2]
def self.up
change_column :comments, :comment, :text, :default => ""
change_column :comments, :comment, :text, default: ''
end
def self.down
change_column :comments, :comment, :string, :default => ""
change_column :comments, :comment, :string, default: ''
end
end

View file

@ -10,10 +10,10 @@ class RoadToVersionThree < ActiveRecord::Migration[4.2]
create_table :messages do |t|
t.references :sender
t.text :recipients_ids
t.string :subject, :null => false
t.string :subject, null: false
t.text :body
t.integer :email_state, :default => 0, :null => false
t.boolean :private, :default => false
t.integer :email_state, default: 0, null: false
t.boolean :private, default: false
t.datetime :created_at
end
@ -23,9 +23,9 @@ class RoadToVersionThree < ActiveRecord::Migration[4.2]
add_column :groups, :deleted_at, :datetime
# == Workgroups
puts "Migrate all groups to workgroups.."
Group.find(:all, :conditions => { :type => "" }).each do |workgroup|
workgroup.update_attribute(:type, "Workgroup")
puts 'Migrate all groups to workgroups..'
Group.find(:all, conditions: { type: '' }).each do |workgroup|
workgroup.update_attribute(:type, 'Workgroup')
end
# == Ordergroups
@ -34,11 +34,11 @@ class RoadToVersionThree < ActiveRecord::Migration[4.2]
rename_column :financial_transactions, :order_group_id, :ordergroup_id
rename_column :group_orders, :order_group_id, :ordergroup_id
rename_column :tasks, :group_id, :workgroup_id
remove_index :group_orders, :name => "index_group_orders_on_order_group_id_and_order_id"
add_index :group_orders, [:ordergroup_id, :order_id], :unique => true
remove_index :group_orders, name: 'index_group_orders_on_order_group_id_and_order_id'
add_index :group_orders, %i[ordergroup_id order_id], unique: true
Group.find(:all, :conditions => { :type => "OrderGroup" }).each do |ordergroup|
ordergroup.update_attribute(:type, "Ordergroup")
Group.find(:all, conditions: { type: 'OrderGroup' }).each do |ordergroup|
ordergroup.update_attribute(:type, 'Ordergroup')
end
# move contact-infos from users to ordergroups
add_column :groups, :contact_person, :string
@ -46,9 +46,7 @@ class RoadToVersionThree < ActiveRecord::Migration[4.2]
add_column :groups, :contact_address, :string
Ordergroup.all.each do |ordergroup|
contact = ordergroup.users.first
if contact
ordergroup.update(contact_person: contact.name, contact_phone: contact.phone, contact_address: contact.address)
end
ordergroup.update(contact_person: contact.name, contact_phone: contact.phone, contact_address: contact.address) if contact
end
remove_column :users, :address
@ -57,15 +55,18 @@ class RoadToVersionThree < ActiveRecord::Migration[4.2]
drop_table :group_order_results
drop_table :order_article_results
drop_table :group_order_article_results
GroupOrder.delete_all; OrderArticle.delete_all; GroupOrderArticle.delete_all; GroupOrderArticleQuantity.delete_all
GroupOrder.delete_all
OrderArticle.delete_all
GroupOrderArticle.delete_all
GroupOrderArticleQuantity.delete_all
create_table :orders do |t|
t.references :supplier
t.text :note
t.datetime :starts
t.datetime :ends
t.string :state, :default => "open" # Statemachine ... open -> finished -> closed
t.integer :lock_version, :default => 0, :null => false
t.string :state, default: 'open' # Statemachine ... open -> finished -> closed
t.integer :lock_version, default: 0, null: false
t.integer :updated_by_user_id
end
@ -78,9 +79,9 @@ class RoadToVersionThree < ActiveRecord::Migration[4.2]
t.date :date
t.date :paid_on
t.text :note
t.decimal :amount, :null => false, :precision => 8, :scale => 2, :default => 0.0
t.decimal :deposit, :precision => 8, :scale => 2, :default => 0.0, :null => false
t.decimal :deposit_credit, :precision => 8, :scale => 2, :default => 0.0, :null => false
t.decimal :amount, null: false, precision: 8, scale: 2, default: 0.0
t.decimal :deposit, precision: 8, scale: 2, default: 0.0, null: false
t.decimal :deposit_credit, precision: 8, scale: 2, default: 0.0, null: false
t.timestamps
end
@ -107,41 +108,41 @@ class RoadToVersionThree < ActiveRecord::Migration[4.2]
# == ArticlePrice
create_table :article_prices do |t|
t.references :article
t.decimal :price, :precision => 8, :scale => 2, :default => 0.0, :null => false
t.decimal :tax, :precision => 8, :scale => 2, :default => 0.0, :null => false
t.decimal :deposit, :precision => 8, :scale => 2, :default => 0.0, :null => false
t.decimal :price, precision: 8, scale: 2, default: 0.0, null: false
t.decimal :tax, precision: 8, scale: 2, default: 0.0, null: false
t.decimal :deposit, precision: 8, scale: 2, default: 0.0, null: false
t.integer :unit_quantity
t.datetime :created_at
end
# Create price history for every Article
Article.all.each do |a|
a.article_prices.create :price => a.price, :tax => a.tax,
:deposit => a.deposit, :unit_quantity => a.unit_quantity
a.article_prices.create price: a.price, tax: a.tax,
deposit: a.deposit, unit_quantity: a.unit_quantity
end
# Every Article has now a Category. Fix it if neccessary.
Article.all(:conditions => { :article_category_id => nil }).each do |article|
Article.all(conditions: { article_category_id: nil }).each do |article|
article.update_attribute(:article_category, ArticleCategory.first)
end
# order-articles
add_column :order_articles, :article_price_id, :integer
# == GroupOrder
change_column :group_orders, :updated_by_user_id, :integer, :default => nil, :null => true
change_column :group_orders, :updated_by_user_id, :integer, default: nil, null: true
# == GroupOrderArticle
# The total order result in ordergroup is now saved!
add_column :group_order_articles, :result, :integer, :default => nil
add_column :group_order_articles, :result, :integer, default: nil
# == StockArticle
add_column :articles, :type, :string
add_column :articles, :quantity, :integer, :default => 0
add_column :articles, :quantity, :integer, default: 0
# == StockChanges
create_table :stock_changes do |t|
t.references :delivery
t.references :order
t.references :stock_article
t.integer :quantity, :default => 0
t.integer :quantity, default: 0
t.datetime :created_at
end
@ -158,6 +159,5 @@ class RoadToVersionThree < ActiveRecord::Migration[4.2]
User.all.each { |u| u.settings['notify.upcoming_tasks'] = 1 }
end
def self.down
end
def self.down; end
end

View file

@ -1,6 +1,6 @@
class AddProfitToOrders < ActiveRecord::Migration[4.2]
def self.up
add_column :orders, :foodcoop_result, :decimal, :precision => 8, :scale => 2
add_column :orders, :foodcoop_result, :decimal, precision: 8, scale: 2
Order.closed.each do |order|
order.update_attribute(:foodcoop_result, order.profit)

View file

@ -5,7 +5,7 @@ class CreatePages < ActiveRecord::Migration[4.2]
t.string :title
t.text :body
t.string :permalink
t.integer :lock_version, :default => 0
t.integer :lock_version, default: 0
t.integer :updated_by
t.integer :redirect
t.integer :parent_id

View file

@ -1,6 +1,6 @@
class ModifyGroupOrderArticleResult < ActiveRecord::Migration[4.2]
def self.up
change_column :group_order_articles, :result, :decimal, :precision => 8, :scale => 3
change_column :group_order_articles, :result, :decimal, precision: 8, scale: 3
end
def self.down

View file

@ -1,35 +1,34 @@
class AddMissingIndexes < ActiveRecord::Migration[4.2]
def self.up
add_index "article_prices", ["article_id"]
add_index 'article_prices', ['article_id']
add_index "articles", ["supplier_id"]
add_index "articles", ["article_category_id"]
add_index "articles", ["type"]
add_index 'articles', ['supplier_id']
add_index 'articles', ['article_category_id']
add_index 'articles', ['type']
add_index "deliveries", ["supplier_id"]
add_index 'deliveries', ['supplier_id']
add_index "financial_transactions", ["ordergroup_id"]
add_index 'financial_transactions', ['ordergroup_id']
add_index "group_order_article_quantities", ["group_order_article_id"]
add_index "group_orders", ["order_id"]
add_index "group_orders", ["ordergroup_id"]
add_index 'group_order_article_quantities', ['group_order_article_id']
add_index 'group_orders', ['order_id']
add_index 'group_orders', ['ordergroup_id']
add_index "invoices", ["supplier_id"]
add_index "invoices", ["delivery_id"]
add_index 'invoices', ['supplier_id']
add_index 'invoices', ['delivery_id']
add_index "order_articles", ["order_id"]
add_index 'order_articles', ['order_id']
add_index "order_comments", ["order_id"]
add_index 'order_comments', ['order_id']
add_index "orders", ["state"]
add_index 'orders', ['state']
add_index "stock_changes", ["delivery_id"]
add_index "stock_changes", ["stock_article_id"]
add_index "stock_changes", ["stock_taking_id"]
add_index 'stock_changes', ['delivery_id']
add_index 'stock_changes', ['stock_article_id']
add_index 'stock_changes', ['stock_taking_id']
add_index "tasks", ["workgroup_id"]
add_index 'tasks', ['workgroup_id']
end
def self.down
end
def self.down; end
end

View file

@ -1,6 +1,6 @@
class AddDurationToTasks < ActiveRecord::Migration[4.2]
def self.up
add_column :tasks, :duration, :integer, :default => 1
add_column :tasks, :duration, :integer, default: 1
end
def self.down

View file

@ -1,6 +1,6 @@
class AddTaskDurationToWorkgroups < ActiveRecord::Migration[4.2]
def self.up
add_column :groups, :task_duration, :integer, :default => 1
add_column :groups, :task_duration, :integer, default: 1
end
def self.down

View file

@ -1,6 +1,6 @@
class AddNextWeeklyTasksNumberToWorkgroups < ActiveRecord::Migration[4.2]
def self.up
add_column :groups, :next_weekly_tasks_number, :integer, :default => 8
add_column :groups, :next_weekly_tasks_number, :integer, default: 8
end
def self.down

View file

@ -15,21 +15,21 @@ class MoveWeeklyTasks < ActiveRecord::Migration[4.2]
def down
PeriodicTaskGroup.all.each do |task_group|
unless task_group.tasks.empty?
task = task_group.tasks.first
workgroup = task.workgroup
puts "Writing task data of group #{task_group.id} to workgroup #{workgroup.name}"
workgroup_attributes = {
weekly_task: true,
weekday: task.due_date.days_to_week_start(:sunday),
task_name: task.name,
task_description: task.description,
task_required_users: task.required_users,
task_duration: task.duration
}
workgroup.update(workgroup_attributes)
task_group.tasks.update_all weekly: true
end
next if task_group.tasks.empty?
task = task_group.tasks.first
workgroup = task.workgroup
puts "Writing task data of group #{task_group.id} to workgroup #{workgroup.name}"
workgroup_attributes = {
weekly_task: true,
weekday: task.due_date.days_to_week_start(:sunday),
task_name: task.name,
task_description: task.description,
task_required_users: task.required_users,
task_duration: task.duration
}
workgroup.update(workgroup_attributes)
task_group.tasks.update_all weekly: true
end
end

View file

@ -1,18 +1,17 @@
class UpdateGroupOrderTotals < ActiveRecord::Migration[4.2]
def self.up
say "If you have ever modified an order after it was settled, the group_order's " +
"price may be calculated incorrectly. This can take a lot of time on a " +
"large database."
'price may be calculated incorrectly. This can take a lot of time on a ' +
'large database.'
say "If you do want to update the ordergroup totals, open the rails console " +
"(by running `rails c`), and enter:"
say 'If you do want to update the ordergroup totals, open the rails console ' +
'(by running `rails c`), and enter:'
say "GroupOrder.all.each { |go| go.order.closed? and go.update_price! }", subitem: true
say 'GroupOrder.all.each { |go| go.order.closed? and go.update_price! }', subitem: true
say "You may want to check first that no undesired accounting issues are introduced. " +
"It may be wise to discuss this with those responsible for the ordering finances."
say 'You may want to check first that no undesired accounting issues are introduced. ' +
'It may be wise to discuss this with those responsible for the ordering finances.'
end
def self.down
end
def self.down; end
end

View file

@ -8,7 +8,7 @@ class CreateSettings < ActiveRecord::Migration[4.2]
t.timestamps
end
add_index :settings, [:thing_type, :thing_id, :var], unique: true
add_index :settings, %i[thing_type thing_id var], unique: true
end
def self.down

View file

@ -46,8 +46,7 @@ class MigrateUserSettings < ActiveRecord::Migration[4.2]
drop_table :configurable_settings
end
def down
end
def down; end
end
# this is the base class of all configurable settings

View file

@ -1,9 +1,9 @@
class AllowMissingNick < ActiveRecord::Migration[4.2]
def self.up
change_column :users, :nick, :string, :default => nil, :null => true
change_column :users, :nick, :string, default: nil, null: true
end
def self.down
change_column :users, :nick, :string, :default => "", :null => false
change_column :users, :nick, :string, default: '', null: false
end
end

View file

@ -1,6 +1,6 @@
class AddResultComputedToGroupOrderArticles < ActiveRecord::Migration[4.2]
def change
add_column :group_order_articles, :result_computed,
:decimal, :precision => 8, :scale => 3
:decimal, precision: 8, scale: 3
end
end

View file

@ -4,6 +4,5 @@ class DeleteEmptyGroupOrderArticles < ActiveRecord::Migration[4.2]
GroupOrderArticle.where(quantity: 0, tolerance: 0, result: [0, nil], result_computed: [0, nil]).delete_all
end
def down
end
def down; end
end

View file

@ -1,5 +1,5 @@
class RemoveStaleMemberships < ActiveRecord::Migration[4.2]
def up
Membership.where("group_id NOT IN (?)", Group.ids).delete_all
Membership.where.not(group_id: Group.ids).delete_all
end
end

View file

@ -1,5 +1,5 @@
class AddRoleInvoicesToGroup < ActiveRecord::Migration[4.2]
def change
add_column :groups, :role_invoices, :boolean, :default => false, :null => false
add_column :groups, :role_invoices, :boolean, default: false, null: false
end
end

View file

@ -1,6 +1,6 @@
class AddAttachmentToInvoice < ActiveRecord::Migration[4.2]
def change
add_column :invoices, :attachment_mime, :string
add_column :invoices, :attachment_data, :binary, :limit => 8.megabyte
add_column :invoices, :attachment_data, :binary, limit: 8.megabyte
end
end

View file

@ -1,12 +1,12 @@
class CreateFinancialTransactionClassAndTypes < ActiveRecord::Migration[4.2]
def change
create_table :financial_transaction_classes do |t|
t.string :name, :null => false
t.string :name, null: false
end
create_table :financial_transaction_types do |t|
t.string :name, :null => false
t.references :financial_transaction_class, :null => false
t.string :name, null: false
t.references :financial_transaction_class, null: false
end
change_table :financial_transactions do |t|
@ -17,7 +17,7 @@ class CreateFinancialTransactionClassAndTypes < ActiveRecord::Migration[4.2]
dir.up do
execute "INSERT INTO financial_transaction_classes (id, name) VALUES (1, 'Standard')"
execute "INSERT INTO financial_transaction_types (id, name, financial_transaction_class_id) VALUES (1, 'Foodsoft', 1)"
execute "UPDATE financial_transactions SET financial_transaction_type_id = 1"
execute 'UPDATE financial_transactions SET financial_transaction_type_id = 1'
end
end

View file

@ -1,9 +1,9 @@
class AllowStockGroupOrder < ActiveRecord::Migration[4.2]
def self.up
change_column :group_orders, :ordergroup_id, :integer, :default => nil, :null => true
change_column :group_orders, :ordergroup_id, :integer, default: nil, null: true
end
def self.down
change_column :group_orders, :ordergroup_id, :integer, :default => 0, :null => false
change_column :group_orders, :ordergroup_id, :integer, default: 0, null: false
end
end

View file

@ -2,6 +2,6 @@
class AddEmailToMessage < ActiveRecord::Migration[4.2]
def change
add_column :messages, :salt, :string
add_column :messages, :received_email, :binary, :limit => 1.megabyte
add_column :messages, :received_email, :binary, limit: 1.megabyte
end
end

View file

@ -2,8 +2,8 @@ class CreateMailDeliveryStatus < ActiveRecord::Migration[4.2]
def change
create_table :mail_delivery_status do |t|
t.datetime :created_at
t.string :email, :null => false
t.string :message, :null => false
t.string :email, null: false
t.string :message, null: false
t.string :attachment_mime
t.binary :attachment_data, limit: 16.megabyte

View file

@ -24,14 +24,14 @@ class CreatePolls < ActiveRecord::Migration[4.2]
t.references :ordergroup
t.text :note
t.timestamps
t.index [:poll_id, :user_id, :ordergroup_id], unique: true
t.index %i[poll_id user_id ordergroup_id], unique: true
end
create_table :poll_choices do |t|
t.references :poll_vote, null: false
t.integer :choice, null: false
t.integer :value, null: false
t.index [:poll_vote_id, :choice], unique: true
t.index %i[poll_vote_id choice], unique: true
end
end
end

View file

@ -1,5 +1,5 @@
class IncreaseChoicesSize < ActiveRecord::Migration[4.2]
def up
change_column :polls, :choices, :text, limit: 65535
change_column :polls, :choices, :text, limit: 65_535
end
end

View file

@ -15,6 +15,6 @@ class CreatePrinterJobs < ActiveRecord::Migration[4.2]
t.text :message
end
add_index :printer_job_updates, [:printer_job_id, :created_at]
add_index :printer_job_updates, %i[printer_job_id created_at]
end
end

View file

@ -14,7 +14,7 @@ class CreateMessageRecipients < ActiveRecord::Migration[4.2]
t.datetime :read_at
end
add_index :message_recipients, [:user_id, :read_at]
add_index :message_recipients, %i[user_id read_at]
Message.all.each do |m|
recipients = YAML.load(m.recipients_ids).map do |r|

View file

@ -20,7 +20,8 @@ class CreateActiveStorageTables < ActiveRecord::Migration[4.2][5.2]
t.datetime :created_at, null: false
t.index [:record_type, :record_id, :name, :blob_id], name: "index_active_storage_attachments_uniqueness", unique: true
t.index %i[record_type record_id name blob_id], name: 'index_active_storage_attachments_uniqueness',
unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end

View file

@ -1,7 +1,7 @@
class IntroduceReceivedStateInOrders < ActiveRecord::Migration[5.2]
def up
Order.where(state: 'finished').each do |order|
order.update_attribute(:state, 'received') if order.order_articles.where('units_received IS NOT NULL').any?
order.update_attribute(:state, 'received') if order.order_articles.where.not(units_received: nil).any?
end
end

View file

@ -3,15 +3,15 @@ class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
def up
return unless table_exists?(:active_storage_blobs)
unless column_exists?(:active_storage_blobs, :service_name)
add_column :active_storage_blobs, :service_name, :string
return if column_exists?(:active_storage_blobs, :service_name)
if configured_service = ActiveStorage::Blob.service.name
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
end
add_column :active_storage_blobs, :service_name, :string
change_column :active_storage_blobs, :service_name, :string, null: false
if configured_service = ActiveStorage::Blob.service.name
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
end
change_column :active_storage_blobs, :service_name, :string, null: false
end
def down

View file

@ -8,7 +8,7 @@ class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type
t.string :variation_digest, null: false
t.index [:blob_id, :variation_digest], name: "index_active_storage_variant_records_uniqueness", unique: true
t.index %i[blob_id variation_digest], name: 'index_active_storage_variant_records_uniqueness', unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end