From 637b46ef1088a9dd49b3b11c8cff16fafc9d3c09 Mon Sep 17 00:00:00 2001 From: Mackenzie Morgan Date: Thu, 1 Dec 2016 12:54:55 -0500 Subject: [PATCH 1/3] add photos to seeds Fixes #495 --- app/constants/photo_models.rb | 3 ++- app/models/seed.rb | 1 + db/schema.rb | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/constants/photo_models.rb b/app/constants/photo_models.rb index bc9fc24fd..8f79933e4 100644 --- a/app/constants/photo_models.rb +++ b/app/constants/photo_models.rb @@ -4,8 +4,9 @@ module Growstuff PLANTING = { type: 'planting', class: 'Planting', relation: 'plantings' }.freeze HARVEST = { type: 'harvest', class: 'Harvest', relation: 'harvests' }.freeze GARDEN = { type: 'garden', class: 'Garden', relation: 'gardens' }.freeze + SEED = { type: 'seed', class: 'Seed', relation: 'seeds' }.freeze - ALL = [PLANTING, HARVEST, GARDEN].freeze + ALL = [PLANTING, HARVEST, GARDEN, SEED].freeze def self.types ALL.map do |model| diff --git a/app/models/seed.rb b/app/models/seed.rb index 4c8a1c1c7..02a36fe3a 100644 --- a/app/models/seed.rb +++ b/app/models/seed.rb @@ -1,5 +1,6 @@ class Seed < ActiveRecord::Base extend FriendlyId + include PhotoCapable friendly_id :seed_slug, use: [:slugged, :finders] belongs_to :crop diff --git a/db/schema.rb b/db/schema.rb index 6596b2428..4901b8499 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161129021533) do +ActiveRecord::Schema.define(version: 20161201154922) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -355,6 +355,14 @@ ActiveRecord::Schema.define(version: 20161129021533) do t.integer "product_id" end + create_table "photo_mappings", force: :cascade do |t| + t.integer "photo_id" + t.integer "object_id" + t.string "object_type" + end + + add_index "photo_mappings", ["object_id", "photo_id"], name: "index_photo_mappings_on_object_id_and_photo_id", using: :btree + create_table "photos", force: :cascade do |t| t.integer "owner_id", null: false t.string "thumbnail_url", null: false @@ -373,6 +381,11 @@ ActiveRecord::Schema.define(version: 20161129021533) do t.integer "planting_id" end + create_table "photos_seeds", id: false, force: :cascade do |t| + t.integer "photo_id" + t.integer "seed_id" + end + create_table "plant_parts", force: :cascade do |t| t.string "name" t.datetime "created_at" From a3c8bc0586f68b0457dc2acc5d7c7822b0f4b5bf Mon Sep 17 00:00:00 2001 From: Mackenzie Morgan Date: Thu, 1 Dec 2016 13:23:52 -0500 Subject: [PATCH 2/3] include the migration --- db/migrate/20161201154922_add_photos_seeds_table.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 db/migrate/20161201154922_add_photos_seeds_table.rb diff --git a/db/migrate/20161201154922_add_photos_seeds_table.rb b/db/migrate/20161201154922_add_photos_seeds_table.rb new file mode 100644 index 000000000..12605ae4c --- /dev/null +++ b/db/migrate/20161201154922_add_photos_seeds_table.rb @@ -0,0 +1,8 @@ +class AddPhotosSeedsTable < ActiveRecord::Migration + def change + create_table :photos_seeds, id: false do |t| + t.integer :photo_id + t.integer :seed_id + end + end +end From c201200e9bd9fbc021824fb20c70767c60b2d48e Mon Sep 17 00:00:00 2001 From: Mackenzie Morgan Date: Fri, 2 Dec 2016 23:17:01 -0500 Subject: [PATCH 3/3] correct schema and add index for photos_seeds --- db/migrate/20161201154922_add_photos_seeds_table.rb | 1 + db/schema.rb | 10 ++-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/db/migrate/20161201154922_add_photos_seeds_table.rb b/db/migrate/20161201154922_add_photos_seeds_table.rb index 12605ae4c..31693d225 100644 --- a/db/migrate/20161201154922_add_photos_seeds_table.rb +++ b/db/migrate/20161201154922_add_photos_seeds_table.rb @@ -4,5 +4,6 @@ class AddPhotosSeedsTable < ActiveRecord::Migration t.integer :photo_id t.integer :seed_id end + add_index(:photos_seeds, [:seed_id, :photo_id]) end end diff --git a/db/schema.rb b/db/schema.rb index 4901b8499..429fabf04 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -355,14 +355,6 @@ ActiveRecord::Schema.define(version: 20161201154922) do t.integer "product_id" end - create_table "photo_mappings", force: :cascade do |t| - t.integer "photo_id" - t.integer "object_id" - t.string "object_type" - end - - add_index "photo_mappings", ["object_id", "photo_id"], name: "index_photo_mappings_on_object_id_and_photo_id", using: :btree - create_table "photos", force: :cascade do |t| t.integer "owner_id", null: false t.string "thumbnail_url", null: false @@ -386,6 +378,8 @@ ActiveRecord::Schema.define(version: 20161201154922) do t.integer "seed_id" end + add_index "photos_seeds", ["seed_id", "photo_id"], name: "index_photos_seeds_on_seed_id_and_photo_id", using: :btree + create_table "plant_parts", force: :cascade do |t| t.string "name" t.datetime "created_at"