diff --git a/db/migrate/20211104180156_add_category_id_to_sqm_category.rb b/db/migrate/20211104180156_add_category_id_to_sqm_category.rb new file mode 100644 index 00000000..3050ff9f --- /dev/null +++ b/db/migrate/20211104180156_add_category_id_to_sqm_category.rb @@ -0,0 +1,8 @@ +class AddCategoryIdToSqmCategory < ActiveRecord::Migration[6.1] + def change + add_column :sqm_categories, :category_id, :string, default: 'default-category-id', null: false + + # give everything a default value + change_column_default :sqm_categories, :category_id, from: 'default-category-id', to: nil + end +end diff --git a/db/migrate/20211104181819_add_subcategory_id_to_subcategory.rb b/db/migrate/20211104181819_add_subcategory_id_to_subcategory.rb new file mode 100644 index 00000000..bf8876d4 --- /dev/null +++ b/db/migrate/20211104181819_add_subcategory_id_to_subcategory.rb @@ -0,0 +1,7 @@ +class AddSubcategoryIdToSubcategory < ActiveRecord::Migration[6.1] + def change + add_column :subcategories, :subcategory_id, :string, default: 'default-subcategory-id', null: false + + change_column_default :subcategories, :subcategory_id, from: 'default-subcategory-id', to: nil + end +end diff --git a/db/schema.rb b/db/schema.rb index 4daa96b5..587a57a3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_11_02_130307) do +ActiveRecord::Schema.define(version: 2021_11_04_181819) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -221,6 +221,7 @@ ActiveRecord::Schema.define(version: 2021_11_02_130307) do t.integer "sort_index" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.string "category_id", null: false t.index ["slug"], name: "index_sqm_categories_on_slug", unique: true end @@ -242,6 +243,7 @@ ActiveRecord::Schema.define(version: 2021_11_02_130307) do t.text "description" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.string "subcategory_id", null: false end create_table "survey_item_responses", id: :serial, force: :cascade do |t| diff --git a/spec/factories.rb b/spec/factories.rb index 2a673a89..a9d31a37 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -18,6 +18,7 @@ FactoryBot.define do factory :sqm_category do name { "A #{rand} category" } + category_id { rand.to_s } description { "A description of a category" } slug { "a-#{rand}-category" } sort_index { 1 } @@ -25,6 +26,7 @@ FactoryBot.define do factory :subcategory do name { "A subcategory" } + subcategory_id { rand.to_s } description { "A description of a subcategory" } sqm_category