Skip to content

Instantly share code, notes, and snippets.

@jadehopepunk
Last active August 29, 2015 14:05
Show Gist options
  • Save jadehopepunk/7f20595d55becd39fd4d to your computer and use it in GitHub Desktop.
Save jadehopepunk/7f20595d55becd39fd4d to your computer and use it in GitHub Desktop.
cobudget schema
class CreateInitialDb < ActiveRecord::Migration
def change
create_table :people do |t|
end
create_table :buckets do |t|
end
create_table :budgets do |t|
end
create_table :reserve_buckets do |t|
t.integer :bucket_id
t.integer :budget_id
t.integer :allocator_id
end
create_table :allocators do |t|
t.integer :person_id
t.integer :budget_id
end
create_table :budgets do |t|
end
create_table :rounds do |t|
end
create_table :projects do |t|
t.integer :budget_id
t.integer :sponsor_id
t.string :name
t.text :description
t.integer :min_cents
t.integer :target_cents
t.integer :max_cents
end
create_table :round_projects do |t|
t.integer :project_id
t.integer :round_id
t.integer :bucket_id
end
create_table :allocation_rights do |t|
t.integer :allocator_id
t.integer :round_id
t.integer :amount_cents
end
create_table :allocations do |t|
t.integer :allocator_id
t.integer :bucket_id
t.integer :amount_cents
end
add_foreign_key :reserve_buckets, :buckets
add_foreign_key :reserve_buckets, :budgets
add_foreign_key :reserve_buckets, :allocators
add_foreign_key :budgets, :reserve_buckets
add_foreign_key :buckets, :projects
add_foreign_key :buckets, :rounds
add_foreign_key :projects, :budgets
add_foreign_key :projects, :people, column: :sponsor_id
add_foreign_key :allocators, :people
add_foreign_key :allocators, :budgets
add_foreign_key :allocation_rights, :allocators
add_foreign_key :allocation_rights, :rounds
add_foreign_key :allocations, :allocators
add_foreign_key :allocations, :buckets
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment