-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from zacstewart/fix-fulltext-timeout
Fix fulltext timeout
- Loading branch information
Showing
7 changed files
with
188 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# Prior to this migration, databases were created and auto-upgraded by | ||
# datamapper | ||
STARTING_POINT = <<-SQL | ||
-- | ||
-- PostgreSQL database dump | ||
-- | ||
-- Dumped from database version 13.4 | ||
-- Dumped by pg_dump version 13.4 | ||
SET statement_timeout = 0; | ||
SET lock_timeout = 0; | ||
SET idle_in_transaction_session_timeout = 0; | ||
SET client_encoding = 'UTF8'; | ||
SET standard_conforming_strings = on; | ||
SELECT pg_catalog.set_config('search_path', '', false); | ||
SET check_function_bodies = false; | ||
SET xmloption = content; | ||
SET client_min_messages = warning; | ||
SET row_security = off; | ||
SET default_tablespace = ''; | ||
SET default_table_access_method = heap; | ||
-- | ||
-- Name: tech404_index_channels; Type: TABLE; Schema: public; Owner: - | ||
-- | ||
CREATE TABLE public.tech404_index_channels ( | ||
id character varying(50) NOT NULL, | ||
name character varying(50), | ||
creator_id character varying(50), | ||
member boolean | ||
); | ||
-- | ||
-- Name: tech404_index_messages; Type: TABLE; Schema: public; Owner: - | ||
-- | ||
CREATE TABLE public.tech404_index_messages ( | ||
id integer NOT NULL, | ||
channel_id character varying(50), | ||
user_id character varying(50), | ||
text text, | ||
"timestamp" timestamp without time zone | ||
); | ||
-- | ||
-- Name: tech404_index_messages_id_seq; Type: SEQUENCE; Schema: public; Owner: - | ||
-- | ||
CREATE SEQUENCE public.tech404_index_messages_id_seq | ||
AS integer | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
-- | ||
-- Name: tech404_index_messages_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - | ||
-- | ||
ALTER SEQUENCE public.tech404_index_messages_id_seq OWNED BY public.tech404_index_messages.id; | ||
-- | ||
-- Name: tech404_index_users; Type: TABLE; Schema: public; Owner: - | ||
-- | ||
CREATE TABLE public.tech404_index_users ( | ||
id character varying(50) NOT NULL, | ||
name character varying(50), | ||
real_name character varying(50), | ||
image character varying(255) | ||
); | ||
-- | ||
-- Name: tech404_index_messages id; Type: DEFAULT; Schema: public; Owner: - | ||
-- | ||
ALTER TABLE ONLY public.tech404_index_messages ALTER COLUMN id SET DEFAULT nextval('public.tech404_index_messages_id_seq'::regclass); | ||
-- | ||
-- Name: tech404_index_channels tech404_index_channels_pkey; Type: CONSTRAINT; Schema: public; Owner: - | ||
-- | ||
ALTER TABLE ONLY public.tech404_index_channels | ||
ADD CONSTRAINT tech404_index_channels_pkey PRIMARY KEY (id); | ||
-- | ||
-- Name: tech404_index_messages tech404_index_messages_pkey; Type: CONSTRAINT; Schema: public; Owner: - | ||
-- | ||
ALTER TABLE ONLY public.tech404_index_messages | ||
ADD CONSTRAINT tech404_index_messages_pkey PRIMARY KEY (id); | ||
-- | ||
-- Name: tech404_index_users tech404_index_users_pkey; Type: CONSTRAINT; Schema: public; Owner: - | ||
-- | ||
ALTER TABLE ONLY public.tech404_index_users | ||
ADD CONSTRAINT tech404_index_users_pkey PRIMARY KEY (id); | ||
-- | ||
-- PostgreSQL database dump complete | ||
-- | ||
SQL | ||
|
||
migration 0, :starting_point do | ||
up do | ||
execute STARTING_POINT | ||
end | ||
|
||
down do | ||
drop_table :tech404logs_channels | ||
drop table :tech404logs_messages | ||
drop_table :tech404logs_users | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
migration 5, :add_fulltext_index_to_messages do | ||
up do | ||
execute <<~SQL | ||
CREATE MATERIALIZED VIEW searchable_messages AS | ||
SELECT | ||
messages.*, | ||
channels.name AS channel_name, | ||
users.image AS user_image, | ||
users.real_name AS user_real_name, | ||
users.name AS user_name, | ||
to_tsvector(messages.text || ' ' || channels.name || ' ' || users.real_name || ' ' || users.name) AS tsv | ||
FROM messages | ||
INNER JOIN users ON messages.user_id = users.id | ||
INNER JOIN channels ON messages.channel_id = channels.id | ||
WITH NO DATA; | ||
SQL | ||
|
||
execute 'CREATE INDEX searchable_messages_tsv ON searchable_messages USING gin(tsv)' | ||
end | ||
|
||
down do | ||
execute 'DROP INDEX searchable_messages_tsv' | ||
execute 'DROP MATERIALIZED VIEW searchable_messages;' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Tech404logs | ||
class SearchableMessage | ||
include DataMapper::Resource | ||
storage_names[:default] = 'searchable_messages' | ||
|
||
property :id, Serial | ||
property :channel_id, String | ||
property :user_id, String | ||
property :text, Text | ||
property :timestamp, DateTime | ||
|
||
belongs_to :user | ||
belongs_to :channel | ||
end | ||
end |