diff --git a/Cargo.toml b/Cargo.toml index b14d88018..27858a613 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,8 +34,8 @@ tracing = { version = "0.1", default-features = false, features = ["attributes", rust_decimal = { version = "1", default-features = false, optional = true } bigdecimal = { version = "0.3", default-features = false, optional = true } sea-orm-macros = { version = "0.12.12", path = "sea-orm-macros", default-features = false, features = ["strum"] } -sea-query = { version = "0.30.4", default-features = false, features = ["thread-safe", "hashable-value", "backend-mysql", "backend-postgres", "backend-sqlite"] } -sea-query-binder = { version = "0.5.0", default-features = false, optional = true } +sea-query = { version = "0.31.0-rc.3", default-features = false, features = ["thread-safe", "hashable-value", "backend-mysql", "backend-postgres", "backend-sqlite"] } +sea-query-binder = { version = "0.6.0-rc.1", default-features = false, optional = true } strum = { version = "0.25", default-features = false } serde = { version = "1.0", default-features = false } serde_json = { version = "1.0", default-features = false, optional = true } diff --git a/examples/basic/src/example_filling.rs b/examples/basic/src/example_filling.rs index 008d84b43..fe0545064 100644 --- a/examples/basic/src/example_filling.rs +++ b/examples/basic/src/example_filling.rs @@ -55,7 +55,7 @@ impl ColumnTrait for Column { fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), - Self::Name => ColumnType::String(None).def(), + Self::Name => ColumnType::string(None).def(), } } } diff --git a/examples/basic/src/example_fruit.rs b/examples/basic/src/example_fruit.rs index 59a072e9c..038753299 100644 --- a/examples/basic/src/example_fruit.rs +++ b/examples/basic/src/example_fruit.rs @@ -62,7 +62,7 @@ impl ColumnTrait for Column { fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), - Self::Name => ColumnType::String(None).def(), + Self::Name => ColumnType::string(None).def(), Self::CakeId => ColumnType::Integer.def(), } } diff --git a/examples/seaography_example/graphql/src/entities/cake.rs b/examples/seaography_example/graphql/src/entities/cake.rs index 2fe78ca1d..30e1ee200 100644 --- a/examples/seaography_example/graphql/src/entities/cake.rs +++ b/examples/seaography_example/graphql/src/entities/cake.rs @@ -8,7 +8,7 @@ pub struct Model { #[sea_orm(primary_key)] pub id: i32, pub name: String, - #[sea_orm(column_type = "Decimal(Some((19, 4)))")] + #[sea_orm(column_type = "Decimal(Some((16, 4)))")] pub price: Decimal, pub bakery_id: Option, pub gluten_free: i8, diff --git a/examples/seaography_example/migration/src/entity/cake.rs b/examples/seaography_example/migration/src/entity/cake.rs index 58bc8edc0..b0990d663 100644 --- a/examples/seaography_example/migration/src/entity/cake.rs +++ b/examples/seaography_example/migration/src/entity/cake.rs @@ -8,7 +8,7 @@ pub struct Model { #[sea_orm(primary_key)] pub id: i32, pub name: String, - #[sea_orm(column_type = "Decimal(Some((19, 4)))")] + #[sea_orm(column_type = "Decimal(Some((16, 4)))")] pub price: Decimal, pub bakery_id: Option, pub gluten_free: i8, diff --git a/examples/seaography_example/migration/src/m20230101_000003_create_cake_table.rs b/examples/seaography_example/migration/src/m20230101_000003_create_cake_table.rs index a73b53f59..33f86096a 100644 --- a/examples/seaography_example/migration/src/m20230101_000003_create_cake_table.rs +++ b/examples/seaography_example/migration/src/m20230101_000003_create_cake_table.rs @@ -18,7 +18,7 @@ impl MigrationTrait for Migration { .primary_key(), ) .col(ColumnDef::new(Cake::Name).string().not_null()) - .col(ColumnDef::new(Cake::Price).decimal_len(19, 4).not_null()) + .col(ColumnDef::new(Cake::Price).decimal_len(16, 4).not_null()) .col(ColumnDef::new(Cake::BakeryId).integer()) .foreign_key( ForeignKey::create() diff --git a/issues/1143/src/entity/sea_orm_active_enums.rs b/issues/1143/src/entity/sea_orm_active_enums.rs index 57ba0551e..887edf62c 100644 --- a/issues/1143/src/entity/sea_orm_active_enums.rs +++ b/issues/1143/src/entity/sea_orm_active_enums.rs @@ -1,7 +1,7 @@ use sea_orm::entity::prelude::*; #[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] -#[sea_orm(rs_type = "String", db_type = "String(Some(1))")] +#[sea_orm(rs_type = "String", db_type = "string(Some(1))")] pub enum Category { #[sea_orm(string_value = "B")] Big, diff --git a/issues/1599/entity/src/filling.rs b/issues/1599/entity/src/filling.rs index 21a90301b..30d1009ff 100644 --- a/issues/1599/entity/src/filling.rs +++ b/issues/1599/entity/src/filling.rs @@ -55,7 +55,7 @@ impl ColumnTrait for Column { fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), - Self::Name => ColumnType::String(None).def(), + Self::Name => ColumnType::string(None).def(), Self::VendorId => ColumnType::Integer.def().nullable(), } } diff --git a/sea-orm-cli/Cargo.toml b/sea-orm-cli/Cargo.toml index 2ab7d6fd3..8960b410a 100644 --- a/sea-orm-cli/Cargo.toml +++ b/sea-orm-cli/Cargo.toml @@ -38,7 +38,7 @@ clap = { version = "4.3", features = ["env", "derive"], optional = true } dotenvy = { version = "0.15", default-features = false, optional = true } async-std = { version = "1.9", default-features = false, features = ["attributes", "tokio1"], optional = true } sea-orm-codegen = { version = "=0.12.12", path = "../sea-orm-codegen", default-features = false, optional = true } -sea-schema = { version = "0.14.2" } +sea-schema = { version = "0.15.0-rc.1" } sqlx = { version = "0.7", default-features = false, features = ["mysql", "postgres"], optional = true } tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] } tracing = { version = "0.1", default-features = false } diff --git a/sea-orm-codegen/Cargo.toml b/sea-orm-codegen/Cargo.toml index 7ba52b49b..f7ed1ed02 100644 --- a/sea-orm-codegen/Cargo.toml +++ b/sea-orm-codegen/Cargo.toml @@ -17,7 +17,7 @@ name = "sea_orm_codegen" path = "src/lib.rs" [dependencies] -sea-query = { version = "0.30.0", default-features = false, features = ["thread-safe"] } +sea-query = { version = "0.31.0-rc.3", default-features = false, features = ["thread-safe"] } syn = { version = "2", default-features = false, features = ["parsing", "proc-macro", "derive", "printing"] } quote = { version = "1", default-features = false } heck = { version = "0.4", default-features = false } diff --git a/sea-orm-codegen/src/entity/base_entity.rs b/sea-orm-codegen/src/entity/base_entity.rs index f261f22e4..72ea224ee 100644 --- a/sea-orm-codegen/src/entity/base_entity.rs +++ b/sea-orm-codegen/src/entity/base_entity.rs @@ -284,7 +284,7 @@ mod tests { }, Column { name: "name".to_owned(), - col_type: ColumnType::String(None), + col_type: ColumnType::string(None), auto_increment: false, not_null: false, unique: false, diff --git a/sea-orm-codegen/src/entity/column.rs b/sea-orm-codegen/src/entity/column.rs index f5ba9284b..ce4210506 100644 --- a/sea-orm-codegen/src/entity/column.rs +++ b/sea-orm-codegen/src/entity/column.rs @@ -2,7 +2,7 @@ use crate::{util::escape_rust_keyword, DateTimeCrate}; use heck::{ToSnakeCase, ToUpperCamelCase}; use proc_macro2::{Ident, TokenStream}; use quote::{format_ident, quote}; -use sea_query::{BlobSize, ColumnDef, ColumnSpec, ColumnType}; +use sea_query::{ColumnDef, ColumnSpec, ColumnType, StringLen}; use std::fmt::Write as FmtWrite; #[derive(Clone, Debug)] @@ -96,14 +96,12 @@ impl Column { ColumnType::Text => Some("Text".to_owned()), ColumnType::JsonBinary => Some("JsonBinary".to_owned()), ColumnType::Custom(iden) => Some(format!("custom(\"{}\")", iden.to_string())), - ColumnType::Binary(BlobSize::Blob(None)) => Some("Binary(BlobSize::Blob(None))".into()), - ColumnType::Binary(BlobSize::Blob(Some(s))) => { - Some(format!("Binary(BlobSize::Blob(Some({s})))")) - } - ColumnType::Binary(BlobSize::Tiny) => Some("Binary(BlobSize::Tiny)".into()), - ColumnType::Binary(BlobSize::Medium) => Some("Binary(BlobSize::Medium)".into()), - ColumnType::Binary(BlobSize::Long) => Some("Binary(BlobSize::Long)".into()), - ColumnType::VarBinary(s) => Some(format!("VarBinary({s})")), + ColumnType::Binary(s) => Some(format!("Binary({s})")), + ColumnType::VarBinary(s) => match s { + StringLen::N(s) => Some(format!("VarBinary(StringLen::N({s}))")), + StringLen::None => Some("VarBinary(StringLen::None)".to_owned()), + StringLen::Max => Some("VarBinary(StringLen::Max)".to_owned()), + }, _ => None, }; col_type.map(|ty| quote! { column_type = #ty }) @@ -117,8 +115,9 @@ impl Column { None => quote! { ColumnType::Char(None) }, }, ColumnType::String(s) => match s { - Some(s) => quote! { ColumnType::String(Some(#s)) }, - None => quote! { ColumnType::String(None) }, + StringLen::N(s) => quote! { ColumnType::string(Some(#s)) }, + StringLen::None => quote! { ColumnType::string(None) }, + StringLen::Max => quote! { ColumnType::String(StringLen::Max) }, }, ColumnType::Text => quote! { ColumnType::Text }, ColumnType::TinyInteger => quote! { ColumnType::TinyInteger }, @@ -142,24 +141,14 @@ impl Column { } ColumnType::Time => quote! { ColumnType::Time }, ColumnType::Date => quote! { ColumnType::Date }, - ColumnType::Binary(BlobSize::Blob(None)) => { - quote! { ColumnType::Binary(BlobSize::Blob(None)) } - } - ColumnType::Binary(BlobSize::Blob(Some(s))) => { - quote! { ColumnType::Binary(BlobSize::Blob(Some(#s))) } - } - ColumnType::Binary(BlobSize::Tiny) => { - quote! { ColumnType::Binary(BlobSize::Tiny) } - } - ColumnType::Binary(BlobSize::Medium) => { - quote! { ColumnType::Binary(BlobSize::Medium) } - } - ColumnType::Binary(BlobSize::Long) => { - quote! { ColumnType::Binary(BlobSize::Long) } - } - ColumnType::VarBinary(s) => { - quote! { ColumnType::VarBinary(#s) } + ColumnType::Binary(s) => { + quote! { ColumnType::Binary(#s) } } + ColumnType::VarBinary(s) => match s { + StringLen::N(s) => quote! { ColumnType::VarBinary(StringLen::N(#s)) }, + StringLen::None => quote! { ColumnType::VarBinary(StringLen::None) }, + StringLen::Max => quote! { ColumnType::VarBinary(StringLen::Max) }, + }, ColumnType::Boolean => quote! { ColumnType::Boolean }, ColumnType::Money(s) => match s { Some((s1, s2)) => quote! { ColumnType::Money(Some((#s1, #s2))) }, @@ -298,7 +287,7 @@ mod tests { use crate::{Column, DateTimeCrate}; use proc_macro2::TokenStream; use quote::quote; - use sea_query::{Alias, BlobSize, ColumnDef, ColumnType, SeaRc}; + use sea_query::{Alias, ColumnDef, ColumnType, SeaRc, StringLen}; fn setup() -> Vec { macro_rules! make_col { @@ -313,7 +302,8 @@ mod tests { }; } vec![ - make_col!("id", ColumnType::String(Some(255))), + make_col!("id", ColumnType::string(Some(255))), + make_col!("id", ColumnType::string(None)), make_col!( "cake_id", ColumnType::Custom(SeaRc::new(Alias::new("cus_col"))) @@ -328,15 +318,10 @@ mod tests { make_col!("CakeFillingId", ColumnType::BigUnsigned), make_col!("cake-filling-id", ColumnType::Float), make_col!("CAKE_FILLING_ID", ColumnType::Double), - make_col!("CAKE-FILLING-ID", ColumnType::Binary(BlobSize::Blob(None))), - make_col!( - "CAKE-FILLING-ID", - ColumnType::Binary(BlobSize::Blob(Some(10))) - ), - make_col!("CAKE-FILLING-ID", ColumnType::Binary(BlobSize::Tiny)), - make_col!("CAKE-FILLING-ID", ColumnType::Binary(BlobSize::Medium)), - make_col!("CAKE-FILLING-ID", ColumnType::Binary(BlobSize::Long)), - make_col!("CAKE-FILLING-ID", ColumnType::VarBinary(10)), + make_col!("CAKE-FILLING-ID", ColumnType::Binary(10)), + make_col!("CAKE-FILLING-ID", ColumnType::VarBinary(StringLen::None)), + make_col!("CAKE-FILLING-ID", ColumnType::VarBinary(StringLen::N(10))), + make_col!("CAKE-FILLING-ID", ColumnType::VarBinary(StringLen::Max)), make_col!("CAKE", ColumnType::Boolean), make_col!("date", ColumnType::Date), make_col!("time", ColumnType::Time), @@ -350,6 +335,7 @@ mod tests { fn test_get_name_snake_case() { let columns = setup(); let snack_cases = vec![ + "id", "id", "cake_id", "cake_id", @@ -366,8 +352,6 @@ mod tests { "cake_filling_id", "cake_filling_id", "cake_filling_id", - "cake_filling_id", - "cake_filling_id", "cake", "date", "time", @@ -384,6 +368,7 @@ mod tests { fn test_get_name_camel_case() { let columns = setup(); let camel_cases = vec![ + "Id", "Id", "CakeId", "CakeId", @@ -400,8 +385,6 @@ mod tests { "CakeFillingId", "CakeFillingId", "CakeFillingId", - "CakeFillingId", - "CakeFillingId", "Cake", "Date", "Time", @@ -419,6 +402,7 @@ mod tests { let columns = setup(); let chrono_crate = DateTimeCrate::Chrono; let rs_types = vec![ + "String", "String", "String", "i8", @@ -435,8 +419,6 @@ mod tests { "Vec", "Vec", "Vec", - "Vec", - "Vec", "bool", "Date", "Time", @@ -466,6 +448,7 @@ mod tests { let columns = setup(); let time_crate = DateTimeCrate::Time; let rs_types = vec![ + "String", "String", "String", "i8", @@ -482,8 +465,6 @@ mod tests { "Vec", "Vec", "Vec", - "Vec", - "Vec", "bool", "TimeDate", "TimeTime", @@ -512,7 +493,8 @@ mod tests { fn test_get_def() { let columns = setup(); let col_defs = vec![ - "ColumnType::String(Some(255u32)).def()", + "ColumnType::string(Some(255u32)).def()", + "ColumnType::string(None).def()", "ColumnType::custom(\"cus_col\").def()", "ColumnType::TinyInteger.def()", "ColumnType::TinyUnsigned.def()", @@ -524,12 +506,10 @@ mod tests { "ColumnType::BigUnsigned.def()", "ColumnType::Float.def()", "ColumnType::Double.def()", - "ColumnType::Binary(BlobSize::Blob(None)).def()", - "ColumnType::Binary(BlobSize::Blob(Some(10u32))).def()", - "ColumnType::Binary(BlobSize::Tiny).def()", - "ColumnType::Binary(BlobSize::Medium).def()", - "ColumnType::Binary(BlobSize::Long).def()", - "ColumnType::VarBinary(10u32).def()", + "ColumnType::Binary(10u32).def()", + "ColumnType::VarBinary(StringLen::None).def()", + "ColumnType::VarBinary(StringLen::N(10u32)).def()", + "ColumnType::VarBinary(StringLen::Max).def()", "ColumnType::Boolean.def()", "ColumnType::Date.def()", "ColumnType::Time.def()", @@ -701,7 +681,7 @@ mod tests { assert_eq!( column.get_def().to_string(), quote! { - ColumnType::String(None).def().null() + ColumnType::string(None).def().null() } .to_string() ); diff --git a/sea-orm-codegen/src/entity/writer.rs b/sea-orm-codegen/src/entity/writer.rs index 3c4c17eeb..f85f956dc 100644 --- a/sea-orm-codegen/src/entity/writer.rs +++ b/sea-orm-codegen/src/entity/writer.rs @@ -993,7 +993,7 @@ mod tests { }, Column { name: "name".to_owned(), - col_type: ColumnType::String(Some(255)), + col_type: ColumnType::string(Some(255)), auto_increment: false, not_null: true, unique: false, @@ -1020,7 +1020,7 @@ mod tests { }, Column { name: "name".to_owned(), - col_type: ColumnType::String(Some(255)), + col_type: ColumnType::string(Some(255)), auto_increment: false, not_null: true, unique: false, @@ -1074,7 +1074,7 @@ mod tests { }, Column { name: "_name_".to_owned(), - col_type: ColumnType::String(Some(255)), + col_type: ColumnType::string(Some(255)), auto_increment: false, not_null: true, unique: false, diff --git a/sea-orm-codegen/tests/expanded/filling.rs b/sea-orm-codegen/tests/expanded/filling.rs index 22035244f..c359b564a 100644 --- a/sea-orm-codegen/tests/expanded/filling.rs +++ b/sea-orm-codegen/tests/expanded/filling.rs @@ -44,7 +44,7 @@ impl ColumnTrait for Column { fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), - Self::Name => ColumnType::String(Some(255u32)).def(), + Self::Name => ColumnType::string(Some(255u32)).def(), } } } diff --git a/sea-orm-codegen/tests/expanded/fruit.rs b/sea-orm-codegen/tests/expanded/fruit.rs index df1618cad..6de130f3c 100644 --- a/sea-orm-codegen/tests/expanded/fruit.rs +++ b/sea-orm-codegen/tests/expanded/fruit.rs @@ -49,7 +49,7 @@ impl ColumnTrait for Column { fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), - Self::Name => ColumnType::String(Some(255u32)).def(), + Self::Name => ColumnType::string(Some(255u32)).def(), Self::CakeId => ColumnType::Integer.def().null(), } } diff --git a/sea-orm-codegen/tests/expanded/vendor.rs b/sea-orm-codegen/tests/expanded/vendor.rs index 91cbbd47a..793f9c1c4 100644 --- a/sea-orm-codegen/tests/expanded/vendor.rs +++ b/sea-orm-codegen/tests/expanded/vendor.rs @@ -50,7 +50,7 @@ impl ColumnTrait for Column { fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), - Self::Name => ColumnType::String(Some(255u32)).def(), + Self::Name => ColumnType::string(Some(255u32)).def(), Self::FruitId => ColumnType::Integer.def().null(), } } diff --git a/sea-orm-codegen/tests/expanded_with_schema_name/filling.rs b/sea-orm-codegen/tests/expanded_with_schema_name/filling.rs index 918fd1bfc..606e20181 100644 --- a/sea-orm-codegen/tests/expanded_with_schema_name/filling.rs +++ b/sea-orm-codegen/tests/expanded_with_schema_name/filling.rs @@ -48,7 +48,7 @@ impl ColumnTrait for Column { fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), - Self::Name => ColumnType::String(Some(255u32)).def(), + Self::Name => ColumnType::string(Some(255u32)).def(), } } } diff --git a/sea-orm-codegen/tests/expanded_with_schema_name/fruit.rs b/sea-orm-codegen/tests/expanded_with_schema_name/fruit.rs index e2268ba67..57e2cc155 100644 --- a/sea-orm-codegen/tests/expanded_with_schema_name/fruit.rs +++ b/sea-orm-codegen/tests/expanded_with_schema_name/fruit.rs @@ -53,7 +53,7 @@ impl ColumnTrait for Column { fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), - Self::Name => ColumnType::String(Some(255u32)).def(), + Self::Name => ColumnType::string(Some(255u32)).def(), Self::CakeId => ColumnType::Integer.def().null(), } } diff --git a/sea-orm-codegen/tests/expanded_with_schema_name/vendor.rs b/sea-orm-codegen/tests/expanded_with_schema_name/vendor.rs index 1ad920abc..14e714926 100644 --- a/sea-orm-codegen/tests/expanded_with_schema_name/vendor.rs +++ b/sea-orm-codegen/tests/expanded_with_schema_name/vendor.rs @@ -54,7 +54,7 @@ impl ColumnTrait for Column { fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), - Self::Name => ColumnType::String(Some(255u32)).def(), + Self::Name => ColumnType::string(Some(255u32)).def(), Self::FruitId => ColumnType::Integer.def().null(), } } diff --git a/sea-orm-macros/src/derives/sql_type_match.rs b/sea-orm-macros/src/derives/sql_type_match.rs index 65465d12a..c954473a6 100644 --- a/sea-orm-macros/src/derives/sql_type_match.rs +++ b/sea-orm-macros/src/derives/sql_type_match.rs @@ -12,7 +12,7 @@ pub fn col_type_match( None => { let col_type = match field_type { "char" => quote! { Char(None) }, - "String" | "&str" => quote! { String(None) }, + "String" | "&str" => quote! { string(None) }, "i8" => quote! { TinyInteger }, "u8" => quote! { TinyUnsigned }, "i16" => quote! { SmallInteger }, @@ -36,7 +36,7 @@ pub fn col_type_match( "Json" => quote! { Json }, "Decimal" => quote! { Decimal(None) }, "Vec" => { - quote! { Binary(sea_orm::sea_query::BlobSize::Blob(None)) } + quote! { VarBinary(sea_orm::sea_query::StringLen::None) } } _ => { // Assumed it's ActiveEnum if none of the above type matches diff --git a/sea-orm-macros/src/lib.rs b/sea-orm-macros/src/lib.rs index 26256700f..23aa197f6 100644 --- a/sea-orm-macros/src/lib.rs +++ b/sea-orm-macros/src/lib.rs @@ -60,7 +60,7 @@ mod strum; /// # fn def(&self) -> ColumnDef { /// # match self { /// # Self::Id => ColumnType::Integer.def(), -/// # Self::Name => ColumnType::String(None).def(), +/// # Self::Name => ColumnType::string(None).def(), /// # } /// # } /// # } @@ -344,7 +344,7 @@ pub fn derive_custom_column(input: TokenStream) -> TokenStream { /// # fn def(&self) -> ColumnDef { /// # match self { /// # Self::Id => ColumnType::Integer.def(), -/// # Self::Name => ColumnType::String(None).def(), +/// # Self::Name => ColumnType::string(None).def(), /// # } /// # } /// # } @@ -417,7 +417,7 @@ pub fn derive_model(input: TokenStream) -> TokenStream { /// # fn def(&self) -> ColumnDef { /// # match self { /// # Self::Id => ColumnType::Integer.def(), -/// # Self::Name => ColumnType::String(None).def(), +/// # Self::Name => ColumnType::string(None).def(), /// # } /// # } /// # } @@ -503,7 +503,7 @@ pub fn derive_into_active_model(input: TokenStream) -> TokenStream { /// # fn def(&self) -> ColumnDef { /// # match self { /// # Self::Id => ColumnType::Integer.def(), -/// # Self::Name => ColumnType::String(None).def(), +/// # Self::Name => ColumnType::string(None).def(), /// # } /// # } /// # } diff --git a/sea-orm-migration/Cargo.toml b/sea-orm-migration/Cargo.toml index 71a4b4f33..57b7c5964 100644 --- a/sea-orm-migration/Cargo.toml +++ b/sea-orm-migration/Cargo.toml @@ -25,7 +25,7 @@ clap = { version = "4.3", features = ["env", "derive"], optional = true } dotenvy = { version = "0.15", default-features = false, optional = true } sea-orm = { version = "0.12.12", path = "../", default-features = false, features = ["macros"] } sea-orm-cli = { version = "0.12.12", path = "../sea-orm-cli", default-features = false, optional = true } -sea-schema = { version = "0.14.1" } +sea-schema = { version = "0.15.0-rc.1" } tracing = { version = "0.1", default-features = false, features = ["log"] } tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] } futures = { version = "0.3", default-features = false, features = ["std"] } diff --git a/src/entity/active_enum.rs b/src/entity/active_enum.rs index bb8df7358..7425913bf 100644 --- a/src/entity/active_enum.rs +++ b/src/entity/active_enum.rs @@ -20,7 +20,7 @@ use sea_query::{DynIden, Expr, Nullable, SimpleExpr, Value, ValueType}; /// #[derive(Debug, PartialEq, EnumIter, DeriveActiveEnum, DeriveDisplay)] /// #[sea_orm( /// rs_type = "String", -/// db_type = "String(Some(1))", +/// db_type = "string(Some(1))", /// enum_name = "category" /// )] /// pub enum DeriveCategory { @@ -74,7 +74,7 @@ use sea_query::{DynIden, Expr, Nullable, SimpleExpr, Value, ValueType}; /// /// fn db_type() -> ColumnDef { /// // The macro attribute `db_type` is being pasted here -/// ColumnType::String(Some(1)).def() +/// ColumnType::string(Some(1)).def() /// } /// } /// ``` @@ -86,7 +86,7 @@ use sea_query::{DynIden, Expr, Nullable, SimpleExpr, Value, ValueType}; /// /// // Define the `Category` active enum /// #[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, DeriveDisplay)] -/// #[sea_orm(rs_type = "String", db_type = "String(Some(1))")] +/// #[sea_orm(rs_type = "String", db_type = "string(Some(1))")] /// pub enum Category { /// #[sea_orm(string_value = "B")] /// Big, @@ -246,14 +246,14 @@ mod tests { } fn db_type() -> ColumnDef { - ColumnType::String(Some(1)).def() + ColumnType::string(Some(1)).def() } } #[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum, DeriveDisplay)] #[sea_orm( rs_type = "String", - db_type = "String(Some(1))", + db_type = "string(Some(1))", enum_name = "category" )] pub enum DeriveCategory { @@ -293,8 +293,8 @@ mod tests { Some(DeriveCategory::Small) ); - assert_eq!(Category::db_type(), ColumnType::String(Some(1)).def()); - assert_eq!(DeriveCategory::db_type(), ColumnType::String(Some(1)).def()); + assert_eq!(Category::db_type(), ColumnType::string(Some(1)).def()); + assert_eq!(DeriveCategory::db_type(), ColumnType::string(Some(1)).def()); assert_eq!( Category::name().to_string(), @@ -496,7 +496,7 @@ mod tests { #[derive(Clone, Debug, PartialEq, EnumIter, DeriveActiveEnum, DeriveDisplay)] #[sea_orm( rs_type = "String", - db_type = "String(None)", + db_type = "string(None)", enum_name = "conflicting_string_values" )] pub enum ConflictingStringValues { diff --git a/src/entity/column.rs b/src/entity/column.rs index b59f410e7..8256557e5 100644 --- a/src/entity/column.rs +++ b/src/entity/column.rs @@ -620,11 +620,11 @@ mod tests { ); assert_eq!( hello::Column::Twelve.def(), - ColumnType::String(None).def().default("twelve_value") + ColumnType::string(None).def().default("twelve_value") ); assert_eq!( hello::Column::TwelveTwo.def(), - ColumnType::String(None).def().default("twelve_value") + ColumnType::string(None).def().default("twelve_value") ); } diff --git a/src/entity/mod.rs b/src/entity/mod.rs index 92913c48f..131378229 100644 --- a/src/entity/mod.rs +++ b/src/entity/mod.rs @@ -80,7 +80,7 @@ /// fn def(&self) -> ColumnDef { /// match self { /// Self::Id => ColumnType::Integer.def(), -/// Self::Name => ColumnType::String(None).def(), +/// Self::Name => ColumnType::string(None).def(), /// } /// } /// } diff --git a/src/entity/prelude.rs b/src/entity/prelude.rs index 003ddcd02..fd1d91b1d 100644 --- a/src/entity/prelude.rs +++ b/src/entity/prelude.rs @@ -1,6 +1,6 @@ pub use crate::{ error::*, - sea_query::{BlobSize, DynIden, Expr, RcOrArc, SeaRc}, + sea_query::{DynIden, Expr, RcOrArc, SeaRc, StringLen}, ActiveEnum, ActiveModelBehavior, ActiveModelTrait, ColumnDef, ColumnTrait, ColumnType, ColumnTypeTrait, ConnectionTrait, CursorTrait, DatabaseConnection, DbConn, EntityName, EntityTrait, EnumIter, ForeignKeyAction, Iden, IdenStatic, Linked, LoaderTrait, ModelTrait, diff --git a/src/entity/primary_key.rs b/src/entity/primary_key.rs index 95f44331c..b4e69ca1b 100644 --- a/src/entity/primary_key.rs +++ b/src/entity/primary_key.rs @@ -170,7 +170,7 @@ mod tests { #[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] #[sea_orm( rs_type = "String", - db_type = "String(Some(1))", + db_type = "string(Some(1))", enum_name = "category" )] pub enum DeriveCategory { diff --git a/src/schema/entity.rs b/src/schema/entity.rs index 5e42d7b13..a99226631 100644 --- a/src/schema/entity.rs +++ b/src/schema/entity.rs @@ -197,13 +197,16 @@ where { let orm_column_def = column.def(); let types = match orm_column_def.col_type { - ColumnType::Enum { name, variants } => match backend { + ColumnType::Enum { + ref name, + ref variants, + } => match backend { DbBackend::MySql => { let variants: Vec = variants.iter().map(|v| v.to_string()).collect(); ColumnType::custom(format!("ENUM('{}')", variants.join("', '")).as_str()) } - DbBackend::Postgres => ColumnType::Custom(SeaRc::clone(&name)), - DbBackend::Sqlite => ColumnType::Text, + DbBackend::Postgres => ColumnType::Custom(SeaRc::clone(name)), + DbBackend::Sqlite => orm_column_def.col_type, }, _ => orm_column_def.col_type, }; diff --git a/src/tests_cfg/cake_expanded.rs b/src/tests_cfg/cake_expanded.rs index d0215b607..7675a7651 100644 --- a/src/tests_cfg/cake_expanded.rs +++ b/src/tests_cfg/cake_expanded.rs @@ -46,7 +46,7 @@ impl ColumnTrait for Column { fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), - Self::Name => ColumnType::String(None).def(), + Self::Name => ColumnType::string(None).def(), } } } diff --git a/src/tests_cfg/filling.rs b/src/tests_cfg/filling.rs index 882b76a95..055e2421b 100644 --- a/src/tests_cfg/filling.rs +++ b/src/tests_cfg/filling.rs @@ -58,7 +58,7 @@ impl ColumnTrait for Column { fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), - Self::Name => ColumnType::String(None).def(), + Self::Name => ColumnType::string(None).def(), Self::VendorId => ColumnType::Integer.def().nullable(), } } diff --git a/src/tests_cfg/lunch_set_expanded.rs b/src/tests_cfg/lunch_set_expanded.rs index c15bb59c7..0a904dba6 100644 --- a/src/tests_cfg/lunch_set_expanded.rs +++ b/src/tests_cfg/lunch_set_expanded.rs @@ -49,7 +49,7 @@ impl ColumnTrait for Column { fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), - Self::Name => ColumnType::String(None).def(), + Self::Name => ColumnType::string(None).def(), Self::Tea => Tea::db_type().def(), } } diff --git a/tests/common/bakery_chain/cake.rs b/tests/common/bakery_chain/cake.rs index 1096b420b..a43f989c3 100644 --- a/tests/common/bakery_chain/cake.rs +++ b/tests/common/bakery_chain/cake.rs @@ -7,7 +7,7 @@ pub struct Model { #[sea_orm(primary_key)] pub id: i32, pub name: String, - #[sea_orm(column_type = "Decimal(Some((19, 4)))")] + #[sea_orm(column_type = "Decimal(Some((16, 4)))")] pub price: Decimal, pub bakery_id: Option, pub gluten_free: bool, diff --git a/tests/common/bakery_chain/lineitem.rs b/tests/common/bakery_chain/lineitem.rs index 5b12d62cd..eb8b58785 100644 --- a/tests/common/bakery_chain/lineitem.rs +++ b/tests/common/bakery_chain/lineitem.rs @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - #[sea_orm(column_type = "Decimal(Some((19, 4)))")] + #[sea_orm(column_type = "Decimal(Some((16, 4)))")] pub price: Decimal, pub quantity: i32, pub order_id: i32, diff --git a/tests/common/bakery_chain/order.rs b/tests/common/bakery_chain/order.rs index 020de925b..bc137fc9f 100644 --- a/tests/common/bakery_chain/order.rs +++ b/tests/common/bakery_chain/order.rs @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - #[sea_orm(column_type = "Decimal(Some((19, 4)))")] + #[sea_orm(column_type = "Decimal(Some((16, 4)))")] pub total: Decimal, pub bakery_id: i32, pub customer_id: i32, diff --git a/tests/common/bakery_chain/schema.rs b/tests/common/bakery_chain/schema.rs index 94bbc6498..c40a61812 100644 --- a/tests/common/bakery_chain/schema.rs +++ b/tests/common/bakery_chain/schema.rs @@ -95,7 +95,7 @@ pub async fn create_order_table(db: &DbConn) -> Result { ) .col( ColumnDef::new(order::Column::Total) - .decimal_len(19, 4) + .decimal_len(16, 4) .not_null(), ) .col(ColumnDef::new(order::Column::BakeryId).integer().not_null()) @@ -142,7 +142,7 @@ pub async fn create_lineitem_table(db: &DbConn) -> Result { ) .col( ColumnDef::new(lineitem::Column::Price) - .decimal_len(19, 4) + .decimal_len(16, 4) .not_null(), ) .col( @@ -234,7 +234,7 @@ pub async fn create_cake_table(db: &DbConn) -> Result { .col(ColumnDef::new(cake::Column::Name).string().not_null()) .col( ColumnDef::new(cake::Column::Price) - .decimal_len(19, 4) + .decimal_len(16, 4) .not_null(), ) .col(ColumnDef::new(cake::Column::BakeryId).integer()) diff --git a/tests/common/features/binary.rs b/tests/common/features/binary.rs index 8ffd611a7..ee2511f77 100644 --- a/tests/common/features/binary.rs +++ b/tests/common/features/binary.rs @@ -5,18 +5,12 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - #[sea_orm(column_type = "Binary(BlobSize::Blob(None))")] + #[sea_orm(column_type = "Binary(1)")] pub binary: Vec, - #[sea_orm(column_type = "Binary(BlobSize::Blob(Some(10)))")] + #[sea_orm(column_type = "Binary(10)")] pub binary_10: Vec, - #[sea_orm(column_type = "Binary(BlobSize::Tiny)")] - pub binary_tiny: Vec, - #[sea_orm(column_type = "Binary(BlobSize::Medium)")] - pub binary_medium: Vec, - #[sea_orm(column_type = "Binary(BlobSize::Long)")] - pub binary_long: Vec, - #[sea_orm(column_type = "VarBinary(10)")] - pub var_binary: Vec, + #[sea_orm(column_type = "VarBinary(StringLen::N(16))")] + pub var_binary_16: Vec, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/tests/common/features/dyn_table_name_lazy_static.rs b/tests/common/features/dyn_table_name_lazy_static.rs index cb2b3b850..ada3b49e5 100644 --- a/tests/common/features/dyn_table_name_lazy_static.rs +++ b/tests/common/features/dyn_table_name_lazy_static.rs @@ -48,7 +48,7 @@ impl ColumnTrait for Column { fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), - Self::Name => ColumnType::String(None).def(), + Self::Name => ColumnType::string(None).def(), } } } diff --git a/tests/common/features/event_trigger.rs b/tests/common/features/event_trigger.rs index bdda7f45b..fd8e8707f 100644 --- a/tests/common/features/event_trigger.rs +++ b/tests/common/features/event_trigger.rs @@ -65,6 +65,6 @@ impl ValueType for Events { } fn column_type() -> ColumnType { - ColumnType::Array(RcOrArc::new(ColumnType::String(None))) + ColumnType::Array(RcOrArc::new(ColumnType::string(None))) } } diff --git a/tests/common/features/metadata.rs b/tests/common/features/metadata.rs index 688c005cd..05c65d007 100644 --- a/tests/common/features/metadata.rs +++ b/tests/common/features/metadata.rs @@ -9,6 +9,7 @@ pub struct Model { pub ty: String, pub key: String, pub value: String, + #[sea_orm(column_type = "var_binary(32)")] pub bytes: Vec, pub date: Option, pub time: Option