From 02a6a1c8d8baa9a48f10929818b57686d8f982d2 Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Thu, 31 Jul 2025 14:12:45 +0200 Subject: [PATCH] Add indexes for models in postgres Signed-off-by: Lee Smet --- heromodels/src/db/postgres.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/heromodels/src/db/postgres.rs b/heromodels/src/db/postgres.rs index ca466cc..945c358 100644 --- a/heromodels/src/db/postgres.rs +++ b/heromodels/src/db/postgres.rs @@ -147,7 +147,17 @@ WHERE table_name = $1 ) .map_err(Error::from)?; - // TODO: Create indexes + for indexed_field in M::indexed_fields() { + tx.execute( + &format!( + "CREATE INDEX {0}_{1}_idx ON {0} ( (value->'{1}') )", + Self::collection_name::(), + indexed_field, + ), + &[], + ) + .map_err(Error::from)?; + } tx.commit().map_err(Error::from)?; }