adds Budget::Group model to group headings

many refactors through budget related models
This commit is contained in:
Juanjo Bazán
2016-06-09 18:00:06 +02:00
parent 3fae269c40
commit b5a6828e41
18 changed files with 156 additions and 110 deletions

View File

@@ -300,18 +300,21 @@ puts "Creating Budgets"
(1..10).each do |i|
budget = Budget.create!(name: (Date.today.year - 10 + i).to_s,
description: "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>",
price: rand(1 .. 100) * 100000,
phase: %w{on_hold accepting selecting balloting finished}.sample,
valuating: [false, true].sample)
puts budget.name
puts " "
geozones = Geozone.reorder("RANDOM()").limit(10)
geozones.each do |geozone|
heading = budget.headings.create!(name: geozone.name,
geozone: geozone,
price: rand(1 .. 100) * 10000)
budget.headings << heading
print "heading.name "
(1..[1,2,3].sample).each do |i|
group = budget.groups.create!(name: Faker::StarWars.planet)
geozones = Geozone.reorder("RANDOM()").limit([2,5,6,7].sample)
geozones.each do |geozone|
group.headings << group.headings.create!(name: geozone.name,
geozone: geozone,
price: rand(1 .. 100) * 10000)
end
print "#{group.name} "
end
puts ""
end

View File

@@ -1,9 +1,9 @@
class CreateBudgetHeading < ActiveRecord::Migration
def change
create_table :budget_headings do |t|
t.references :budget
t.references :group, index: true
t.references :geozone
t.string :name, limit: 50
t.string :name, limit: 50
t.integer :price, limit: 8
end
end

View File

@@ -0,0 +1,10 @@
class CreateBudgetGroup < ActiveRecord::Migration
def change
create_table :budget_groups do |t|
t.references :budget
t.string :name, limit: 50
end
add_index :budget_groups, :budget_id
end
end

View File

@@ -0,0 +1,5 @@
class RemovePriceFromBudget < ActiveRecord::Migration
def change
remove_column :budgets, :price, :integer
end
end

View File

@@ -0,0 +1,5 @@
class RemoveBudgetIdFromInvestments < ActiveRecord::Migration
def change
remove_column :budget_investments, :budget_id, :integer
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160531102008) do
ActiveRecord::Schema.define(version: 20160609152026) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -63,6 +63,21 @@ ActiveRecord::Schema.define(version: 20160531102008) do
add_index "annotations", ["legislation_id"], name: "index_annotations_on_legislation_id", using: :btree
add_index "annotations", ["user_id"], name: "index_annotations_on_user_id", using: :btree
create_table "banners", force: :cascade do |t|
t.string "title", limit: 80
t.string "description"
t.string "target_url"
t.string "style"
t.string "image"
t.date "post_started_at"
t.date "post_ended_at"
t.datetime "hidden_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "banners", ["hidden_at"], name: "index_banners_on_hidden_at", using: :btree
create_table "budget_ballot_lines", force: :cascade do |t|
t.integer "ballot_id"
t.integer "investment_id"
@@ -83,13 +98,22 @@ ActiveRecord::Schema.define(version: 20160531102008) do
add_index "budget_ballots", ["heading_id"], name: "index_budget_ballots_on_heading_id", using: :btree
create_table "budget_headings", force: :cascade do |t|
create_table "budget_groups", force: :cascade do |t|
t.integer "budget_id"
t.string "name", limit: 50
end
add_index "budget_groups", ["budget_id"], name: "index_budget_groups_on_budget_id", using: :btree
create_table "budget_headings", force: :cascade do |t|
t.integer "group_id"
t.integer "geozone_id"
t.string "name", limit: 50
t.integer "price", limit: 8
end
add_index "budget_headings", ["group_id"], name: "index_budget_headings_on_group_id", using: :btree
create_table "budget_investments", force: :cascade do |t|
t.integer "author_id"
t.integer "administrator_id"
@@ -114,13 +138,11 @@ ActiveRecord::Schema.define(version: 20160531102008) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "heading_id"
t.integer "budget_id"
t.string "responsible_name"
end
add_index "budget_investments", ["administrator_id"], name: "index_budget_investments_on_administrator_id", using: :btree
add_index "budget_investments", ["author_id"], name: "index_budget_investments_on_author_id", using: :btree
add_index "budget_investments", ["budget_id"], name: "index_budget_investments_on_budget_id", using: :btree
add_index "budget_investments", ["heading_id"], name: "index_budget_investments_on_heading_id", using: :btree
add_index "budget_investments", ["tsv"], name: "index_budget_investments_on_tsv", using: :gin
@@ -141,24 +163,8 @@ ActiveRecord::Schema.define(version: 20160531102008) do
t.boolean "valuating", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "price"
end
create_table "banners", force: :cascade do |t|
t.string "title", limit: 80
t.string "description"
t.string "target_url"
t.string "style"
t.string "image"
t.date "post_started_at"
t.date "post_ended_at"
t.datetime "hidden_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "banners", ["hidden_at"], name: "index_banners_on_hidden_at", using: :btree
create_table "campaigns", force: :cascade do |t|
t.string "name"
t.string "track_id"
@@ -204,10 +210,10 @@ ActiveRecord::Schema.define(version: 20160531102008) do
t.string "visit_id"
t.datetime "hidden_at"
t.integer "flags_count", default: 0
t.datetime "ignored_flag_at"
t.integer "cached_votes_total", default: 0
t.integer "cached_votes_up", default: 0
t.integer "cached_votes_down", default: 0
t.datetime "ignored_flag_at"
t.integer "comments_count", default: 0
t.datetime "confirmed_hide_at"
t.integer "cached_anonymous_votes_total", default: 0