[deploy] Add unique indexes - part 3 (#8050)
This commit is contained in:
parent
867a268a62
commit
7db40b2117
7 changed files with 50 additions and 5 deletions
|
|
@ -11,6 +11,7 @@ class GithubIssue < ApplicationRecord
|
|||
|
||||
validates :category, inclusion: { in: CATEGORIES }
|
||||
validates :url, presence: true, length: { maximum: 400 }, format: API_URL_REGEXP
|
||||
validates :url, uniqueness: true
|
||||
|
||||
class << self
|
||||
def find_or_fetch(url)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
class AddUniqueIndexToGithubRepoUrlGithubIdCode < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :github_repos, :url, unique: true, algorithm: :concurrently
|
||||
add_index :github_repos, :github_id_code, unique: true, algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
class AddUniqueIndexToDataUpdateScriptFilename < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :data_update_scripts, :file_name, unique: true, algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
class AddUniqueIndexToCollectionSlug < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :collections, %w[slug user_id], unique: true, algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
class AddUniqueIndexToGithubIssueUrl < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :github_issues, :url, unique: true, algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2020_05_21_153435) do
|
||||
ActiveRecord::Schema.define(version: 2020_05_25_125611) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
|
@ -361,6 +361,7 @@ ActiveRecord::Schema.define(version: 2020_05_21_153435) do
|
|||
t.datetime "updated_at", null: false
|
||||
t.integer "user_id"
|
||||
t.index ["organization_id"], name: "index_collections_on_organization_id"
|
||||
t.index ["slug", "user_id"], name: "index_collections_on_slug_and_user_id", unique: true
|
||||
t.index ["user_id"], name: "index_collections_on_user_id"
|
||||
end
|
||||
|
||||
|
|
@ -414,6 +415,7 @@ ActiveRecord::Schema.define(version: 2020_05_21_153435) do
|
|||
t.datetime "run_at"
|
||||
t.integer "status", default: 0, null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["file_name"], name: "index_data_update_scripts_on_file_name", unique: true
|
||||
end
|
||||
|
||||
create_table "display_ad_events", force: :cascade do |t|
|
||||
|
|
@ -526,6 +528,7 @@ ActiveRecord::Schema.define(version: 2020_05_21_153435) do
|
|||
t.string "processed_html"
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "url"
|
||||
t.index ["url"], name: "index_github_issues_on_url", unique: true
|
||||
end
|
||||
|
||||
create_table "github_repos", force: :cascade do |t|
|
||||
|
|
@ -545,6 +548,8 @@ ActiveRecord::Schema.define(version: 2020_05_21_153435) do
|
|||
t.string "url"
|
||||
t.integer "user_id"
|
||||
t.integer "watchers_count"
|
||||
t.index ["github_id_code"], name: "index_github_repos_on_github_id_code", unique: true
|
||||
t.index ["url"], name: "index_github_repos_on_url", unique: true
|
||||
end
|
||||
|
||||
create_table "html_variant_successes", force: :cascade do |t|
|
||||
|
|
|
|||
|
|
@ -58,9 +58,14 @@ RSpec.describe "Articles", type: :request do
|
|||
end
|
||||
|
||||
shared_context "when user/organization articles exist" do
|
||||
let(:organization) { create(:organization) }
|
||||
let!(:user_article) { create(:article, user_id: user.id) }
|
||||
let!(:organization_article) { create(:article, organization_id: organization.id) }
|
||||
let_it_be_readonly(:user) { create(:user) }
|
||||
let_it_be_readonly(:organization) { create(:organization) }
|
||||
let_it_be_readonly(:user_article) do
|
||||
create(:article, user: user, title: "user_article_title")
|
||||
end
|
||||
let_it_be_readonly(:organization_article) do
|
||||
create(:article, organization: organization, title: "organization_article_title")
|
||||
end
|
||||
end
|
||||
|
||||
context "when :username param is given and belongs to a user" do
|
||||
|
|
@ -85,7 +90,12 @@ RSpec.describe "Articles", type: :request do
|
|||
|
||||
context "when :username param is given but it belongs to nither user nor organization" do
|
||||
include_context "when user/organization articles exist"
|
||||
it("renders empty body") { expect { get "/feed", params: { username: "unknown" } }.to raise_error(ActiveRecord::RecordNotFound) }
|
||||
|
||||
it "renders empty body" do
|
||||
expect do
|
||||
get feed_path("unknown")
|
||||
end.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "when format is invalid" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue