Skip to content

Commit

Permalink
Add unique index on people tmdb_id column
Browse files Browse the repository at this point in the history
  • Loading branch information
spohlenz committed Oct 9, 2024
1 parent b5f90f2 commit 2ba1395
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Person < ApplicationRecord
scope :alphabetical, -> { order(name: :asc) }

validates :name, presence: true
validates :tmdb_id, presence: true, uniqueness: true

enum gender: { "Not specified" => 0, "Female" => 1, "Male" => 2, "Non-Binary" => 3 }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddUniqueIndexOnPeopldTmdbId < ActiveRecord::Migration[7.2]
def change
remove_index :people, :tmdb_id
add_index :people, :tmdb_id, unique: true
end
end
5 changes: 2 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2021_05_14_120638) do
ActiveRecord::Schema[7.2].define(version: 2024_10_03_013148) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -106,7 +106,7 @@
t.datetime "updated_at", precision: nil, null: false
t.tsvector "tsv"
t.index ["name"], name: "index_people_on_name"
t.index ["tmdb_id"], name: "index_people_on_tmdb_id"
t.index ["tmdb_id"], name: "index_people_on_tmdb_id", unique: true
t.index ["tsv"], name: "index_people_on_tsv", using: :gin
end

Expand Down Expand Up @@ -156,5 +156,4 @@
t.datetime "updated_at", precision: nil, null: false
t.index ["media_type", "media_id"], name: "index_videos_on_media_type_and_media_id"
end

end
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).

puts "Creating demo user ([email protected] / demo)...\n"
Administrator.create!(email: "[email protected]", password: "demo", first_name: "Demo", last_name: "User")
Administrator.create(email: "[email protected]", password: "demo", first_name: "Demo", last_name: "User")

# Pages of movies / TV shows to fetch
PAGES = ENV.fetch("PAGES") { 4 }.to_i
Expand Down

0 comments on commit 2ba1395

Please sign in to comment.