From 8383104d538f69db49b8a62aa80ba8a834258dd6 Mon Sep 17 00:00:00 2001 From: eraden Date: Fri, 16 Jun 2023 21:44:53 +0200 Subject: [PATCH] Improve check --- migration/src/lib.rs | 4 ++++ migration/src/notifications/mod.rs | 0 migration/src/sea_ext/mod.rs | 9 ++++++++- ...gration__sea_ext__tests__combine_not_null_or_sql.snap | 2 +- ...a_ext__tests__constraint_combine_not_null_or_sql.snap | 2 +- migrations/20230603073530_shippings.sql | 9 ++++----- 6 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 migration/src/notifications/mod.rs diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 801a96e..77cab86 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -1,3 +1,5 @@ +#![feature(box_patterns)] + pub use sea_orm_migration::prelude::*; pub mod carts; @@ -18,6 +20,8 @@ mod sea_ext; pub use sea_ext::*; pub mod stocks; pub use stocks::*; +pub mod notifications; +pub use notifications::*; pub mod types; pub use types::*; diff --git a/migration/src/notifications/mod.rs b/migration/src/notifications/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/migration/src/sea_ext/mod.rs b/migration/src/sea_ext/mod.rs index 05d228b..29f9be5 100644 --- a/migration/src/sea_ext/mod.rs +++ b/migration/src/sea_ext/mod.rs @@ -228,7 +228,14 @@ pub mod constraint { Check::Greater(l, r) => { f.write_fmt(format_args!("{} > {}", l.to_string(), r.to_string())) } - Check::Or(l, r) => f.write_fmt(format_args!("({l}) OR ({r})")), + Check::Or(l, r) => match (l, r) { + (box Check::Or(_, _), box Check::Or(_, _)) => { + f.write_fmt(format_args!("{l} OR {r}")) + } + (_, box Check::Or(_, _)) => f.write_fmt(format_args!("({l}) OR {r}")), + (box Check::Or(_, _), _) => f.write_fmt(format_args!("{l} OR ({r})")), + _ => f.write_fmt(format_args!("({l}) OR ({r})")), + }, Check::NotNull(l) => f.write_fmt(format_args!("{} IS NOT NULL", l.to_string())), } } diff --git a/migration/src/sea_ext/snapshots/migration__sea_ext__tests__combine_not_null_or_sql.snap b/migration/src/sea_ext/snapshots/migration__sea_ext__tests__combine_not_null_or_sql.snap index 43dccd9..b3a4733 100644 --- a/migration/src/sea_ext/snapshots/migration__sea_ext__tests__combine_not_null_or_sql.snap +++ b/migration/src/sea_ext/snapshots/migration__sea_ext__tests__combine_not_null_or_sql.snap @@ -2,4 +2,4 @@ source: migration/src/sea_ext/mod.rs expression: s.to_string() --- -"((((claim_order_id IS NOT NULL) OR (order_id IS NOT NULL)) OR (cart_id IS NOT NULL)) OR (swap_id IS NOT NULL)) OR (return_id IS NOT NULL)" +"(claim_order_id IS NOT NULL) OR (order_id IS NOT NULL) OR (cart_id IS NOT NULL) OR (swap_id IS NOT NULL) OR (return_id IS NOT NULL)" diff --git a/migration/src/sea_ext/snapshots/migration__sea_ext__tests__constraint_combine_not_null_or_sql.snap b/migration/src/sea_ext/snapshots/migration__sea_ext__tests__constraint_combine_not_null_or_sql.snap index a066ba4..b737c27 100644 --- a/migration/src/sea_ext/snapshots/migration__sea_ext__tests__constraint_combine_not_null_or_sql.snap +++ b/migration/src/sea_ext/snapshots/migration__sea_ext__tests__constraint_combine_not_null_or_sql.snap @@ -2,4 +2,4 @@ source: migration/src/sea_ext/mod.rs expression: c.to_string() --- -"CHECK ((((claim_order_id IS NOT NULL) OR (order_id IS NOT NULL)) OR (cart_id IS NOT NULL)) OR (swap_id IS NOT NULL)) OR (return_id IS NOT NULL)" +"CHECK ((claim_order_id IS NOT NULL) OR (order_id IS NOT NULL) OR (cart_id IS NOT NULL) OR (swap_id IS NOT NULL) OR (return_id IS NOT NULL))" diff --git a/migrations/20230603073530_shippings.sql b/migrations/20230603073530_shippings.sql index cf18e37..224ca3c 100644 --- a/migrations/20230603073530_shippings.sql +++ b/migrations/20230603073530_shippings.sql @@ -1,3 +1,7 @@ +--- DONE +--- DONE +--- DONE + CREATE TABLE tracking_links ( id uuid NOT NULL, @@ -23,11 +27,6 @@ CREATE TABLE custom_shipping_options metadata jsonb ); ---------- ---------- ---------- ---------- - CREATE TABLE shipping_methods ( id uuid NOT NULL,