From 0aab717bb3024d689364fca3cc17f5527cf23958 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Thu, 25 Jun 2020 21:33:56 +0530 Subject: [PATCH] Chore: Add default value for label color (#981) --- app/models/label.rb | 2 +- .../20200625154254_add_default_value_to_color.rb | 11 +++++++++++ db/schema.rb | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20200625154254_add_default_value_to_color.rb diff --git a/app/models/label.rb b/app/models/label.rb index 9f59b194f..edecf5922 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -3,7 +3,7 @@ # Table name: labels # # id :bigint not null, primary key -# color :string +# color :string default("#1f93ff"), not null # description :text # show_on_sidebar :boolean # title :string diff --git a/db/migrate/20200625154254_add_default_value_to_color.rb b/db/migrate/20200625154254_add_default_value_to_color.rb new file mode 100644 index 000000000..9257cc3ae --- /dev/null +++ b/db/migrate/20200625154254_add_default_value_to_color.rb @@ -0,0 +1,11 @@ +class AddDefaultValueToColor < ActiveRecord::Migration[6.0] + def up + Label.where(color: nil).find_each { |u| u.update(color: '#1f93ff') } + + change_column :labels, :color, :string, default: '#1f93ff', null: false + end + + def down + change_column :labels, :color, :string, default: nil, null: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 4f967e4e1..b3820f7c2 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: 2020_06_25_124400) do +ActiveRecord::Schema.define(version: 2020_06_25_154254) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" @@ -274,7 +274,7 @@ ActiveRecord::Schema.define(version: 2020_06_25_124400) do create_table "labels", force: :cascade do |t| t.string "title" t.text "description" - t.string "color" + t.string "color", default: "#1f93ff", null: false t.boolean "show_on_sidebar" t.bigint "account_id" t.datetime "created_at", precision: 6, null: false