[deploy] Add unique index on articles canonical_url (#10161)
This commit is contained in:
parent
ff0edc3540
commit
99b239bb80
4 changed files with 19 additions and 3 deletions
|
|
@ -51,8 +51,8 @@ class Article < ApplicationRecord
|
|||
|
||||
validates :body_markdown, length: { minimum: 0, allow_nil: false }, uniqueness: { scope: %i[user_id title] }
|
||||
validates :cached_tag_list, length: { maximum: 126 }
|
||||
validates :canonical_url, url: { allow_blank: true, no_local: true,
|
||||
schemes: %w[https http] }, uniqueness: { allow_blank: true }
|
||||
validates :canonical_url, uniqueness: { allow_nil: true }
|
||||
validates :canonical_url, url: { allow_blank: true, no_local: true, schemes: %w[https http] }
|
||||
validates :feed_source_url, uniqueness: { allow_blank: true }
|
||||
validates :main_image, url: { allow_blank: true, schemes: %w[https http] }
|
||||
validates :main_image_background_hex_color, format: /\A#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
class AddUniqueIndexToArticlesCanonicalUrl < ActiveRecord::Migration[6.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
unless index_exists?(:articles, :canonical_url, unique: true)
|
||||
add_index :articles, :canonical_url, unique: true, algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
if index_exists?(:articles, :canonical_url, unique: true)
|
||||
remove_index :articles, column: :canonical_url, algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -154,6 +154,7 @@ ActiveRecord::Schema.define(version: 2020_09_02_204028) do
|
|||
t.string "video_state"
|
||||
t.string "video_thumbnail_url"
|
||||
t.index ["boost_states"], name: "index_articles_on_boost_states", using: :gin
|
||||
t.index ["canonical_url"], name: "index_articles_on_canonical_url", unique: true
|
||||
t.index ["comment_score"], name: "index_articles_on_comment_score"
|
||||
t.index ["featured_number"], name: "index_articles_on_featured_number"
|
||||
t.index ["feed_source_url"], name: "index_articles_on_feed_source_url"
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ RSpec.describe Article, type: :model do
|
|||
it { is_expected.to validate_length_of(:title).is_at_most(128) }
|
||||
it { is_expected.to validate_presence_of(:title) }
|
||||
it { is_expected.to validate_presence_of(:user_id) }
|
||||
it { is_expected.to validate_uniqueness_of(:canonical_url).allow_blank }
|
||||
it { is_expected.to validate_uniqueness_of(:canonical_url).allow_nil }
|
||||
it { is_expected.to validate_uniqueness_of(:feed_source_url).allow_blank }
|
||||
it { is_expected.to validate_uniqueness_of(:slug).scoped_to(:user_id) }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue