Skip to content

Commit

Permalink
Use generated columns for Movie and TvShow tsv search indexes (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
spohlenz authored Oct 9, 2024
1 parent 42d6532 commit c8c5062
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
10 changes: 10 additions & 0 deletions db/migrate/20241009064048_add_generated_tsv_column_to_movies.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddGeneratedTsvColumnToMovies < ActiveRecord::Migration[7.2]
def up
execute "DROP TRIGGER IF EXISTS tsvectorupdate ON movies"

remove_column :movies, :tsv, :tsvector

add_column :movies, :tsv, :tsvector, as: "to_tsvector('english', coalesce(title, '') || ' ' || coalesce(tagline, '') || ' ' || coalesce(overview, ''))", stored: true
add_index :movies, :tsv, using: 'gin'
end
end
10 changes: 10 additions & 0 deletions db/migrate/20241009064855_add_generated_tsv_column_to_tv_shows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddGeneratedTsvColumnToTVShows < ActiveRecord::Migration[7.2]
def up
execute "DROP TRIGGER IF EXISTS tsvectorupdate ON tv_shows"

remove_column :tv_shows, :tsv, :tsvector

add_column :tv_shows, :tsv, :tsvector, as: "to_tsvector('english', coalesce(name, '') || ' ' || coalesce(overview, ''))", stored: true
add_index :tv_shows, :tsv, using: 'gin'
end
end
6 changes: 3 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.2].define(version: 2024_10_03_013148) do
ActiveRecord::Schema[7.2].define(version: 2024_10_09_064855) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -89,7 +89,7 @@
t.integer "vote_count", default: 0
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.tsvector "tsv"
t.virtual "tsv", type: :tsvector, as: "to_tsvector('english'::regconfig, (((((COALESCE(title, ''::character varying))::text || ' '::text) || (COALESCE(tagline, ''::character varying))::text) || ' '::text) || (COALESCE(overview, ''::character varying))::text))", stored: true
t.index ["release_date"], name: "index_movies_on_release_date"
t.index ["title"], name: "index_movies_on_title"
t.index ["tmdb_id"], name: "index_movies_on_tmdb_id"
Expand Down Expand Up @@ -138,7 +138,7 @@
t.integer "vote_count", default: 0
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.tsvector "tsv"
t.virtual "tsv", type: :tsvector, as: "to_tsvector('english'::regconfig, (((COALESCE(name, ''::character varying))::text || ' '::text) || (COALESCE(overview, ''::character varying))::text))", stored: true
t.index ["name"], name: "index_tv_shows_on_name"
t.index ["tmdb_id"], name: "index_tv_shows_on_tmdb_id"
t.index ["tsv"], name: "index_tv_shows_on_tsv", using: :gin
Expand Down

0 comments on commit c8c5062

Please sign in to comment.