From 2c688c016bc5801ff92a22ff37d2c8c0c9924267 Mon Sep 17 00:00:00 2001 From: Bryan Larsen Date: Mon, 3 Jun 2013 16:38:22 +0200 Subject: [PATCH] migration-to-create-initial-models Now watch how Hobo can create a single migration for all of these: $ hobo generate migration When the migration generator asks you What now: [g]enerate migration, generate and [m]igrate now or [c]ancel? Choose `m` to both generate the migration and apply it to your database. We entered `initial_models` as the name for our migration. Now you can start your application $ rails server You can access it via your web browser at `http://localhost:3000`. It's not a polished UI of course, but we do actually have a working application. Make sure you are logged in as an administrator (e.g. the user who signed up first), and spend a few minutes populating the app with projects, stories and tasks. With some more very simple changes, and without even touching the views, we can get surprisingly close to a decent UI. --- db/migrate/20130109013414_initial_models.rb | 45 +++++++++++++++++++++ db/schema.rb | 40 +++++++++++++++++- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20130109013414_initial_models.rb diff --git a/db/migrate/20130109013414_initial_models.rb b/db/migrate/20130109013414_initial_models.rb new file mode 100644 index 0000000..994af01 --- /dev/null +++ b/db/migrate/20130109013414_initial_models.rb @@ -0,0 +1,45 @@ +class InitialModels < ActiveRecord::Migration + def self.up + create_table :projects do |t| + t.string :name + t.integer :stories_count, :default => 0, :null => false + t.datetime :created_at + t.datetime :updated_at + end + + create_table :stories do |t| + t.string :title + t.text :body + t.string :status + t.integer :tasks_count, :default => 0, :null => false + t.datetime :created_at + t.datetime :updated_at + t.integer :project_id + end + add_index :stories, [:project_id] + + create_table :tasks do |t| + t.string :description + t.datetime :created_at + t.datetime :updated_at + t.integer :story_id + end + add_index :tasks, [:story_id] + + create_table :task_assignments do |t| + t.datetime :created_at + t.datetime :updated_at + t.integer :user_id + t.integer :task_id + end + add_index :task_assignments, [:user_id] + add_index :task_assignments, [:task_id] + end + + def self.down + drop_table :projects + drop_table :stories + drop_table :tasks + drop_table :task_assignments + end +end diff --git a/db/schema.rb b/db/schema.rb index f39af9a..e9eaa8d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,45 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130108212536) do +ActiveRecord::Schema.define(:version => 20130109013414) do + + create_table "projects", :force => true do |t| + t.string "name" + t.integer "stories_count", :default => 0, :null => false + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "stories", :force => true do |t| + t.string "title" + t.text "body" + t.string "status" + t.integer "tasks_count", :default => 0, :null => false + t.datetime "created_at" + t.datetime "updated_at" + t.integer "project_id" + end + + add_index "stories", ["project_id"], :name => "index_stories_on_project_id" + + create_table "task_assignments", :force => true do |t| + t.datetime "created_at" + t.datetime "updated_at" + t.integer "user_id" + t.integer "task_id" + end + + add_index "task_assignments", ["task_id"], :name => "index_task_assignments_on_task_id" + add_index "task_assignments", ["user_id"], :name => "index_task_assignments_on_user_id" + + create_table "tasks", :force => true do |t| + t.string "description" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "story_id" + end + + add_index "tasks", ["story_id"], :name => "index_tasks_on_story_id" create_table "users", :force => true do |t| t.string "crypted_password", :limit => 40