-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(community): Search index for roles (#1979)
fix(community): Search index for roles (#1979) No-Issue
- Loading branch information
1 parent
f168319
commit 5d53bbb
Showing
5 changed files
with
220 additions
and
124 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
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,38 @@ | ||
# Generated by Django 4.2.7 on 2023-11-15 15:52 | ||
|
||
import django.contrib.postgres.indexes | ||
import django.contrib.postgres.search | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("galaxy", "0045_setting"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="LegacyRoleSearchVector", | ||
fields=[ | ||
( | ||
"role", | ||
models.OneToOneField( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
primary_key=True, | ||
serialize=False, | ||
to="galaxy.legacyrole", | ||
), | ||
), | ||
("search_vector", django.contrib.postgres.search.SearchVectorField(default="")), | ||
("modified", models.DateTimeField(auto_now=True)), | ||
], | ||
options={ | ||
"indexes": [ | ||
django.contrib.postgres.indexes.GinIndex( | ||
fields=["search_vector"], name="galaxy_lega_search__13e661_gin" | ||
) | ||
], | ||
}, | ||
), | ||
] |
64 changes: 64 additions & 0 deletions
64
galaxy_ng/app/migrations/0047_update_role_search_vector_trigger.py
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,64 @@ | ||
# Generated by Django 4.2.7 on 2023-11-15 15:55 | ||
|
||
from django.db import migrations | ||
|
||
REBUILD_ROLES_TS_VECTOR = """ | ||
UPDATE galaxy_legacyrole SET name = name; | ||
""" | ||
|
||
CREATE_ROLE_TS_VECTOR_TRIGGER = """ | ||
CREATE OR REPLACE FUNCTION update_role_ts_vector() | ||
RETURNS TRIGGER | ||
AS $$ | ||
DECLARE | ||
_search_vector tsvector; | ||
_namespace text; | ||
BEGIN | ||
_namespace := (select name from galaxy_legacynamespace WHERE id = NEW.namespace_id); | ||
_search_vector := (((( | ||
setweight(to_tsvector(COALESCE(_namespace, '')), 'A') | ||
|| setweight(to_tsvector(COALESCE(NEW."name", '')), 'A')) | ||
|| setweight(to_tsvector(COALESCE(((NEW."full_metadata"->'tags'))::text, '')), 'B')) | ||
|| setweight(to_tsvector(COALESCE(((NEW."full_metadata"->'platforms'))::text, '')), 'C')) | ||
|| setweight(to_tsvector(COALESCE((NEW."full_metadata"->>'description'), '')), 'D')); | ||
INSERT INTO galaxy_legacyrolesearchvector(role_id,search_vector,modified) | ||
VALUES(new.id,_search_vector,current_timestamp) | ||
ON CONFLICT (role_id) | ||
DO UPDATE SET | ||
search_vector = _search_vector, modified = current_timestamp; | ||
RETURN NEW; | ||
END; | ||
$$ | ||
LANGUAGE plpgsql; | ||
DROP TRIGGER IF EXISTS update_ts_vector ON galaxy_legacyrole; | ||
CREATE TRIGGER update_ts_vector | ||
AFTER INSERT OR UPDATE | ||
ON galaxy_legacyrole | ||
FOR EACH ROW | ||
EXECUTE PROCEDURE update_role_ts_vector(); | ||
""" | ||
|
||
DROP_ROLE_TS_VECTOR_TRIGGER = """ | ||
DROP TRIGGER IF EXISTS update_ts_vector ON galaxy_legacyrole; | ||
DROP FUNCTION IF EXISTS update_role_ts_vector(); | ||
""" | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("galaxy", "0046_legacyrolesearchvector"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunSQL( | ||
sql=CREATE_ROLE_TS_VECTOR_TRIGGER, | ||
reverse_sql=DROP_ROLE_TS_VECTOR_TRIGGER, | ||
), | ||
migrations.RunSQL( | ||
sql=REBUILD_ROLES_TS_VECTOR, | ||
reverse_sql=migrations.RunSQL.noop, | ||
) | ||
] |
Oops, something went wrong.