Feature: Improve label experience (#975)

Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
Pranav Raj S
2020-06-25 21:04:03 +05:30
committed by GitHub
parent 8b61452d56
commit 97ad39713b
56 changed files with 1712 additions and 284 deletions

View File

@@ -0,0 +1,20 @@
class MigrateAndAddUniqueIndexToLabels < ActiveRecord::Migration[6.0]
def change
add_index :labels, [:title, :account_id], unique: true
migrate_existing_tags
end
private
def migrate_existing_tags
::ActsAsTaggableOn::Tag.all.each do |tag|
tag.taggings.each do |tagging|
ensure_label_for_account(tag.name, tagging.taggable.account)
end
end
end
def ensure_label_for_account(name, account)
account.labels.where(title: name.downcase).first_or_create
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_06_10_143132) do
ActiveRecord::Schema.define(version: 2020_06_25_124400) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
@@ -280,6 +280,7 @@ ActiveRecord::Schema.define(version: 2020_06_10_143132) do
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["account_id"], name: "index_labels_on_account_id"
t.index ["title", "account_id"], name: "index_labels_on_title_and_account_id", unique: true
end
create_table "messages", id: :serial, force: :cascade do |t|