From 4d553d793b8b76c40c6b79eec926c799e58a86a3 Mon Sep 17 00:00:00 2001 From: JuliusR <> Date: Sat, 18 Dec 2021 11:39:41 +0100 Subject: [PATCH] replace db by previous version --- db/migrate/001_create_suppliers.rb | 31 +++++++ db/migrate/002_create_articles.rb | 33 +++++++ db/migrate/003_add_list_to_article.rb | 11 +++ db/migrate/004_new_wording.rb | 10 +++ ...0110306172553_add_bnn_sync_to_suppliers.rb | 15 ++++ db/migrate/20120312184452_create_users.rb | 15 ++++ .../20120312190323_create_user_accesses.rb | 18 ++++ ...501_remove_article_lists_from_suppliers.rb | 11 +++ .../20121017084147_add_admin_flag_to_users.rb | 9 ++ .../20130627093146_add_category_to_article.rb | 9 ++ ...0170901183454_add_mail_sync_to_supplier.rb | 8 ++ .../20170901200146_add_salt_to_suppliers.rb | 19 +++++ ...11115732_generalize_ftp_sync_beyond_bnn.rb | 11 +++ db/schema.rb | 85 +++++++++++++++++++ db/seeds.rb | 6 +- 15 files changed, 288 insertions(+), 3 deletions(-) create mode 100644 db/migrate/001_create_suppliers.rb create mode 100644 db/migrate/002_create_articles.rb create mode 100644 db/migrate/003_add_list_to_article.rb create mode 100644 db/migrate/004_new_wording.rb create mode 100644 db/migrate/20110306172553_add_bnn_sync_to_suppliers.rb create mode 100644 db/migrate/20120312184452_create_users.rb create mode 100644 db/migrate/20120312190323_create_user_accesses.rb create mode 100644 db/migrate/20121013164501_remove_article_lists_from_suppliers.rb create mode 100644 db/migrate/20121017084147_add_admin_flag_to_users.rb create mode 100644 db/migrate/20130627093146_add_category_to_article.rb create mode 100644 db/migrate/20170901183454_add_mail_sync_to_supplier.rb create mode 100644 db/migrate/20170901200146_add_salt_to_suppliers.rb create mode 100644 db/migrate/20190811115732_generalize_ftp_sync_beyond_bnn.rb create mode 100644 db/schema.rb diff --git a/db/migrate/001_create_suppliers.rb b/db/migrate/001_create_suppliers.rb new file mode 100644 index 0000000..8d30405 --- /dev/null +++ b/db/migrate/001_create_suppliers.rb @@ -0,0 +1,31 @@ +class CreateSuppliers < ActiveRecord::Migration + SUPPLIER_SAMPLE = 'Sample Supplier' + + def self.up + 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 :phone2, :string + t.column :fax, :string + t.column :email, :string + t.column :url, :string + t.column :delivery_days, :string + t.column :note, :string + + t.column :created_on, :datetime + t.column :updated_on, :datetime + end + 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) + + end + + def self.down + drop_table :suppliers + end +end diff --git a/db/migrate/002_create_articles.rb b/db/migrate/002_create_articles.rb new file mode 100644 index 0000000..e7e534a --- /dev/null +++ b/db/migrate/002_create_articles.rb @@ -0,0 +1,33 @@ +class CreateArticles < ActiveRecord::Migration + def self.up + create_table :articles do |t| + t.column :name, :string, :null => false + t.column :supplier_id, :integer, :null => false + t.column :number, :string + t.column :note, :string + t.column :manufacturer , :string + t.column :origin, :string + t.column :unit, :string + + # now the price and order conditions + t.column :price, :decimal, :precision => 8, :scale => 2, :null => false, :default => 0.00 + t.column :tax, :decimal, :precision => 3, :scale => 1,:null => false, :default => 7.0 + t.column :refund, :decimal, :precision => 8, :scale => 2, :null => false, :default => 0.00 + t.column :unit_quantity, :decimal, :precision => 4, :scale => 1,:null => false, :default => 1 + + # the price-quantity-scale + t.column :scale_quantity, :decimal, :precision => 4, :scale => 2 + t.column :scale_price, :decimal, :precision => 8, :scale => 2 + + t.column :created_on, :datetime + t.column :updated_on, :datetime + + end + add_index(:articles, :name) + add_index(:articles, [:number, :supplier_id], :unique => true) + end + + def self.down + drop_table :articles + end +end diff --git a/db/migrate/003_add_list_to_article.rb b/db/migrate/003_add_list_to_article.rb new file mode 100644 index 0000000..3155433 --- /dev/null +++ b/db/migrate/003_add_list_to_article.rb @@ -0,0 +1,11 @@ +class AddListToArticle < ActiveRecord::Migration + def self.up + add_column :articles, :list, :string + add_column :suppliers, :lists, :string + end + + def self.down + remove_column :articles, :list + remove_column :suppliers, :lists + end +end diff --git a/db/migrate/004_new_wording.rb b/db/migrate/004_new_wording.rb new file mode 100644 index 0000000..76c42bb --- /dev/null +++ b/db/migrate/004_new_wording.rb @@ -0,0 +1,10 @@ +class NewWording < ActiveRecord::Migration + def self.up + rename_column :articles, :refund, :deposit + # and make 0.0 deposit the default ... + change_column :articles, :deposit, :decimal, :precision => 8, :scale => 2, :default => 0.0, :null => false + end + + def self.down + end +end diff --git a/db/migrate/20110306172553_add_bnn_sync_to_suppliers.rb b/db/migrate/20110306172553_add_bnn_sync_to_suppliers.rb new file mode 100644 index 0000000..29fff57 --- /dev/null +++ b/db/migrate/20110306172553_add_bnn_sync_to_suppliers.rb @@ -0,0 +1,15 @@ +class AddBnnSyncToSuppliers < ActiveRecord::Migration + def self.up + add_column :suppliers, :bnn_sync, :boolean, :default => false + add_column :suppliers, :bnn_host, :string + add_column :suppliers, :bnn_user, :string + add_column :suppliers, :bnn_password, :string + end + + def self.down + remove_column :suppliers, :bnn_password + remove_column :suppliers, :bnn_user + remove_column :suppliers, :bnn_host + remove_column :suppliers, :bnn_sync + end +end diff --git a/db/migrate/20120312184452_create_users.rb b/db/migrate/20120312184452_create_users.rb new file mode 100644 index 0000000..34fae6b --- /dev/null +++ b/db/migrate/20120312184452_create_users.rb @@ -0,0 +1,15 @@ +class CreateUsers < ActiveRecord::Migration + def self.up + create_table :users do |t| + t.string :email + t.string :password_hash + t.string :password_salt + + t.timestamps + end + end + + def self.down + drop_table :users + end +end diff --git a/db/migrate/20120312190323_create_user_accesses.rb b/db/migrate/20120312190323_create_user_accesses.rb new file mode 100644 index 0000000..b0bdf64 --- /dev/null +++ b/db/migrate/20120312190323_create_user_accesses.rb @@ -0,0 +1,18 @@ +class CreateUserAccesses < ActiveRecord::Migration + def self.up + create_table :user_accesses do |t| + t.integer :user_id + t.integer :supplier_id + + t.timestamps + end + + add_index :user_accesses, :user_id + add_index :user_accesses, :supplier_id + add_index :user_accesses, [:user_id, :supplier_id] + end + + def self.down + drop_table :user_accesses + end +end diff --git a/db/migrate/20121013164501_remove_article_lists_from_suppliers.rb b/db/migrate/20121013164501_remove_article_lists_from_suppliers.rb new file mode 100644 index 0000000..33ffe58 --- /dev/null +++ b/db/migrate/20121013164501_remove_article_lists_from_suppliers.rb @@ -0,0 +1,11 @@ +class RemoveArticleListsFromSuppliers < ActiveRecord::Migration + def self.up + remove_column :suppliers, :lists + remove_column :articles, :list + end + + def self.down + add_column :articles, :list, :string + add_column :suppliers, :lists, :string + end +end diff --git a/db/migrate/20121017084147_add_admin_flag_to_users.rb b/db/migrate/20121017084147_add_admin_flag_to_users.rb new file mode 100644 index 0000000..f58e57b --- /dev/null +++ b/db/migrate/20121017084147_add_admin_flag_to_users.rb @@ -0,0 +1,9 @@ +class AddAdminFlagToUsers < ActiveRecord::Migration + def self.up + add_column :users, :admin, :boolean, :default => false + end + + def self.down + remove_column :users, :admin + end +end diff --git a/db/migrate/20130627093146_add_category_to_article.rb b/db/migrate/20130627093146_add_category_to_article.rb new file mode 100644 index 0000000..be9c45d --- /dev/null +++ b/db/migrate/20130627093146_add_category_to_article.rb @@ -0,0 +1,9 @@ +class AddCategoryToArticle < ActiveRecord::Migration + def self.up + add_column :articles, :category, :string + end + + def self.down + remove_column :articles, :category + end +end diff --git a/db/migrate/20170901183454_add_mail_sync_to_supplier.rb b/db/migrate/20170901183454_add_mail_sync_to_supplier.rb new file mode 100644 index 0000000..3c3f86d --- /dev/null +++ b/db/migrate/20170901183454_add_mail_sync_to_supplier.rb @@ -0,0 +1,8 @@ +class AddMailSyncToSupplier < ActiveRecord::Migration + def change + add_column :suppliers, :mail_sync, :boolean + add_column :suppliers, :mail_from, :string + add_column :suppliers, :mail_subject, :string + add_column :suppliers, :mail_type, :string + end +end diff --git a/db/migrate/20170901200146_add_salt_to_suppliers.rb b/db/migrate/20170901200146_add_salt_to_suppliers.rb new file mode 100644 index 0000000..42cd5c0 --- /dev/null +++ b/db/migrate/20170901200146_add_salt_to_suppliers.rb @@ -0,0 +1,19 @@ +class AddSaltToSuppliers < ActiveRecord::Migration + + class Supplier < ActiveRecord::Base; end + + def up + add_column :suppliers, :salt, :string + + Supplier.find_each do |supplier| + salt = [Array.new(6){rand(256).chr}.join].pack("m").chomp + supplier.update_attributes! salt: salt + end + + change_column_null :suppliers, :salt, false + end + + def down + remove_column :suppliers, :salt + end +end diff --git a/db/migrate/20190811115732_generalize_ftp_sync_beyond_bnn.rb b/db/migrate/20190811115732_generalize_ftp_sync_beyond_bnn.rb new file mode 100644 index 0000000..de28b1c --- /dev/null +++ b/db/migrate/20190811115732_generalize_ftp_sync_beyond_bnn.rb @@ -0,0 +1,11 @@ +class GeneralizeFtpSyncBeyondBnn < ActiveRecord::Migration + def change + rename_column :suppliers, :bnn_sync, :ftp_sync + rename_column :suppliers, :bnn_host, :ftp_host + rename_column :suppliers, :bnn_user, :ftp_user + rename_column :suppliers, :bnn_password, :ftp_password + + add_column :suppliers, :ftp_type, :string, default: 'bnn', null: false, after: :ftp_password + add_column :suppliers, :ftp_regexp, :string, default: '^([.]/)?PL', after: :ftp_type + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..9583638 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,85 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 20190811115732) do + + create_table "articles", :force => true do |t| + t.string "name", :null => false + t.integer "supplier_id", :null => false + t.string "number" + t.string "note" + t.string "manufacturer" + t.string "origin" + t.string "unit" + t.decimal "price", :precision => 8, :scale => 2, :default => 0.0, :null => false + t.decimal "tax", :precision => 3, :scale => 1, :default => 7.0, :null => false + t.decimal "deposit", :precision => 8, :scale => 2, :default => 0.0, :null => false + t.decimal "unit_quantity", :precision => 4, :scale => 1, :default => 1.0, :null => false + t.decimal "scale_quantity", :precision => 4, :scale => 2 + t.decimal "scale_price", :precision => 8, :scale => 2 + t.datetime "created_on" + t.datetime "updated_on" + t.string "category" + end + + add_index "articles", ["name"], :name => "index_articles_on_name" + add_index "articles", ["number", "supplier_id"], :name => "index_articles_on_number_and_supplier_id", :unique => true + + create_table "suppliers", :force => true do |t| + t.string "name", :null => false + t.string "address", :null => false + t.string "phone", :null => false + t.string "phone2" + t.string "fax" + t.string "email" + t.string "url" + t.string "delivery_days" + t.string "note" + t.datetime "created_on" + t.datetime "updated_on" + t.boolean "ftp_sync", :default => false + t.string "ftp_host" + t.string "ftp_user" + t.string "ftp_password" + t.string "ftp_type", :default => "bnn", :null => false + t.string "ftp_regexp", :default => "^([.]/)?PL" + t.boolean "mail_sync" + t.string "mail_from" + t.string "mail_subject" + t.string "mail_type" + t.string "salt", :null => false + end + + add_index "suppliers", ["name"], :name => "index_suppliers_on_name", :unique => true + + create_table "user_accesses", :force => true do |t| + t.integer "user_id" + t.integer "supplier_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "user_accesses", ["supplier_id"], :name => "index_user_accesses_on_supplier_id" + add_index "user_accesses", ["user_id", "supplier_id"], :name => "index_user_accesses_on_user_id_and_supplier_id" + add_index "user_accesses", ["user_id"], :name => "index_user_accesses_on_user_id" + + create_table "users", :force => true do |t| + t.string "email" + t.string "password_hash" + t.string "password_salt" + t.datetime "created_at" + t.datetime "updated_at" + t.boolean "admin", :default => false + end + +end diff --git a/db/seeds.rb b/db/seeds.rb index f3a0480..664d8c7 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,7 +1,7 @@ # This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # -# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) -# Character.create(name: 'Luke', movie: movies.first) +# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) +# Mayor.create(:name => 'Daley', :city => cities.first)