Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add editoast ci code to operational point search #6145

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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;
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_operational_point";
DROP TRIGGER IF EXISTS search_operational_point__ins_trig ON "infra_object_operational_point";
DROP TRIGGER IF EXISTS search_operational_point__upd_trig ON "infra_object_operational_point";
DROP FUNCTION IF EXISTS search_operational_point__ins_trig_fun;
DROP FUNCTION IF EXISTS search_operational_point__upd_trig_fun;
85 changes: 85 additions & 0 deletions editoast/migrations/2023-12-19-122428_search_op_ci_code/up.sql
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_operational_point";

CREATE TABLE "search_operational_point" (
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_operational_point_obj_id" ON "search_operational_point" ("obj_id");
CREATE INDEX "search_operational_point_infra_id" ON "search_operational_point" ("infra_id");
CREATE INDEX "search_operational_point_uic" ON "search_operational_point" ("uic");
CREATE INDEX "search_operational_point_trigram" ON "search_operational_point" ("trigram");
CREATE INDEX "search_operational_point_ci" ON "search_operational_point" ("ci");
CREATE INDEX "search_operational_point_ch" ON "search_operational_point" ("ch");
CREATE INDEX "search_operational_point_name" ON "search_operational_point" USING gin ("name" gin_trgm_ops);

CREATE OR REPLACE FUNCTION search_operational_point__ins_trig_fun()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO "search_operational_point" (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_operational_point__ins_trig
AFTER INSERT ON "infra_object_operational_point"
FOR EACH ROW EXECUTE FUNCTION search_operational_point__ins_trig_fun();


CREATE OR REPLACE FUNCTION search_operational_point__upd_trig_fun()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
UPDATE "search_operational_point"
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_operational_point".id;
RETURN NEW;
END;
$$;
CREATE OR REPLACE TRIGGER search_operational_point__upd_trig
AFTER UPDATE ON "infra_object_operational_point"
FOR EACH ROW EXECUTE FUNCTION search_operational_point__upd_trig_fun();



INSERT INTO "search_operational_point"
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"
;
5 changes: 5 additions & 0 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2388,6 +2388,10 @@ components:
properties:
ch:
type: string
ci:
format: int64
minimum: 0
type: integer
geographic:
$ref: '#/components/schemas/GeoJsonPoint'
infra_id:
Expand Down Expand Up @@ -2424,6 +2428,7 @@ components:
- name
- trigram
- ch
- ci
- geographic
- schematic
- track_sections
Expand Down
7 changes: 4 additions & 3 deletions editoast/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,15 @@ diesel::table! {

search_operational_point (id) {
id -> Int8,
name -> Nullable<Text>,
infra_id -> Nullable<Int4>,
#[max_length = 255]
obj_id -> Nullable<Varchar>,
infra_id -> Nullable<Int4>,
uic -> Nullable<Int4>,
ch -> Nullable<Text>,
#[max_length = 3]
trigram -> Nullable<Varchar>,
ci -> Nullable<Int4>,
ch -> Nullable<Text>,
name -> Nullable<Text>,
}
}

Expand Down
45 changes: 39 additions & 6 deletions editoast/src/views/search/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,47 @@ pub(super) struct SearchResultItemTrack {
#[search(
name = "operationalpoint",
table = "search_operational_point",
migration(src_table = "infra_object_operational_point"),
joins = "
INNER JOIN infra_object_operational_point AS OP ON OP.id = search_operational_point.id
INNER JOIN (SELECT DISTINCT ON (infra_id, obj_id) * FROM infra_layer_operational_point)
AS lay ON OP.obj_id = lay.obj_id AND OP.infra_id = lay.infra_id",
column(name = "obj_id", data_type = "string"),
column(name = "infra_id", data_type = "integer"),
column(name = "name", data_type = "string"),
column(name = "uic", data_type = "integer"),
column(name = "ch", data_type = "string"),
column(name = "trigram", data_type = "string")
column(
name = "obj_id",
data_type = "varchar(255)",
sql = "infra_object_operational_point.obj_id",
),
column(
name = "infra_id",
data_type = "integer",
sql = "infra_object_operational_point.infra_id",
),
column(
name = "uic",
data_type = "integer",
sql = "(infra_object_operational_point.data->'extensions'->'identifier'->>'uic')::integer",
),
column(
name = "trigram",
data_type = "varchar(3)",
sql = "infra_object_operational_point.data->'extensions'->'sncf'->>'trigram'",
),
column(
name = "ci",
data_type = "integer",
sql = "(infra_object_operational_point.data->'extensions'->'sncf'->>'ci')::integer",
),
column(
name = "ch",
data_type = "text",
sql = "infra_object_operational_point.data->'extensions'->'sncf'->>'ch'",
),
column(
name = "name",
data_type = "text",
sql = "infra_object_operational_point.data->'extensions'->'identifier'->>'name'",
textual_search,
)
)]
#[allow(unused)]
/// A search result item for a query with `object = "operationalpoint"`
Expand All @@ -64,6 +95,8 @@ pub(super) struct SearchResultItemOperationalPoint {
trigram: String,
#[search(sql = "OP.data#>>'{extensions,sncf,ch}'")]
ch: String,
#[search(sql = "OP.data#>>'{extensions,sncf,ci}'")]
ci: u64,
#[search(sql = "ST_AsGeoJSON(ST_Transform(lay.geographic, 4326))::json")]
geographic: GeoJsonPoint,
#[search(sql = "ST_AsGeoJSON(ST_Transform(lay.schematic, 4326))::json")]
Expand Down
6 changes: 4 additions & 2 deletions editoast/src/views/search/search_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ impl SearchConfig {
};
let insert_trigger_name = format!("{table}__ins_trig");
let update_trigger_name = format!("{table}__upd_trig");
let insert_trigger_function = format!("{table}__ins_trig_fun");
let update_trigger_function = format!("{table}__upd_trig_fun");
let insert_trigger = format!(
include_str!("sql/insert_trigger_template.sql"),
trigger = insert_trigger_name,
Expand Down Expand Up @@ -166,8 +168,8 @@ CREATE TABLE "{table}" (
DROP TABLE IF EXISTS "{table}";
DROP TRIGGER IF EXISTS {insert_trigger_name} ON "{src_table}";
DROP TRIGGER IF EXISTS {update_trigger_name} ON "{src_table}";
DROP FUNCTION IF EXISTS {insert_trigger_name};
DROP FUNCTION IF EXISTS {update_trigger_name};
DROP FUNCTION IF EXISTS {insert_trigger_function};
DROP FUNCTION IF EXISTS {update_trigger_function};
{append_down}"#
);
(up, down)
Expand Down
1 change: 1 addition & 0 deletions front/src/common/api/osrdEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,7 @@ export type SearchResultItemTrack = {
};
export type SearchResultItemOperationalPoint = {
ch: string;
ci: number;
geographic: GeoJsonPoint;
infra_id: number;
name: string;
Expand Down
Loading