-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
editoast: add ci code to operational point search
- Loading branch information
Showing
9 changed files
with
189 additions
and
8 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
editoast/migrations/2023-12-18-145922_search_op_rename_table/down.sql
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,14 @@ | ||
ALTER TABLE infra_object_operational_point | ||
RENAME TO infra_object_operationalpoint; | ||
|
||
ALTER TRIGGER search_operational_point__ins_trig ON infra_object_operational_point | ||
RENAME TO search_operationalpoint__ins_trig; | ||
|
||
ALTER TRIGGER search_operational_point__upd_trig ON infra_object_operational_point | ||
RENAME TO search_operationalpoint__upd_trig; | ||
|
||
ALTER FUNCTION search_operational_point__ins_trig_fun () | ||
RENAME TO search_operationalpoint__ins_trig_fun; | ||
|
||
ALTER FUNCTION search_operational_point__upd_trig_fun () | ||
RENAME TO search_operationalpoint__upd_trig_fun; |
14 changes: 14 additions & 0 deletions
14
editoast/migrations/2023-12-18-145922_search_op_rename_table/up.sql
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,14 @@ | ||
ALTER TABLE infra_object_operationalpoint | ||
RENAME TO infra_object_operational_point; | ||
|
||
ALTER TRIGGER search_operationalpoint__ins_trig ON infra_object_operational_point | ||
RENAME TO search_operational_point__ins_trig; | ||
|
||
ALTER TRIGGER search_operationalpoint__upd_trig ON infra_object_operational_point | ||
RENAME TO search_operational_point__upd_trig; | ||
|
||
ALTER FUNCTION search_operationalpoint__ins_trig_fun () | ||
RENAME TO search_operational_point__ins_trig_fun; | ||
|
||
ALTER FUNCTION search_operationalpoint__upd_trig_fun () | ||
RENAME TO search_operational_point__upd_trig_fun; |
7 changes: 7 additions & 0 deletions
7
editoast/migrations/2023-12-19-122428_search_op_ci_code/down.sql
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,7 @@ | ||
-- DO NOT EDIT THIS FILE MANUALLY! | ||
|
||
DROP TABLE IF EXISTS "search_operationalpoint"; | ||
DROP TRIGGER IF EXISTS search_operationalpoint__ins_trig ON "infra_object_operational_point"; | ||
DROP TRIGGER IF EXISTS search_operationalpoint__upd_trig ON "infra_object_operational_point"; | ||
DROP FUNCTION IF EXISTS search_operationalpoint__ins_trig_fun; | ||
DROP FUNCTION IF EXISTS search_operationalpoint__upd_trig_fun; |
85 changes: 85 additions & 0 deletions
85
editoast/migrations/2023-12-19-122428_search_op_ci_code/up.sql
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,85 @@ | ||
-- DO NOT EDIT THIS FILE MANUALLY! | ||
-- To change the migration's content, use `editoast search make-migration`. | ||
-- To add custom SQL code, check out `#[derive(Search)]` attributes `prepend_sql` and `append_sql`. | ||
|
||
DROP TABLE IF EXISTS "search_operationalpoint"; | ||
|
||
CREATE TABLE "search_operationalpoint" ( | ||
id BIGINT PRIMARY KEY REFERENCES "infra_object_operational_point"("id") ON UPDATE CASCADE ON DELETE CASCADE, | ||
"obj_id" varchar(255), | ||
"infra_id" integer, | ||
"uic" integer, | ||
"trigram" varchar(3), | ||
"ci" integer, | ||
"ch" text, | ||
"name" text | ||
); | ||
|
||
CREATE INDEX "search_operationalpoint_obj_id" ON "search_operationalpoint" ("obj_id"); | ||
CREATE INDEX "search_operationalpoint_infra_id" ON "search_operationalpoint" ("infra_id"); | ||
CREATE INDEX "search_operationalpoint_uic" ON "search_operationalpoint" ("uic"); | ||
CREATE INDEX "search_operationalpoint_trigram" ON "search_operationalpoint" ("trigram"); | ||
CREATE INDEX "search_operationalpoint_ci" ON "search_operationalpoint" ("ci"); | ||
CREATE INDEX "search_operationalpoint_ch" ON "search_operationalpoint" ("ch"); | ||
CREATE INDEX "search_operationalpoint_name" ON "search_operationalpoint" USING gin ("name" gin_trgm_ops); | ||
|
||
CREATE OR REPLACE FUNCTION search_operationalpoint__ins_trig_fun() | ||
RETURNS TRIGGER | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
INSERT INTO "search_operationalpoint" (id, obj_id, infra_id, uic, trigram, ci, ch, name) | ||
SELECT "infra_object_operational_point".id AS id, (infra_object_operational_point.obj_id) AS obj_id, | ||
(infra_object_operational_point.infra_id) AS infra_id, | ||
((infra_object_operational_point.data->'extensions'->'identifier'->>'uic')::integer) AS uic, | ||
(infra_object_operational_point.data->'extensions'->'sncf'->>'trigram') AS trigram, | ||
((infra_object_operational_point.data->'extensions'->'sncf'->>'ci')::integer) AS ci, | ||
(infra_object_operational_point.data->'extensions'->'sncf'->>'ch') AS ch, | ||
osrd_prepare_for_search(infra_object_operational_point.data->'extensions'->'identifier'->>'name') AS name | ||
FROM (SELECT NEW.*) AS "infra_object_operational_point" | ||
; | ||
RETURN NEW; | ||
END; | ||
$$; | ||
CREATE OR REPLACE TRIGGER search_operationalpoint__ins_trig | ||
AFTER INSERT ON "infra_object_operational_point" | ||
FOR EACH ROW EXECUTE FUNCTION search_operationalpoint__ins_trig_fun(); | ||
|
||
|
||
CREATE OR REPLACE FUNCTION search_operationalpoint__upd_trig_fun() | ||
RETURNS TRIGGER | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
UPDATE "search_operationalpoint" | ||
SET "obj_id" = (infra_object_operational_point.obj_id), | ||
"infra_id" = (infra_object_operational_point.infra_id), | ||
"uic" = ((infra_object_operational_point.data->'extensions'->'identifier'->>'uic')::integer), | ||
"trigram" = (infra_object_operational_point.data->'extensions'->'sncf'->>'trigram'), | ||
"ci" = ((infra_object_operational_point.data->'extensions'->'sncf'->>'ci')::integer), | ||
"ch" = (infra_object_operational_point.data->'extensions'->'sncf'->>'ch'), | ||
"name" = osrd_prepare_for_search(infra_object_operational_point.data->'extensions'->'identifier'->>'name') | ||
FROM (SELECT NEW.*) AS "infra_object_operational_point" | ||
|
||
WHERE "infra_object_operational_point".id = "search_operationalpoint".id; | ||
RETURN NEW; | ||
END; | ||
$$; | ||
CREATE OR REPLACE TRIGGER search_operationalpoint__upd_trig | ||
AFTER UPDATE ON "infra_object_operational_point" | ||
FOR EACH ROW EXECUTE FUNCTION search_operationalpoint__upd_trig_fun(); | ||
|
||
|
||
|
||
INSERT INTO "search_operationalpoint" | ||
SELECT | ||
"infra_object_operational_point"."id" AS id, | ||
(infra_object_operational_point.obj_id) AS obj_id | ||
, (infra_object_operational_point.infra_id) AS infra_id | ||
, ((infra_object_operational_point.data->'extensions'->'identifier'->>'uic')::integer) AS uic | ||
, (infra_object_operational_point.data->'extensions'->'sncf'->>'trigram') AS trigram | ||
, ((infra_object_operational_point.data->'extensions'->'sncf'->>'ci')::integer) AS ci | ||
, (infra_object_operational_point.data->'extensions'->'sncf'->>'ch') AS ch | ||
, osrd_prepare_for_search(infra_object_operational_point.data->'extensions'->'identifier'->>'name') AS name | ||
FROM "infra_object_operational_point" | ||
; |
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
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