Run rubocop --fix-layout and remove encoding comments

This commit is contained in:
Patrick Gansterer 2021-03-01 15:27:26 +01:00
parent fa63e6e81d
commit ea2862fdef
283 changed files with 1164 additions and 1969 deletions

View file

@ -16,13 +16,13 @@ class CreateUsers < ActiveRecord::Migration[4.2]
end
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")
# 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")

View file

@ -1,49 +1,50 @@
class CreateGroups < ActiveRecord::Migration[4.2]
GROUP_ADMIN = 'Administrators'
GROUP_ORDER = 'Sample Order Group'
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 :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_updated, :timestamp # OrderGroup column
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_updated, :timestamp # OrderGroup column
t.column :created_on, :timestamp, :null => false
t.column :role_admin, :boolean, :default => false, :null => false
end
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
end
add_index(:memberships, [: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)
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)
# 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
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
end
def self.down

View file

@ -1,18 +1,18 @@
class CreateSuppliers < ActiveRecord::Migration[4.2]
SUPPLIER_SAMPLE = 'Sample Supplier'
def self.up
SUPPLIER_SAMPLE = 'Sample Supplier'
def self.up
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?
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)
raise "Failed!" unless supplier = Supplier.find_by_name(SUPPLIER_SAMPLE)
end
def self.down

View file

@ -2,28 +2,27 @@ class CreateArticleMeta < ActiveRecord::Migration[4.2]
CATEGORY_SAMPLE = 'Sample Category'
TAX_STANDARD = 'Standard'
TAX_REDUCED = 'Reduced'
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 '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 :description, :string
end
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)
raise "Failed!" unless category = ArticleCategory.find_by_name(CATEGORY_SAMPLE)
end
def self.down

View file

@ -21,16 +21,16 @@ class CreateFinancialTransactions < ActiveRecord::Migration[4.2]
# Add transactions to the sample order group
puts "Add 30 transactions to the group '#{CreateGroups::GROUP_ORDER}'..."
raise "Group '#{CreateGroups::GROUP_ORDER}' not found!" unless ordergroup = Group.find_by_name(CreateGroups::GROUP_ORDER)
balance = 0
for i in 1..30
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!" 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
remove_column :groups, :role_finance
drop_table :financial_transactions

View file

@ -1,5 +1,5 @@
class CreateArticles < ActiveRecord::Migration[4.2]
SAMPLE_ARTICLE_NAMES = ['banana', 'kiwi', 'strawberry']
SAMPLE_ARTICLE_NAMES = ['banana', 'kiwi', 'strawberry']
def self.up
create_table :articles do |t|
@ -11,23 +11,23 @@ class CreateArticles < ActiveRecord::Migration[4.2]
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}'..."
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
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

View file

@ -3,30 +3,30 @@ class CreateArticlePrices < ActiveRecord::Migration[4.2]
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 :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 :order_number, :string
end
add_index(:article_prices, :article_id)
#add some prices ...
puts 'add prices to the sample articles'
CreateArticles::SAMPLE_ARTICLE_NAMES.each do |a|
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))
article.add_price(new_price)
raise 'Failed!' unless ArticlePrice.find_by_article_id(article.id)
end
raise 'Failed!' unless ArticlePrice.find(:all).length == CreateArticles::SAMPLE_ARTICLE_NAMES.length
add_index(:article_prices, :article_id)
# add some prices ...
puts 'add prices to the sample articles'
CreateArticles::SAMPLE_ARTICLE_NAMES.each do |a|
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))
article.add_price(new_price)
raise 'Failed!' unless ArticlePrice.find_by_article_id(article.id)
end
raise 'Failed!' unless ArticlePrice.find(:all).length == CreateArticles::SAMPLE_ARTICLE_NAMES.length
end
def self.down

View file

@ -1,7 +1,7 @@
class CreateOrders < ActiveRecord::Migration[4.2]
ORDER_TEST = 'Test Order'
GROUP_ORDER = 'Orders'
def self.up
# Order role
add_column :groups, :role_orders, :boolean, :default => false, :null => false
@ -10,12 +10,12 @@ class CreateOrders < ActiveRecord::Migration[4.2]
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)
# Order
create_table :orders do |t|
t.column :name, :string, :null => false
@ -31,9 +31,10 @@ class CreateOrders < ActiveRecord::Migration[4.2]
add_index(:orders, :starts)
add_index(:orders, :ends)
add_index(:orders, :finished)
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)
raise 'Creating test order failed!' unless order = Order.find_by_name(ORDER_TEST)
@ -47,17 +48,18 @@ class CreateOrders < ActiveRecord::Migration[4.2]
t.column :lock_version, :integer, :null => false, :default => 0
end
add_index(:order_articles, [:order_id, :article_id], :unique => true)
puts 'Adding articles to the order...'
CreateArticles::SAMPLE_ARTICLE_NAMES.each { | 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)
raise 'Creating OrderArticle failed!' unless OrderArticle.find_by_order_id_and_article_id(order.id, article.id)
}
raise 'Creating OrderArticles failed!' unless order.articles.size == CreateArticles::SAMPLE_ARTICLE_NAMES.length
CreateArticles::SAMPLE_ARTICLE_NAMES.each { |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)
raise 'Creating OrderArticle failed!' unless OrderArticle.find_by_order_id_and_article_id(order.id, article.id)
}
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
@ -67,14 +69,15 @@ class CreateOrders < ActiveRecord::Migration[4.2]
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, [: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}")
# GroupOrderArticles
create_table :group_order_articles do |t|
t.column :group_order_id, :integer, :null => false
@ -82,7 +85,7 @@ class CreateOrders < ActiveRecord::Migration[4.2]
t.column :quantity, :integer, :null => false
t.column :tolerance, :integer, :null => false
t.column :updated_on, :timestamp, :null => false
end
end
add_index(:group_order_articles, [:group_order_id, :order_article_id], :unique => true, :name => "goa_index")
# GroupOrderArticleQuantity
create_table :group_order_article_quantities do |t|
@ -91,20 +94,22 @@ class CreateOrders < ActiveRecord::Migration[4.2]
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 { |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}")
article.updateQuantities(rand(6) + 1, rand(4) + 1)
}
raise 'Failed to create orders!' unless groupOrder.order_articles.size == order.order_articles.size
raise 'Failed to create orders!' unless groupOrder.order_articles.size == order.order_articles.size
groupOrder.updatePrice
raise 'Failed to update GroupOrder.price' unless groupOrder.save!
raise 'Failed to update GroupOrder.price' unless groupOrder.save!
# Update order
order.updateQuantities
order.updateQuantities
end
def self.down

View file

@ -6,7 +6,7 @@ class CreateOrderResults < ActiveRecord::Migration[4.2]
t.column :price, :decimal, :precision => 8, :scale => 2, :null => false, :default => 0
end
add_index(:group_order_results, [: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
@ -22,7 +22,7 @@ class CreateOrderResults < ActiveRecord::Migration[4.2]
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

View file

@ -1,8 +1,7 @@
class UserPasswordReset < ActiveRecord::Migration[4.2]
def self.up
add_column :users, :reset_password_token, :string
add_column :users, :reset_password_expires, :timestamp
add_column :users, :reset_password_expires, :timestamp
end
def self.down

View file

@ -6,13 +6,13 @@ class CreateComments < ActiveRecord::Migration[4.2]
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
:default => "", :null => false
t.column :user_id, :integer, :default => 0, :null => false
end
add_index :comments, ["user_id"], :name => "fk_comments_user"
end
def self.down
drop_table :comments
end

View file

@ -1,5 +1,4 @@
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

View file

@ -13,7 +13,7 @@ class AddMessaging < ActiveRecord::Migration[4.2]
end
add_index(:messages, :sender_id)
add_index(:messages, :recipient_id)
# Setup acts_as_configurable plugin for user options etc.
ConfigurableSetting.create_table
end

View file

@ -12,14 +12,14 @@ class CreateTasks < ActiveRecord::Migration[4.2]
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
end
add_index :assignments, [: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, :weekday, :integer # e.g. 1 means monday, 2 = tuesday an so on
add_column :groups, :task_name, :string # the name of the weekly task

View file

@ -6,6 +6,6 @@ class ChangeResultQuantities < ActiveRecord::Migration[4.2]
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 :order_article_results, :units_to_order, :integer, :default => 0, :null => false
end
end

View file

@ -1,7 +1,7 @@
class AddSharedListsConnection < ActiveRecord::Migration[4.2]
def self.up
add_column :suppliers, :shared_supplier_id, :integer
add_column :articles, :manufacturer , :string
add_column :articles, :manufacturer, :string
add_column :articles, :origin, :string
add_column :articles, :shared_updated_on, :timestamp
end

View file

@ -1,6 +1,5 @@
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
@ -10,24 +9,23 @@ class RemoveTableArticlePrices < ActiveRecord::Migration[4.2]
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..."
Article.find(:all).each do |article|
price = article.current_price
article.update_attributes!(:clear_price => price.clear_price,
:gross_price => price.gross_price,
:tax => price.tax,
:refund => price.refund,
:unit_quantity => price.unit_quantity,
:order_number => price.order_number,
:updated_at => price.updated_on,
:created_at => price.updated_on)
:gross_price => price.gross_price,
:tax => price.tax,
:refund => price.refund,
:unit_quantity => price.unit_quantity,
:order_number => price.order_number,
:updated_at => price.updated_on,
:created_at => price.updated_on)
end
puts "delete article_prices, current_price attribute"
drop_table :article_prices
remove_column :articles, :current_price_id
@ -40,29 +38,28 @@ class RemoveTableArticlePrices < ActiveRecord::Migration[4.2]
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.decimal "refund", :precision => 8, :scale => 2, :default => 0.0, :null => false
t.datetime "updated_on"
t.integer "unit_quantity", :default => 1, :null => false
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)
: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)
article.update_attribute(:current_price, price)
price.update_attribute(:article, article)
end
# remove new columns
remove_column "articles", "clear_price"
remove_column "articles", "clear_price"
remove_column "articles", "gross_price"
remove_column "articles", "tax"
remove_column "articles", "refund"
@ -70,6 +67,5 @@ class RemoveTableArticlePrices < ActiveRecord::Migration[4.2]
remove_column "articles", "order_number"
remove_column "articles", "created_at"
remove_column "articles", "updated_at"
end
end

View file

@ -2,10 +2,10 @@ class NewWording < ActiveRecord::Migration[4.2]
def self.up
rename_column :articles, :clear_price, :net_price
rename_column :articles, :refund, :deposit
rename_column :order_article_results, :clear_price, :net_price
rename_column :order_article_results, :refund, :deposit
rename_column :orders, :refund, :deposit
rename_column :orders, :refund_credit, :deposit_credit
end
@ -13,10 +13,10 @@ class NewWording < ActiveRecord::Migration[4.2]
def self.down
rename_column :articles, :net_price, :clear_price
rename_column :articles, :deposit, :refund
rename_column :order_article_results, :net_price, :clear_price
rename_column :order_article_results, :deposit, :refund
rename_column :orders, :deposit, :refund
rename_column :orders, :deposit_credit, :refund_credit
end

View file

@ -1,4 +1,3 @@
class OrderGroup < Group; end # Needed for renaming of OrderGroup to Ordergroup
class RoadToVersionThree < ActiveRecord::Migration[4.2]
@ -30,7 +29,7 @@ class RoadToVersionThree < ActiveRecord::Migration[4.2]
end
# == Ordergroups
remove_column :groups, :actual_size # Useless, desposits are better stored within a transaction.note
remove_column :groups, :actual_size # Useless, desposits are better stored within a transaction.note
# rename from OrderGroup to Ordergroup
rename_column :financial_transactions, :order_group_id, :ordergroup_id
rename_column :group_orders, :order_group_id, :ordergroup_id
@ -49,7 +48,7 @@ class RoadToVersionThree < ActiveRecord::Migration[4.2]
contact = ordergroup.users.first
if contact
ordergroup.update_attributes :contact_person => contact.name,
:contact_phone => contact.phone, :contact_address => contact.address
:contact_phone => contact.phone, :contact_address => contact.address
end
end
remove_column :users, :address
@ -66,7 +65,7 @@ class RoadToVersionThree < ActiveRecord::Migration[4.2]
t.text :note
t.datetime :starts
t.datetime :ends
t.string :state, :default => "open" # Statemachine ... open -> finished -> closed
t.string :state, :default => "open" # Statemachine ... open -> finished -> closed
t.integer :lock_version, :default => 0, :null => false
t.integer :updated_by_user_id
end
@ -81,13 +80,13 @@ class RoadToVersionThree < ActiveRecord::Migration[4.2]
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 :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
# == Delivery
create_table :deliveries do |t|
create_table :deliveries do |t|
t.integer :supplier_id
t.date :delivered_on
t.datetime :created_at
@ -118,11 +117,11 @@ class RoadToVersionThree < ActiveRecord::Migration[4.2]
# 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
: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.update_attribute(:article_category, ArticleCategory.first)
article.update_attribute(:article_category, ArticleCategory.first)
end
# order-articles
add_column :order_articles, :article_price_id, :integer

View file

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

View file

@ -1,11 +1,11 @@
class AddMissingIndexes < ActiveRecord::Migration[4.2]
def self.up
add_index "article_prices", ["article_id"]
add_index "articles", ["supplier_id"]
add_index "articles", ["article_category_id"]
add_index "articles", ["type"]
add_index "deliveries", ["supplier_id"]
add_index "financial_transactions", ["ordergroup_id"]
@ -18,16 +18,16 @@ class AddMissingIndexes < ActiveRecord::Migration[4.2]
add_index "invoices", ["delivery_id"]
add_index "order_articles", ["order_id"]
add_index "order_comments", ["order_id"]
add_index "orders", ["state"]
add_index "stock_changes", ["delivery_id"]
add_index "stock_changes", ["stock_article_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

View file

@ -33,7 +33,8 @@ class MoveWeeklyTasks < ActiveRecord::Migration[4.2]
end
end
private
private
def weekly_task?(workgroup, task)
return false if task.due_date.nil?

View file

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

View file

@ -1,7 +1,6 @@
class MigrateUserSettings < ActiveRecord::Migration[4.2]
def up
say_with_time 'Save old user settings in new RailsSettings module' do
# Allow setting default locale via env parameter
# This is used, when setting users language settings
default_locale = I18n.default_locale
@ -15,7 +14,7 @@ class MigrateUserSettings < ActiveRecord::Migration[4.2]
type = old_setting.configurable_type
id = old_setting.configurable_id
begin
user = type.constantize.find(id)
user = type.constantize.find(id)
rescue ActiveRecord::RecordNotFound
Rails.logger.debug "Can't find configurable object with type: #{type.inspect}, id: #{id.inspect}"
next
@ -32,9 +31,9 @@ class MigrateUserSettings < ActiveRecord::Migration[4.2]
# set the settings_attributes (thanks to settings.merge! we can set them one by one)
user.settings_attributes = {
"#{namespace}" => {
"#{key}" => value
}
"#{namespace}" => {
"#{key}" => value
}
}
# save the user to apply after_save callback
@ -52,4 +51,4 @@ class MigrateUserSettings < ActiveRecord::Migration[4.2]
end
# this is the base class of all configurable settings
class ConfigurableSetting < ActiveRecord::Base; end
class ConfigurableSetting < ActiveRecord::Base; 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

@ -27,11 +27,11 @@ class CreateDoorkeeperTables < ActiveRecord::Migration[4.2]
create_table :oauth_access_tokens do |t|
t.integer :resource_owner_id
t.integer :application_id
t.string :token, null: false
t.string :token, null: false
t.string :refresh_token
t.integer :expires_in
t.datetime :revoked_at
t.datetime :created_at, null: false
t.datetime :created_at, null: false
t.string :scopes
end

View file

@ -1,6 +1,8 @@
class CreateSupplierCategories < ActiveRecord::Migration[4.2]
class FinancialTransactionClass < ActiveRecord::Base; end
class SupplierCategory < ActiveRecord::Base; end
class Supplier < ActiveRecord::Base; end
def change

View file

@ -1,5 +1,6 @@
class ClearInvalidInvoicesFromOrders < ActiveRecord::Migration[4.2]
class Order < ActiveRecord::Base; end
class Invoice < ActiveRecord::Base; end
def up

View file

@ -1,5 +1,6 @@
class CreateStockEvents < ActiveRecord::Migration[4.2]
class StockEvent < ActiveRecord::Base; end
class StockTaking < ActiveRecord::Base; end
def change