db: drop dependency on Postgres test_parser extension.

Drop the final dependency on the Postgres test_parser extension.

We also have to remove references to test_parser in the migration where
it was first defined, otherwise replaying all migrations from the
beginning will fail. Replaying all migrations from the beginning
normally isn't done except in testing.

After this, it should be possible to use a vanilla install of Postgres
with Danbooru. It's still recommended to use Danbooru's Docker image for
Postgres (https://ghcr.io/danbooru/postgres), as other Postgres extensions
may be necessary in the future.
This commit is contained in:
evazion
2021-10-14 01:53:21 -05:00
parent c8e4dceedb
commit d50cfdb856
4 changed files with 77 additions and 103 deletions

View File

@@ -75,32 +75,40 @@ class CreatePosts < ActiveRecord::Migration[4.2]
execute "SET statement_timeout = 0"
execute "SET search_path = public"
execute "CREATE OR REPLACE FUNCTION testprs_start(internal, int4)
RETURNS internal
AS '$libdir/test_parser'
LANGUAGE C STRICT"
#execute "CREATE OR REPLACE FUNCTION testprs_start(internal, int4)
#RETURNS internal
#AS '$libdir/test_parser'
#LANGUAGE C STRICT"
execute "CREATE OR REPLACE FUNCTION testprs_getlexeme(internal, internal, internal)
RETURNS internal
AS '$libdir/test_parser'
LANGUAGE C STRICT"
#execute "CREATE OR REPLACE FUNCTION testprs_getlexeme(internal, internal, internal)
#RETURNS internal
#AS '$libdir/test_parser'
#LANGUAGE C STRICT"
execute "CREATE OR REPLACE FUNCTION testprs_end(internal)
RETURNS void
AS '$libdir/test_parser'
LANGUAGE C STRICT"
#execute "CREATE OR REPLACE FUNCTION testprs_end(internal)
#RETURNS void
#AS '$libdir/test_parser'
#LANGUAGE C STRICT"
execute "CREATE OR REPLACE FUNCTION testprs_lextype(internal)
RETURNS internal
AS '$libdir/test_parser'
LANGUAGE C STRICT"
#execute "CREATE OR REPLACE FUNCTION testprs_lextype(internal)
#RETURNS internal
#AS '$libdir/test_parser'
#LANGUAGE C STRICT"
#execute "CREATE TEXT SEARCH PARSER testparser (
# START = testprs_start,
# GETTOKEN = testprs_getlexeme,
# END = testprs_end,
# HEADLINE = pg_catalog.prsd_headline,
# LEXTYPES = testprs_lextype
#)"
execute "CREATE TEXT SEARCH PARSER testparser (
START = testprs_start,
GETTOKEN = testprs_getlexeme,
END = testprs_end,
START = pg_catalog.prsd_start,
GETTOKEN = pg_catalog.prsd_nexttoken,
END = pg_catalog.prsd_end,
HEADLINE = pg_catalog.prsd_headline,
LEXTYPES = testprs_lextype
LEXTYPES = pg_catalog.prsd_lextype
)"
execute "CREATE INDEX index_posts_on_tags_index ON posts USING gin (tag_index)"

View File

@@ -0,0 +1,47 @@
class DropTestParser < ActiveRecord::Migration[6.1]
def up
execute "DROP INDEX index_posts_on_tag_index"
execute "DROP TRIGGER trigger_posts_on_tag_index_update ON posts"
execute "DROP TEXT SEARCH CONFIGURATION danbooru"
execute "DROP TEXT SEARCH PARSER testparser"
execute "DROP FUNCTION IF EXISTS testprs_start"
execute "DROP FUNCTION IF EXISTS testprs_end"
execute "DROP FUNCTION IF EXISTS testprs_getlexeme"
execute "DROP FUNCTION IF EXISTS testprs_lextype"
end
def down
execute "CREATE OR REPLACE FUNCTION testprs_start(internal, int4)
RETURNS internal
AS '$libdir/test_parser'
LANGUAGE C STRICT"
execute "CREATE OR REPLACE FUNCTION testprs_getlexeme(internal, internal, internal)
RETURNS internal
AS '$libdir/test_parser'
LANGUAGE C STRICT"
execute "CREATE OR REPLACE FUNCTION testprs_end(internal)
RETURNS void
AS '$libdir/test_parser'
LANGUAGE C STRICT"
execute "CREATE OR REPLACE FUNCTION testprs_lextype(internal)
RETURNS internal
AS '$libdir/test_parser'
LANGUAGE C STRICT"
execute "CREATE TEXT SEARCH PARSER testparser (
START = testprs_start,
GETTOKEN = testprs_getlexeme,
END = testprs_end,
HEADLINE = pg_catalog.prsd_headline,
LEXTYPES = testprs_lextype
)"
execute "CREATE TEXT SEARCH CONFIGURATION public.danbooru (PARSER = public.testparser)"
execute "ALTER TEXT SEARCH CONFIGURATION public.danbooru ADD MAPPING FOR WORD WITH SIMPLE"
execute "CREATE TRIGGER trigger_posts_on_tag_index_update BEFORE INSERT OR UPDATE ON posts FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('tag_index', 'public.danbooru', 'tag_string', 'fav_string', 'pool_string')"
execute "CREATE INDEX index_posts_on_tag_index ON posts USING gin (tag_index)"
end
end

View File

@@ -60,42 +60,6 @@ CREATE FUNCTION public.reverse_textregexeq(text, text) RETURNS boolean
AS $_$ SELECT textregexeq($2, $1); $_$;
--
-- Name: testprs_end(internal); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.testprs_end(internal) RETURNS void
LANGUAGE c STRICT
AS '$libdir/test_parser', 'testprs_end';
--
-- Name: testprs_getlexeme(internal, internal, internal); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.testprs_getlexeme(internal, internal, internal) RETURNS internal
LANGUAGE c STRICT
AS '$libdir/test_parser', 'testprs_getlexeme';
--
-- Name: testprs_lextype(internal); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.testprs_lextype(internal) RETURNS internal
LANGUAGE c STRICT
AS '$libdir/test_parser', 'testprs_lextype';
--
-- Name: testprs_start(internal, integer); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.testprs_start(internal, integer) RETURNS internal
LANGUAGE c STRICT
AS '$libdir/test_parser', 'testprs_start';
--
-- Name: ~<<; Type: OPERATOR; Schema: public; Owner: -
--
@@ -107,29 +71,6 @@ CREATE OPERATOR public.~<< (
);
--
-- Name: testparser; Type: TEXT SEARCH PARSER; Schema: public; Owner: -
--
CREATE TEXT SEARCH PARSER public.testparser (
START = public.testprs_start,
GETTOKEN = public.testprs_getlexeme,
END = public.testprs_end,
HEADLINE = prsd_headline,
LEXTYPES = public.testprs_lextype );
--
-- Name: danbooru; Type: TEXT SEARCH CONFIGURATION; Schema: public; Owner: -
--
CREATE TEXT SEARCH CONFIGURATION public.danbooru (
PARSER = public.testparser );
ALTER TEXT SEARCH CONFIGURATION public.danbooru
ADD MAPPING FOR word WITH simple;
SET default_tablespace = '';
SET default_table_access_method = heap;
@@ -4356,13 +4297,6 @@ CREATE INDEX index_posts_on_string_to_array_tag_string ON public.posts USING gin
ALTER INDEX public.index_posts_on_string_to_array_tag_string ALTER COLUMN 1 SET STATISTICS 3000;
--
-- Name: index_posts_on_tag_index; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_posts_on_tag_index ON public.posts USING gin (tag_index);
--
-- Name: index_posts_on_uploader_id; Type: INDEX; Schema: public; Owner: -
--
@@ -4797,13 +4731,6 @@ CREATE TRIGGER trigger_forum_topics_on_update BEFORE INSERT OR UPDATE ON public.
CREATE TRIGGER trigger_notes_on_update BEFORE INSERT OR UPDATE ON public.notes FOR EACH ROW EXECUTE FUNCTION tsvector_update_trigger('body_index', 'pg_catalog.english', 'body');
--
-- Name: posts trigger_posts_on_tag_index_update; Type: TRIGGER; Schema: public; Owner: -
--
CREATE TRIGGER trigger_posts_on_tag_index_update BEFORE INSERT OR UPDATE ON public.posts FOR EACH ROW EXECUTE FUNCTION tsvector_update_trigger('tag_index', 'public.danbooru', 'tag_string', 'fav_string', 'pool_string');
--
-- Name: wiki_pages trigger_wiki_pages_on_update; Type: TRIGGER; Schema: public; Owner: -
--
@@ -5068,6 +4995,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20211008091234'),
('20211010181657'),
('20211011044400'),
('20211013011619');
('20211013011619'),
('20211014063943');