orders search query also working now
This commit is contained in:
@@ -44,6 +44,7 @@ mod m20260622_000002_product_variants;
|
||||
mod m20260622_000003_variant_stock_nullable;
|
||||
mod m20260622_000004_product_search;
|
||||
mod m20260622_000005_product_search_aggregate;
|
||||
mod m20260622_000006_order_search_indexes;
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@@ -92,6 +93,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260622_000003_variant_stock_nullable::Migration),
|
||||
Box::new(m20260622_000004_product_search::Migration),
|
||||
Box::new(m20260622_000005_product_search_aggregate::Migration),
|
||||
Box::new(m20260622_000006_order_search_indexes::Migration),
|
||||
// inject-above (do not remove this comment)
|
||||
]
|
||||
}
|
||||
|
||||
48
migration/src/m20260622_000006_order_search_indexes.rs
Normal file
48
migration/src/m20260622_000006_order_search_indexes.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
//! Trigram indexes so the admin order search stays fast as orders pile up.
|
||||
//!
|
||||
//! Order search is a plain substring (`ILIKE`) match over the high-signal,
|
||||
//! free-text order fields — order number, email, customer/company name — run
|
||||
//! through `f_unaccent` so diacritics and case never matter (see
|
||||
//! `orders::Entity::search`). These `pg_trgm` GIN indexes let those `ILIKE`
|
||||
//! lookups use an index instead of scanning every row. `pg_trgm` + `f_unaccent`
|
||||
//! already exist from the product-search migration.
|
||||
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.get_connection()
|
||||
.execute_unprepared(
|
||||
r#"
|
||||
CREATE INDEX idx_orders_number_trgm
|
||||
ON orders USING GIN (f_unaccent(order_number) gin_trgm_ops);
|
||||
CREATE INDEX idx_orders_email_trgm
|
||||
ON orders USING GIN (f_unaccent(email) gin_trgm_ops);
|
||||
CREATE INDEX idx_orders_customer_name_trgm
|
||||
ON orders USING GIN (f_unaccent(COALESCE(customer_name, '')) gin_trgm_ops);
|
||||
CREATE INDEX idx_orders_company_name_trgm
|
||||
ON orders USING GIN (f_unaccent(COALESCE(company_name, '')) gin_trgm_ops);
|
||||
"#,
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.get_connection()
|
||||
.execute_unprepared(
|
||||
r#"
|
||||
DROP INDEX IF EXISTS idx_orders_company_name_trgm;
|
||||
DROP INDEX IF EXISTS idx_orders_customer_name_trgm;
|
||||
DROP INDEX IF EXISTS idx_orders_email_trgm;
|
||||
DROP INDEX IF EXISTS idx_orders_number_trgm;
|
||||
"#,
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user