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