From 0b54289b608cffbe849e2f2d8bb669832577fb28 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 6 Dec 2022 16:25:07 +0800 Subject: [PATCH 1/5] MSRV 1.62 --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index c0533449..055e08ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ documentation = "https://docs.rs/sea-schema" repository = "https://github.com/SeaQL/sea-schema" categories = ["database"] keywords = ["database", "sql", "mysql", "postgres"] +rust-version = "1.62" [package.metadata.docs.rs] features = ["default"] From f5b2d500903363ddc3bc387cf14bff390769f00c Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 6 Dec 2022 16:44:38 +0800 Subject: [PATCH 2/5] Bump SeaQuery to 0.28.0 --- Cargo.toml | 2 +- src/mysql/probe.rs | 2 +- src/mysql/query/foreign_key.rs | 4 +- src/mysql/query/table.rs | 2 +- src/mysql/query/version.rs | 4 +- src/mysql/writer/column.rs | 90 +++++++-------------------- src/postgres/probe.rs | 2 +- src/postgres/query/constraints/mod.rs | 22 +++---- src/postgres/query/enumeration.rs | 2 +- src/postgres/writer/column.rs | 34 +++++----- src/probe.rs | 2 +- 11 files changed, 56 insertions(+), 110 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 055e08ac..d9bc555e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ path = "src/lib.rs" [dependencies] futures = { version = "0.3", optional = true } sea-schema-derive = { version = "0.1.0", path = "sea-schema-derive" } -sea-query = { version = "^0.27.1" } +sea-query = { version = "^0.28.0", git = "https://github.com/SeaQL/sea-query" } sea-query-binder = { version = "^0.2", optional = true } serde = { version = "^1", features = ["derive"], optional = true } sqlx = { version = "^0.6", optional = true } diff --git a/src/mysql/probe.rs b/src/mysql/probe.rs index fa152823..8381b1d1 100644 --- a/src/mysql/probe.rs +++ b/src/mysql/probe.rs @@ -16,7 +16,7 @@ impl SchemaProbe for MySql { .cond_where( Condition::all().add( Expr::expr(Self::get_current_schema()) - .equals(Schema::Tables, TablesFields::TableSchema), + .equals((Schema::Tables, TablesFields::TableSchema)), ), ) .take() diff --git a/src/mysql/query/foreign_key.rs b/src/mysql/query/foreign_key.rs index 7dfbb014..d931e251 100644 --- a/src/mysql/query/foreign_key.rs +++ b/src/mysql/query/foreign_key.rs @@ -64,10 +64,10 @@ impl SchemaQueryBuilder { .inner_join( (Schema::Schema, Schema::ReferentialConstraints), Expr::tbl(Schema::KeyColumnUsage, Key::ConstraintSchema) - .equals(Schema::ReferentialConstraints, Ref::ConstraintSchema) + .equals((Schema::ReferentialConstraints, Ref::ConstraintSchema)) .and( Expr::tbl(Schema::KeyColumnUsage, Key::ConstraintName) - .equals(Schema::ReferentialConstraints, Ref::ConstraintName), + .equals((Schema::ReferentialConstraints, Ref::ConstraintName)), ), ) .and_where( diff --git a/src/mysql/query/table.rs b/src/mysql/query/table.rs index 2a45b634..c6f7faf2 100644 --- a/src/mysql/query/table.rs +++ b/src/mysql/query/table.rs @@ -73,7 +73,7 @@ impl SchemaQueryBuilder { Schema::CollationCharacterSet, CharacterSetFields::CollationName, ) - .equals(Schema::Tables, TablesFields::TableCollation), + .equals((Schema::Tables, TablesFields::TableCollation)), ) .and_where(Expr::col(TablesFields::TableSchema).eq(schema.to_string())) .and_where(Expr::col(TablesFields::TableType).is_in([ diff --git a/src/mysql/query/version.rs b/src/mysql/query/version.rs index 5cad3e15..5d889321 100644 --- a/src/mysql/query/version.rs +++ b/src/mysql/query/version.rs @@ -14,9 +14,7 @@ pub struct VersionQueryResult { impl SchemaQueryBuilder { pub fn query_version(&self) -> SelectStatement { - Query::select() - .expr(Func::cust(MysqlFunc::Version).into_simple_expr()) - .take() + Query::select().expr(Func::cust(MysqlFunc::Version)).take() } } diff --git a/src/mysql/writer/column.rs b/src/mysql/writer/column.rs index ef77ffeb..3a578169 100644 --- a/src/mysql/writer/column.rs +++ b/src/mysql/writer/column.rs @@ -53,34 +53,20 @@ impl ColumnInfo { col_def.custom(self.col_type.clone()); } Type::TinyInt(num_attr) => { - if num_attr.unsigned.is_some() { - match num_attr.maximum { - Some(maximum) => col_def.tiny_unsigned_len(maximum), - None => col_def.tiny_unsigned(), - }; - } else { - match num_attr.maximum { - Some(maximum) => col_def.tiny_integer_len(maximum), - None => col_def.tiny_integer(), - }; - } + match num_attr.unsigned { + Some(_) => col_def.tiny_unsigned(), + None => col_def.tiny_integer(), + }; col_def = self.write_num_attr(col_def, num_attr); } Type::Bool => { col_def.boolean(); } Type::SmallInt(num_attr) => { - if num_attr.unsigned.is_some() { - match num_attr.maximum { - Some(maximum) => col_def.small_unsigned_len(maximum), - None => col_def.small_unsigned(), - }; - } else { - match num_attr.maximum { - Some(maximum) => col_def.small_integer_len(maximum), - None => col_def.small_integer(), - }; - } + match num_attr.unsigned { + Some(_) => col_def.small_unsigned(), + None => col_def.small_integer(), + }; col_def = self.write_num_attr(col_def, num_attr); } Type::MediumInt(_) => { @@ -88,74 +74,42 @@ impl ColumnInfo { col_def.custom(self.col_type.clone()); } Type::Int(num_attr) => { - if num_attr.unsigned.is_some() { - match num_attr.maximum { - Some(maximum) => col_def.unsigned_len(maximum), - None => col_def.unsigned(), - }; - } else { - match num_attr.maximum { - Some(maximum) => col_def.integer_len(maximum), - None => col_def.integer(), - }; - } + match num_attr.unsigned { + Some(_) => col_def.unsigned(), + None => col_def.integer(), + }; col_def = self.write_num_attr(col_def, num_attr); } Type::BigInt(num_attr) => { - if num_attr.unsigned.is_some() { - match num_attr.maximum { - Some(maximum) => col_def.big_unsigned_len(maximum), - None => col_def.big_unsigned(), - }; - } else { - match num_attr.maximum { - Some(maximum) => col_def.big_integer_len(maximum), - None => col_def.big_integer(), - }; - } + match num_attr.unsigned { + Some(_) => col_def.big_unsigned(), + None => col_def.big_integer(), + }; col_def = self.write_num_attr(col_def, num_attr); } Type::Decimal(num_attr) => { - match (num_attr.maximum, num_attr.decimal) { - (Some(maximum), Some(decimal)) => col_def.decimal_len(maximum, decimal), - _ => col_def.decimal(), - }; + col_def.decimal(); col_def = self.write_num_attr(col_def, num_attr); } Type::Float(num_attr) => { - match num_attr.decimal { - Some(decimal) => col_def.float_len(decimal), - _ => col_def.float(), - }; + col_def.float(); col_def = self.write_num_attr(col_def, num_attr); } Type::Double(num_attr) => { - match num_attr.decimal { - Some(decimal) => col_def.double_len(decimal), - _ => col_def.double(), - }; + col_def.double(); col_def = self.write_num_attr(col_def, num_attr); } Type::Date => { col_def.date(); } Type::Time(time_attr) => { - match time_attr.fractional { - Some(fractional) => col_def.time_len(fractional), - _ => col_def.time(), - }; + col_def.time(); } Type::DateTime(time_attr) => { - match time_attr.fractional { - Some(fractional) => col_def.date_time_len(fractional), - _ => col_def.date_time(), - }; + col_def.date_time(); } Type::Timestamp(time_attr) => { - match time_attr.fractional { - Some(fractional) => col_def.timestamp_len(fractional), - _ => col_def.timestamp(), - }; + col_def.timestamp(); } Type::Year => { // FIXME: Unresolved type mapping diff --git a/src/postgres/probe.rs b/src/postgres/probe.rs index 80de7b51..aaaae285 100644 --- a/src/postgres/probe.rs +++ b/src/postgres/probe.rs @@ -17,7 +17,7 @@ impl SchemaProbe for Postgres { Condition::all() .add( Expr::expr(Self::get_current_schema()) - .equals(Schema::Tables, TablesFields::TableSchema), + .equals((Schema::Tables, TablesFields::TableSchema)), ) .add(Expr::col(TablesFields::TableType).eq("BASE TABLE")), ) diff --git a/src/postgres/query/constraints/mod.rs b/src/postgres/query/constraints/mod.rs index f08dd4ad..7abdefaa 100644 --- a/src/postgres/query/constraints/mod.rs +++ b/src/postgres/query/constraints/mod.rs @@ -91,15 +91,15 @@ impl SchemaQueryBuilder { Condition::all() .add( Expr::tbl(Schema::TableConstraints, Tcf::ConstraintName) - .equals(Schema::CheckConstraints, Cf::ConstraintName), + .equals((Schema::CheckConstraints, Cf::ConstraintName)), ) .add( Expr::tbl(Schema::TableConstraints, Tcf::ConstraintCatalog) - .equals(Schema::CheckConstraints, Cf::ConstraintCatalog), + .equals((Schema::CheckConstraints, Cf::ConstraintCatalog)), ) .add( Expr::tbl(Schema::TableConstraints, Tcf::ConstraintSchema) - .equals(Schema::CheckConstraints, Cf::ConstraintSchema), + .equals((Schema::CheckConstraints, Cf::ConstraintSchema)), ), ) .join( @@ -108,27 +108,27 @@ impl SchemaQueryBuilder { Condition::all() .add( Expr::tbl(Schema::TableConstraints, Tcf::ConstraintName) - .equals(Schema::KeyColumnUsage, Kcuf::ConstraintName), + .equals((Schema::KeyColumnUsage, Kcuf::ConstraintName)), ) .add( Expr::tbl(Schema::TableConstraints, Tcf::ConstraintCatalog) - .equals(Schema::KeyColumnUsage, Kcuf::ConstraintCatalog), + .equals((Schema::KeyColumnUsage, Kcuf::ConstraintCatalog)), ) .add( Expr::tbl(Schema::TableConstraints, Tcf::ConstraintSchema) - .equals(Schema::KeyColumnUsage, Kcuf::ConstraintSchema), + .equals((Schema::KeyColumnUsage, Kcuf::ConstraintSchema)), ) .add( Expr::tbl(Schema::TableConstraints, Tcf::TableCatalog) - .equals(Schema::KeyColumnUsage, Kcuf::TableCatalog), + .equals((Schema::KeyColumnUsage, Kcuf::TableCatalog)), ) .add( Expr::tbl(Schema::TableConstraints, Tcf::TableSchema) - .equals(Schema::KeyColumnUsage, Kcuf::TableSchema), + .equals((Schema::KeyColumnUsage, Kcuf::TableSchema)), ) .add( Expr::tbl(Schema::TableConstraints, Tcf::TableName) - .equals(Schema::KeyColumnUsage, Kcuf::TableName), + .equals((Schema::KeyColumnUsage, Kcuf::TableName)), ), ) .join_subquery( @@ -151,12 +151,12 @@ impl SchemaQueryBuilder { .left_join( (Schema::Schema, Schema::ConstraintColumnUsage), Expr::tbl(Schema::ReferentialConstraints, RefC::ConstraintName) - .equals(Schema::ConstraintColumnUsage, Kcuf::ConstraintName), + .equals((Schema::ConstraintColumnUsage, Kcuf::ConstraintName)), ) .take(), rcsq.clone(), Expr::tbl(Schema::TableConstraints, Tcf::ConstraintName) - .equals(rcsq.clone(), RefC::ConstraintName), + .equals((rcsq.clone(), RefC::ConstraintName)), ) .and_where( Expr::col((Schema::TableConstraints, Tcf::TableSchema)).eq(schema.to_string()), diff --git a/src/postgres/query/enumeration.rs b/src/postgres/query/enumeration.rs index a1269c41..beb8be3b 100644 --- a/src/postgres/query/enumeration.rs +++ b/src/postgres/query/enumeration.rs @@ -36,7 +36,7 @@ impl SchemaQueryBuilder { .from(PgType::Table) .inner_join( PgEnum::Table, - Expr::tbl(PgEnum::Table, PgEnum::EnumTypeId).equals(PgType::Table, PgType::Oid), + Expr::tbl(PgEnum::Table, PgEnum::EnumTypeId).equals((PgType::Table, PgType::Oid)), ) .order_by((PgType::Table, PgType::TypeName), Order::Asc) .order_by((PgEnum::Table, PgEnum::EnumLabel), Order::Asc) diff --git a/src/postgres/writer/column.rs b/src/postgres/writer/column.rs index 71f9e25a..ea1d2ae7 100644 --- a/src/postgres/writer/column.rs +++ b/src/postgres/writer/column.rs @@ -54,9 +54,9 @@ impl ColumnInfo { pub fn write_col_type(&self) -> ColumnType { fn write_type(col_type: &Type) -> ColumnType { match col_type { - Type::SmallInt => ColumnType::SmallInteger(None), - Type::Integer => ColumnType::Integer(None), - Type::BigInt => ColumnType::BigInteger(None), + Type::SmallInt => ColumnType::SmallInteger, + Type::Integer => ColumnType::Integer, + Type::BigInt => ColumnType::BigInteger, Type::Decimal(num_attr) | Type::Numeric(num_attr) => { match (num_attr.precision, num_attr.scale) { (None, None) => ColumnType::Decimal(None), @@ -66,11 +66,11 @@ impl ColumnInfo { ))), } } - Type::Real => ColumnType::Float(None), - Type::DoublePrecision => ColumnType::Double(None), - Type::SmallSerial => ColumnType::SmallInteger(None), - Type::Serial => ColumnType::Integer(None), - Type::BigSerial => ColumnType::BigInteger(None), + Type::Real => ColumnType::Float, + Type::DoublePrecision => ColumnType::Double, + Type::SmallSerial => ColumnType::SmallInteger, + Type::Serial => ColumnType::Integer, + Type::BigSerial => ColumnType::BigInteger, Type::Money => ColumnType::Money(None), Type::Varchar(string_attr) => { ColumnType::String(string_attr.length.map(Into::into)) @@ -80,17 +80,11 @@ impl ColumnInfo { Type::Bytea => ColumnType::Binary(BlobSize::Blob(None)), // The SQL standard requires that writing just timestamp be equivalent to timestamp without time zone, // and PostgreSQL honors that behavior. (https://www.postgresql.org/docs/current/datatype-datetime.html) - Type::Timestamp(time_attr) => { - ColumnType::DateTime(time_attr.precision.map(Into::into)) - } - Type::TimestampWithTimeZone(time_attr) => { - ColumnType::TimestampWithTimeZone(time_attr.precision.map(Into::into)) - } + Type::Timestamp(_) => ColumnType::DateTime, + Type::TimestampWithTimeZone(_) => ColumnType::TimestampWithTimeZone, Type::Date => ColumnType::Date, - Type::Time(time_attr) => ColumnType::Time(time_attr.precision.map(Into::into)), - Type::TimeWithTimeZone(time_attr) => { - ColumnType::Time(time_attr.precision.map(Into::into)) - } + Type::Time(_) => ColumnType::Time, + Type::TimeWithTimeZone(_) => ColumnType::Time, Type::Interval(interval_attr) => { let field = match &interval_attr.field { Some(field) => PgInterval::try_from(field).ok(), @@ -146,9 +140,9 @@ impl ColumnInfo { .collect(); ColumnType::Enum { name, variants } } - Type::Array(array_def) => ColumnType::Array(SeaRc::new(Box::new(write_type( + Type::Array(array_def) => ColumnType::Array(SeaRc::new(write_type( array_def.col_type.as_ref().expect("Array type not defined"), - )))), + ))), } } write_type(&self.col_type) diff --git a/src/probe.rs b/src/probe.rs index 3a35f11f..2fa40824 100644 --- a/src/probe.rs +++ b/src/probe.rs @@ -29,7 +29,7 @@ pub trait SchemaProbe { Condition::all() .add( Expr::expr(Self::get_current_schema()) - .equals(Alias::new("columns"), Alias::new("table_schema")), + .equals((Alias::new("columns"), Alias::new("table_schema"))), ) .add(Expr::col(Alias::new("table_name")).eq(table.as_ref())) .add(Expr::col(Alias::new("column_name")).eq(column.as_ref())), From d302e04297b14d0c927f3a1b331aecbeff26b120 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 6 Dec 2022 17:00:27 +0800 Subject: [PATCH 3/5] Fixup --- Cargo.toml | 2 +- src/mysql/writer/column.rs | 6 +++--- tests/live/postgres/src/main.rs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d9bc555e..2d09b6a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ path = "src/lib.rs" futures = { version = "0.3", optional = true } sea-schema-derive = { version = "0.1.0", path = "sea-schema-derive" } sea-query = { version = "^0.28.0", git = "https://github.com/SeaQL/sea-query" } -sea-query-binder = { version = "^0.2", optional = true } +sea-query-binder = { version = "^0.2", optional = true, git = "https://github.com/SeaQL/sea-query" } serde = { version = "^1", features = ["derive"], optional = true } sqlx = { version = "^0.6", optional = true } log = { version = "^0.4", optional = true } diff --git a/src/mysql/writer/column.rs b/src/mysql/writer/column.rs index 3a578169..a6bd492e 100644 --- a/src/mysql/writer/column.rs +++ b/src/mysql/writer/column.rs @@ -102,13 +102,13 @@ impl ColumnInfo { Type::Date => { col_def.date(); } - Type::Time(time_attr) => { + Type::Time(_) => { col_def.time(); } - Type::DateTime(time_attr) => { + Type::DateTime(_) => { col_def.date_time(); } - Type::Timestamp(time_attr) => { + Type::Timestamp(_) => { col_def.timestamp(); } Type::Year => { diff --git a/tests/live/postgres/src/main.rs b/tests/live/postgres/src/main.rs index 1cbdaf8f..c0cfce78 100644 --- a/tests/live/postgres/src/main.rs +++ b/tests/live/postgres/src/main.rs @@ -211,7 +211,7 @@ fn create_order_table() -> TableCreateStatement { ) .col( ColumnDef::new(Alias::new("placed_at")) - .date_time_len(6) + .date_time() .not_null(), ) .primary_key( @@ -333,9 +333,9 @@ fn create_collection_table() -> TableCreateStatement { ) .col( ColumnDef::new(Alias::new("integers")) - .array(ColumnType::Integer(None)) + .array(ColumnType::Integer) .not_null(), ) - .col(ColumnDef::new(Alias::new("integers_opt")).array(ColumnType::Integer(None))) + .col(ColumnDef::new(Alias::new("integers_opt")).array(ColumnType::Integer)) .to_owned() } From d8c8d486bfef2af6edae177d2b652083104aa197 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 6 Dec 2022 20:36:41 +0800 Subject: [PATCH 4/5] Revert --- src/mysql/writer/column.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mysql/writer/column.rs b/src/mysql/writer/column.rs index a6bd492e..7f60ba98 100644 --- a/src/mysql/writer/column.rs +++ b/src/mysql/writer/column.rs @@ -88,7 +88,10 @@ impl ColumnInfo { col_def = self.write_num_attr(col_def, num_attr); } Type::Decimal(num_attr) => { - col_def.decimal(); + match (num_attr.maximum, num_attr.decimal) { + (Some(maximum), Some(decimal)) => col_def.decimal_len(maximum, decimal), + _ => col_def.decimal(), + }; col_def = self.write_num_attr(col_def, num_attr); } Type::Float(num_attr) => { From cc29c6fd564bf2dfecec5fff60939fd60b0a4909 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Mon, 12 Dec 2022 11:17:34 +0800 Subject: [PATCH 5/5] Bump sea-query to newly released 0.28.0 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2d09b6a9..475c4cfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,8 +36,8 @@ path = "src/lib.rs" [dependencies] futures = { version = "0.3", optional = true } sea-schema-derive = { version = "0.1.0", path = "sea-schema-derive" } -sea-query = { version = "^0.28.0", git = "https://github.com/SeaQL/sea-query" } -sea-query-binder = { version = "^0.2", optional = true, git = "https://github.com/SeaQL/sea-query" } +sea-query = { version = "^0.28.0" } +sea-query-binder = { version = "^0.3", optional = true } serde = { version = "^1", features = ["derive"], optional = true } sqlx = { version = "^0.6", optional = true } log = { version = "^0.4", optional = true }