From 183639dc8c817fbd3211a87c67bcb983db4050ed Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Mon, 23 May 2022 23:24:07 +0800 Subject: [PATCH 01/14] Migration without depending on async-std (#758) * Migration without depending on async-std runtime * Update examples * Fixup --- examples/actix3_example/migration/Cargo.toml | 6 ++++++ examples/actix_example/migration/Cargo.toml | 6 ++++++ examples/axum_example/migration/Cargo.toml | 6 ++++++ examples/graphql_example/migration/Cargo.toml | 6 ++++++ examples/jsonrpsee_example/migration/Cargo.toml | 6 ++++++ examples/poem_example/migration/Cargo.toml | 6 ++++++ examples/rocket_example/migration/Cargo.toml | 6 ++++++ examples/tonic_example/migration/Cargo.toml | 6 ++++++ sea-orm-migration/Cargo.toml | 4 +++- sea-orm-migration/src/lib.rs | 1 - sea-orm-migration/src/prelude.rs | 1 - 11 files changed, 51 insertions(+), 3 deletions(-) diff --git a/examples/actix3_example/migration/Cargo.toml b/examples/actix3_example/migration/Cargo.toml index 6a1b3c9fb..883afc811 100644 --- a/examples/actix3_example/migration/Cargo.toml +++ b/examples/actix3_example/migration/Cargo.toml @@ -10,7 +10,13 @@ path = "src/lib.rs" [dependencies] entity = { path = "../entity" } +async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] path = "../../../sea-orm-migration" # remove this line in your own project version = "^0.8.0" +features = [ + # Enable following runtime and db backend features if you want to run migration via CLI + # "runtime-async-std-native-tls", + # "sqlx-mysql", +] diff --git a/examples/actix_example/migration/Cargo.toml b/examples/actix_example/migration/Cargo.toml index 6a1b3c9fb..2655a479f 100644 --- a/examples/actix_example/migration/Cargo.toml +++ b/examples/actix_example/migration/Cargo.toml @@ -10,7 +10,13 @@ path = "src/lib.rs" [dependencies] entity = { path = "../entity" } +async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] path = "../../../sea-orm-migration" # remove this line in your own project version = "^0.8.0" +features = [ + # Enable following runtime and db backend features if you want to run migration via CLI + # "runtime-actix-native-tls", + # "sqlx-mysql", +] diff --git a/examples/axum_example/migration/Cargo.toml b/examples/axum_example/migration/Cargo.toml index 6a1b3c9fb..d22b708a3 100644 --- a/examples/axum_example/migration/Cargo.toml +++ b/examples/axum_example/migration/Cargo.toml @@ -10,7 +10,13 @@ path = "src/lib.rs" [dependencies] entity = { path = "../entity" } +async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] path = "../../../sea-orm-migration" # remove this line in your own project version = "^0.8.0" +features = [ + # Enable following runtime and db backend features if you want to run migration via CLI + # "runtime-tokio-native-tls", + # "sqlx-postgres", +] diff --git a/examples/graphql_example/migration/Cargo.toml b/examples/graphql_example/migration/Cargo.toml index b3432a967..78729b11b 100644 --- a/examples/graphql_example/migration/Cargo.toml +++ b/examples/graphql_example/migration/Cargo.toml @@ -11,7 +11,13 @@ path = "src/lib.rs" [dependencies] dotenv = "0.15.0" entity = { path = "../entity" } +async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] path = "../../../sea-orm-migration" # remove this line in your own project version = "^0.8.0" +features = [ + # Enable following runtime and db backend features if you want to run migration via CLI + # "runtime-tokio-native-tls", + # "sqlx-sqlite", +] diff --git a/examples/jsonrpsee_example/migration/Cargo.toml b/examples/jsonrpsee_example/migration/Cargo.toml index 6a1b3c9fb..82e155f9f 100644 --- a/examples/jsonrpsee_example/migration/Cargo.toml +++ b/examples/jsonrpsee_example/migration/Cargo.toml @@ -10,7 +10,13 @@ path = "src/lib.rs" [dependencies] entity = { path = "../entity" } +async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] path = "../../../sea-orm-migration" # remove this line in your own project version = "^0.8.0" +features = [ + # Enable following runtime and db backend features if you want to run migration via CLI + # "runtime-tokio-native-tls", + # "sqlx-sqlite", +] diff --git a/examples/poem_example/migration/Cargo.toml b/examples/poem_example/migration/Cargo.toml index 6a1b3c9fb..82e155f9f 100644 --- a/examples/poem_example/migration/Cargo.toml +++ b/examples/poem_example/migration/Cargo.toml @@ -10,7 +10,13 @@ path = "src/lib.rs" [dependencies] entity = { path = "../entity" } +async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] path = "../../../sea-orm-migration" # remove this line in your own project version = "^0.8.0" +features = [ + # Enable following runtime and db backend features if you want to run migration via CLI + # "runtime-tokio-native-tls", + # "sqlx-sqlite", +] diff --git a/examples/rocket_example/migration/Cargo.toml b/examples/rocket_example/migration/Cargo.toml index db8900581..8e51eed63 100644 --- a/examples/rocket_example/migration/Cargo.toml +++ b/examples/rocket_example/migration/Cargo.toml @@ -11,7 +11,13 @@ path = "src/lib.rs" [dependencies] entity = { path = "../entity" } rocket = { version = "0.5.0-rc.1" } +async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] path = "../../../sea-orm-migration" # remove this line in your own project version = "^0.8.0" +features = [ + # Enable following runtime and db backend features if you want to run migration via CLI + # "runtime-tokio-native-tls", + # "sqlx-postgres", +] diff --git a/examples/tonic_example/migration/Cargo.toml b/examples/tonic_example/migration/Cargo.toml index 6a1b3c9fb..a78ca8eb7 100644 --- a/examples/tonic_example/migration/Cargo.toml +++ b/examples/tonic_example/migration/Cargo.toml @@ -10,7 +10,13 @@ path = "src/lib.rs" [dependencies] entity = { path = "../entity" } +async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] path = "../../../sea-orm-migration" # remove this line in your own project version = "^0.8.0" +features = [ + # Enable following runtime and db backend features if you want to run migration via CLI + # "runtime-tokio-rustls", + # "sqlx-postgres", +] diff --git a/sea-orm-migration/Cargo.toml b/sea-orm-migration/Cargo.toml index e92e56b47..f1b4cb7ac 100644 --- a/sea-orm-migration/Cargo.toml +++ b/sea-orm-migration/Cargo.toml @@ -18,7 +18,6 @@ name = "sea_orm_migration" path = "src/lib.rs" [dependencies] -async-std = { version = "^1", features = ["attributes", "tokio1"] } async-trait = { version = "^0.1" } clap = { version = "^2.33" } dotenv = { version = "^0.15" } @@ -28,6 +27,9 @@ sea-schema = { version = "^0.8.0" } tracing = { version = "0.1", features = ["log"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } +[dev-dependencies] +async-std = { version = "^1", features = ["attributes", "tokio1"] } + [features] sqlx-mysql = ["sea-orm/sqlx-mysql"] sqlx-postgres = ["sea-orm/sqlx-postgres"] diff --git a/sea-orm-migration/src/lib.rs b/sea-orm-migration/src/lib.rs index c9f2dc858..b5d440fee 100644 --- a/sea-orm-migration/src/lib.rs +++ b/sea-orm-migration/src/lib.rs @@ -7,7 +7,6 @@ pub mod seaql_migrations; pub use manager::*; pub use migrator::*; -pub use async_std; pub use async_trait; pub use sea_orm; pub use sea_orm::sea_query; diff --git a/sea-orm-migration/src/prelude.rs b/sea-orm-migration/src/prelude.rs index dfce2d6ab..c80476583 100644 --- a/sea-orm-migration/src/prelude.rs +++ b/sea-orm-migration/src/prelude.rs @@ -2,7 +2,6 @@ pub use super::cli; pub use super::manager::SchemaManager; pub use super::migrator::MigratorTrait; pub use super::{MigrationName, MigrationTrait}; -pub use async_std; pub use async_trait; pub use sea_orm; pub use sea_orm::sea_query; From 8f0c01dbec3133fe69b669836d204b0f313bf88f Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Sat, 28 May 2022 17:05:48 +0800 Subject: [PATCH 02/14] sea-orm-migration 0.8.3 --- sea-orm-migration/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sea-orm-migration/Cargo.toml b/sea-orm-migration/Cargo.toml index f1b4cb7ac..45a421adb 100644 --- a/sea-orm-migration/Cargo.toml +++ b/sea-orm-migration/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "sea-orm-migration" -version = "0.8.2" +version = "0.8.3" authors = [ "Billy Chan " ] edition = "2021" description = "Migration utility for SeaORM" From 4cad2522a82b9ae4390649af1c86ea6e8cbca002 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Sat, 28 May 2022 17:09:58 +0800 Subject: [PATCH 03/14] Changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31793c8b7..4dd4a5126 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 0.9.0 - Pending + +## sea-orm-migration 0.8.3 + +* Removed `async-std` from dependency https://github.com/SeaQL/sea-orm/pull/758 + ## 0.8.0 - 2022-05-10 ### New Features From a0925cc86724e51b8a32180e636e8508ccf62e49 Mon Sep 17 00:00:00 2001 From: Aslam Ahammed Date: Wed, 1 Jun 2022 14:23:58 +0530 Subject: [PATCH 04/14] Update COMMUNITY.md (#776) Add `actix-react-starter-template` in Built with SeaORM to the Open Source Projects section. Reference: https://github.com/aslamplr/actix-react-starter-template/issues/1 --- COMMUNITY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMMUNITY.md b/COMMUNITY.md index 4943ccc4e..f31875920 100644 --- a/COMMUNITY.md +++ b/COMMUNITY.md @@ -36,3 +36,4 @@ If you have built an app using SeaORM and want to showcase it, feel free to open - [Quasar](https://github.com/Technik97/Quasar) | Rust REST API using Actix-Web, SeaOrm and Postgres with Svelte Typescript Frontend - [snmp-sim-rust](https://github.com/sonalake/snmp-sim-rust) | SNMP Simulator - [template_flow](https://github.com/hilary888/template_flow) | An experiment exploring replacing placeholders in pre-prepared templates with their actual values +- [actix-react-starter-template](https://github.com/aslamplr/actix-react-starter-template) | Actix web + SeaORM + React + Redux + Redux Saga project starter template From 1ea8b457bf9f66988a45696c15933a6a756854ed Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 2 Jun 2022 16:34:59 +0800 Subject: [PATCH 05/14] Bump CI actions/cache to v3 (#784) --- .github/workflows/rust.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index cd506c06f..c4a4821a3 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -137,7 +137,7 @@ jobs: toolchain: stable override: true - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: | ~/.cargo/registry @@ -176,7 +176,7 @@ jobs: toolchain: stable override: true - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: | ~/.cargo/registry @@ -215,7 +215,7 @@ jobs: toolchain: stable override: true - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: | ~/.cargo/registry @@ -380,7 +380,7 @@ jobs: toolchain: stable override: true - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: | ~/.cargo/registry @@ -449,7 +449,7 @@ jobs: toolchain: stable override: true - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: | ~/.cargo/registry @@ -518,7 +518,7 @@ jobs: toolchain: stable override: true - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: | ~/.cargo/registry @@ -576,7 +576,7 @@ jobs: toolchain: stable override: true - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: | ~/.cargo/registry From e4f198fbc4168a8144e45361eb1aabb48ba2292a Mon Sep 17 00:00:00 2001 From: Tricked <72335827+Tricked-dev@users.noreply.github.com> Date: Sun, 12 Jun 2022 14:20:28 +0200 Subject: [PATCH 06/14] Create .gitattributes (#712) --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..3d4118bfd --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.html.tera linguist-language=HTML From 0ce8ee6a31e5d3bd44f79d82109d5adaa786e3b4 Mon Sep 17 00:00:00 2001 From: kyoto7250 <50972773+kyoto7250@users.noreply.github.com> Date: Sun, 12 Jun 2022 21:30:49 +0900 Subject: [PATCH 07/14] feat(sea-orm-cli): output log about generated file name. (#735) * feat(sea-orm-cli): output lof about generated file name. https://github.com/SeaQL/sea-orm/issues/722 * include column names in info * cargo fmt * Update sea-orm-cli/src/commands.rs Avoid multiple initializations Co-authored-by: Billy Chan * show info per column * refactor: use write! macro * Refactoring Co-authored-by: Billy Chan --- sea-orm-cli/src/commands.rs | 12 ++++++ sea-orm-codegen/Cargo.toml | 1 + sea-orm-codegen/src/entity/column.rs | 64 ++++++++++++++++++++++++++++ sea-orm-codegen/src/entity/writer.rs | 15 ++++++- 4 files changed, 91 insertions(+), 1 deletion(-) diff --git a/sea-orm-cli/src/commands.rs b/sea-orm-cli/src/commands.rs index dadb3ad2f..04a3d3b0b 100644 --- a/sea-orm-cli/src/commands.rs +++ b/sea-orm-cli/src/commands.rs @@ -3,6 +3,7 @@ use clap::ArgMatches; use regex::Regex; use sea_orm_codegen::{EntityTransformer, OutputFile, WithSerde}; use std::{error::Error, fmt::Display, fs, io::Write, path::Path, process::Command, str::FromStr}; +use tracing_subscriber::{prelude::*, EnvFilter}; use url::Url; pub async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box> { @@ -21,6 +22,17 @@ pub async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box String { + let mut info = String::new(); + let type_info = self.get_rs_type().to_string().replace(' ', ""); + let col_info = self.col_info(); + write!( + &mut info, + "Column `{}`: {}{}", + self.name, type_info, col_info + ) + .unwrap(); + info + } + + fn col_info(&self) -> String { + let mut info = String::new(); + if self.auto_increment { + write!(&mut info, ", auto_increment").unwrap(); + } + if self.not_null { + write!(&mut info, ", not_null").unwrap(); + } + if self.unique { + write!(&mut info, ", unique").unwrap(); + } + info + } } impl From for Column { @@ -361,6 +389,42 @@ mod tests { } } + #[test] + fn test_get_info() { + let column: Column = ColumnDef::new(Alias::new("id")).string().to_owned().into(); + assert_eq!(column.get_info().as_str(), "Column `id`: Option"); + + let column: Column = ColumnDef::new(Alias::new("id")) + .string() + .not_null() + .to_owned() + .into(); + assert_eq!(column.get_info().as_str(), "Column `id`: String, not_null"); + + let column: Column = ColumnDef::new(Alias::new("id")) + .string() + .not_null() + .unique_key() + .to_owned() + .into(); + assert_eq!( + column.get_info().as_str(), + "Column `id`: String, not_null, unique" + ); + + let column: Column = ColumnDef::new(Alias::new("id")) + .string() + .not_null() + .unique_key() + .auto_increment() + .to_owned() + .into(); + assert_eq!( + column.get_info().as_str(), + "Column `id`: String, auto_increment, not_null, unique" + ); + } + #[test] fn test_from_column_def() { let column: Column = ColumnDef::new(Alias::new("id")).string().to_owned().into(); diff --git a/sea-orm-codegen/src/entity/writer.rs b/sea-orm-codegen/src/entity/writer.rs index 88d72ef32..922f4bced 100644 --- a/sea-orm-codegen/src/entity/writer.rs +++ b/sea-orm-codegen/src/entity/writer.rs @@ -4,6 +4,7 @@ use proc_macro2::TokenStream; use quote::{format_ident, quote}; use std::{collections::HashMap, str::FromStr}; use syn::{punctuated::Punctuated, token::Comma}; +use tracing::info; #[derive(Clone, Debug)] pub struct EntityWriter { @@ -94,6 +95,18 @@ impl EntityWriter { self.entities .iter() .map(|entity| { + let entity_file = format!("{}.rs", entity.get_table_name_snake_case()); + let column_info = entity + .columns + .iter() + .map(|column| column.get_info()) + .collect::>(); + + info!("Generating {}", entity_file); + for info in column_info.iter() { + info!(" > {}", info); + } + let mut lines = Vec::new(); Self::write_doc_comment(&mut lines); let code_blocks = if expanded_format { @@ -103,7 +116,7 @@ impl EntityWriter { }; Self::write(&mut lines, code_blocks); OutputFile { - name: format!("{}.rs", entity.get_table_name_snake_case()), + name: entity_file, content: lines.join("\n\n"), } }) From 5cf4d6022b62513e59edace4ff21fb6f4066d85e Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Sun, 12 Jun 2022 22:23:30 +0800 Subject: [PATCH 08/14] Vector of string save as serialized format in db (#783) --- tests/common/features/json_vec.rs | 51 +++++++++++++++++++++++++++++++ tests/common/features/mod.rs | 2 ++ tests/common/features/schema.rs | 21 +++++++++++++ tests/json_vec_tests.rs | 47 ++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 tests/common/features/json_vec.rs create mode 100644 tests/json_vec_tests.rs diff --git a/tests/common/features/json_vec.rs b/tests/common/features/json_vec.rs new file mode 100644 index 000000000..7b347c7b3 --- /dev/null +++ b/tests/common/features/json_vec.rs @@ -0,0 +1,51 @@ +use sea_orm::entity::prelude::*; +use sea_orm::{TryGetError, TryGetable}; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "json_vec")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + pub str_vec: StringVec, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct StringVec(pub Vec); + +impl From for Value { + fn from(source: StringVec) -> Self { + Value::String(serde_json::to_string(&source).ok().map(|s| Box::new(s))) + } +} + +impl TryGetable for StringVec { + fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { + let json_str: String = res.try_get(pre, col).map_err(TryGetError::DbErr)?; + serde_json::from_str(&json_str).map_err(|e| TryGetError::DbErr(DbErr::Json(e.to_string()))) + } +} + +impl sea_query::ValueType for StringVec { + fn try_from(v: Value) -> Result { + match v { + Value::String(Some(x)) => Ok(StringVec( + serde_json::from_str(&x).map_err(|_| sea_query::ValueTypeErr)?, + )), + _ => Err(sea_query::ValueTypeErr), + } + } + + fn type_name() -> String { + stringify!(StringVec).to_owned() + } + + fn column_type() -> sea_query::ColumnType { + sea_query::ColumnType::String(None) + } +} diff --git a/tests/common/features/mod.rs b/tests/common/features/mod.rs index 4dad7956a..fc9ac047e 100644 --- a/tests/common/features/mod.rs +++ b/tests/common/features/mod.rs @@ -3,6 +3,7 @@ pub mod active_enum_child; pub mod applog; pub mod byte_primary_key; pub mod insert_default; +pub mod json_vec; pub mod metadata; pub mod repository; pub mod satellite; @@ -16,6 +17,7 @@ pub use active_enum_child::Entity as ActiveEnumChild; pub use applog::Entity as Applog; pub use byte_primary_key::Entity as BytePrimaryKey; pub use insert_default::Entity as InsertDefault; +pub use json_vec::Entity as JsonVec; pub use metadata::Entity as Metadata; pub use repository::Entity as Repository; pub use satellite::Entity as Satellite; diff --git a/tests/common/features/schema.rs b/tests/common/features/schema.rs index 68f2f2812..10fd038c3 100644 --- a/tests/common/features/schema.rs +++ b/tests/common/features/schema.rs @@ -18,6 +18,7 @@ pub async fn create_tables(db: &DatabaseConnection) -> Result<(), DbErr> { create_byte_primary_key_table(db).await?; create_satellites_table(db).await?; create_transaction_log_table(db).await?; + create_json_vec_table(db).await?; let create_enum_stmts = match db_backend { DbBackend::MySql | DbBackend::Sqlite => Vec::new(), @@ -286,3 +287,23 @@ pub async fn create_insert_default_table(db: &DbConn) -> Result Result { + let create_table_stmt = sea_query::Table::create() + .table(json_vec::Entity.table_ref()) + .col( + ColumnDef::new(json_vec::Column::Id) + .integer() + .not_null() + .auto_increment() + .primary_key(), + ) + .col( + ColumnDef::new(json_vec::Column::StrVec) + .string() + .not_null(), + ) + .to_owned(); + + create_table(db, &create_table_stmt, JsonVec).await +} diff --git a/tests/json_vec_tests.rs b/tests/json_vec_tests.rs new file mode 100644 index 000000000..de8c819bc --- /dev/null +++ b/tests/json_vec_tests.rs @@ -0,0 +1,47 @@ +pub mod common; + +pub use common::{features::*, setup::*, TestContext}; +use pretty_assertions::assert_eq; +use sea_orm::{entity::prelude::*, entity::*, DatabaseConnection}; + +#[sea_orm_macros::test] +#[cfg(any( + feature = "sqlx-mysql", + feature = "sqlx-sqlite", + feature = "sqlx-postgres" +))] +async fn main() -> Result<(), DbErr> { + let ctx = TestContext::new("json_vec_tests").await; + create_tables(&ctx.db).await?; + insert_json_vec(&ctx.db).await?; + ctx.delete().await; + + Ok(()) +} + +pub async fn insert_json_vec(db: &DatabaseConnection) -> Result<(), DbErr> { + let json_vec = json_vec::Model { + id: 1, + str_vec: json_vec::StringVec(vec![ + "1".to_string(), + "2".to_string(), + "3".to_string(), + ]) + }; + + let result = json_vec.clone().into_active_model().insert(db).await?; + + assert_eq!(result, json_vec); + + let model = json_vec::Entity::find() + .filter(json_vec::Column::Id.eq(json_vec.id)) + .one(db) + .await?; + + assert_eq!( + model, + Some(json_vec) + ); + + Ok(()) +} From 9b41f1c1b17917626d204b39da3f7411a4855fde Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Sun, 12 Jun 2022 22:25:32 +0800 Subject: [PATCH 09/14] Migration shouldn't depends on symbol provided by entity crate (#785) * Migration shouldn't depends on symbol provided by entity crate * Add docs --- examples/actix3_example/migration/Cargo.toml | 1 - .../src/m20220120_000001_create_post_table.rs | 25 ++++++-- examples/actix_example/migration/Cargo.toml | 1 - .../src/m20220120_000001_create_post_table.rs | 25 ++++++-- examples/axum_example/migration/Cargo.toml | 1 - .../src/m20220120_000001_create_post_table.rs | 25 ++++++-- examples/graphql_example/migration/Cargo.toml | 1 - .../src/m20220101_000001_create_table.rs | 63 ++++++++++--------- .../jsonrpsee_example/migration/Cargo.toml | 1 - .../src/m20220120_000001_create_post_table.rs | 25 ++++++-- examples/poem_example/migration/Cargo.toml | 1 - .../src/m20220120_000001_create_post_table.rs | 25 ++++++-- examples/rocket_example/migration/Cargo.toml | 1 - .../src/m20220120_000001_create_post_table.rs | 25 ++++++-- examples/tonic_example/migration/Cargo.toml | 1 - .../src/m20220120_000001_create_post_table.rs | 25 ++++++-- sea-orm-cli/template/migration/_Cargo.toml | 9 ++- .../src/m20220101_000001_create_table.rs | 42 ++++++++++++- .../m20220118_000001_create_cake_table.rs | 6 ++ .../m20220118_000002_create_fruit_table.rs | 6 ++ 20 files changed, 227 insertions(+), 82 deletions(-) diff --git a/examples/actix3_example/migration/Cargo.toml b/examples/actix3_example/migration/Cargo.toml index 883afc811..2ba5e0a1a 100644 --- a/examples/actix3_example/migration/Cargo.toml +++ b/examples/actix3_example/migration/Cargo.toml @@ -9,7 +9,6 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] diff --git a/examples/actix3_example/migration/src/m20220120_000001_create_post_table.rs b/examples/actix3_example/migration/src/m20220120_000001_create_post_table.rs index 097c22670..034cd9f6e 100644 --- a/examples/actix3_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/actix3_example/migration/src/m20220120_000001_create_post_table.rs @@ -1,4 +1,3 @@ -use entity::post::*; use sea_orm_migration::prelude::*; pub struct Migration; @@ -15,17 +14,17 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Entity) + .table(Post::Table) .if_not_exists() .col( - ColumnDef::new(Column::Id) + ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) - .col(ColumnDef::new(Column::Title).string().not_null()) - .col(ColumnDef::new(Column::Text).string().not_null()) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) .to_owned(), ) .await @@ -33,7 +32,21 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Entity).to_owned()) + .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/examples/actix_example/migration/Cargo.toml b/examples/actix_example/migration/Cargo.toml index 2655a479f..c113ac97b 100644 --- a/examples/actix_example/migration/Cargo.toml +++ b/examples/actix_example/migration/Cargo.toml @@ -9,7 +9,6 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] diff --git a/examples/actix_example/migration/src/m20220120_000001_create_post_table.rs b/examples/actix_example/migration/src/m20220120_000001_create_post_table.rs index 097c22670..034cd9f6e 100644 --- a/examples/actix_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/actix_example/migration/src/m20220120_000001_create_post_table.rs @@ -1,4 +1,3 @@ -use entity::post::*; use sea_orm_migration::prelude::*; pub struct Migration; @@ -15,17 +14,17 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Entity) + .table(Post::Table) .if_not_exists() .col( - ColumnDef::new(Column::Id) + ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) - .col(ColumnDef::new(Column::Title).string().not_null()) - .col(ColumnDef::new(Column::Text).string().not_null()) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) .to_owned(), ) .await @@ -33,7 +32,21 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Entity).to_owned()) + .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/examples/axum_example/migration/Cargo.toml b/examples/axum_example/migration/Cargo.toml index d22b708a3..d816bce11 100644 --- a/examples/axum_example/migration/Cargo.toml +++ b/examples/axum_example/migration/Cargo.toml @@ -9,7 +9,6 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] diff --git a/examples/axum_example/migration/src/m20220120_000001_create_post_table.rs b/examples/axum_example/migration/src/m20220120_000001_create_post_table.rs index 097c22670..034cd9f6e 100644 --- a/examples/axum_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/axum_example/migration/src/m20220120_000001_create_post_table.rs @@ -1,4 +1,3 @@ -use entity::post::*; use sea_orm_migration::prelude::*; pub struct Migration; @@ -15,17 +14,17 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Entity) + .table(Post::Table) .if_not_exists() .col( - ColumnDef::new(Column::Id) + ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) - .col(ColumnDef::new(Column::Title).string().not_null()) - .col(ColumnDef::new(Column::Text).string().not_null()) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) .to_owned(), ) .await @@ -33,7 +32,21 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Entity).to_owned()) + .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/examples/graphql_example/migration/Cargo.toml b/examples/graphql_example/migration/Cargo.toml index 78729b11b..8101cb8bd 100644 --- a/examples/graphql_example/migration/Cargo.toml +++ b/examples/graphql_example/migration/Cargo.toml @@ -10,7 +10,6 @@ path = "src/lib.rs" [dependencies] dotenv = "0.15.0" -entity = { path = "../entity" } async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] diff --git a/examples/graphql_example/migration/src/m20220101_000001_create_table.rs b/examples/graphql_example/migration/src/m20220101_000001_create_table.rs index 9a69fe7a6..2bb20e11d 100644 --- a/examples/graphql_example/migration/src/m20220101_000001_create_table.rs +++ b/examples/graphql_example/migration/src/m20220101_000001_create_table.rs @@ -1,22 +1,7 @@ -use entity::note; -use sea_orm::{DbBackend, EntityTrait, Schema}; use sea_orm_migration::prelude::*; pub struct Migration; -fn get_seaorm_create_stmt(e: E) -> TableCreateStatement { - let schema = Schema::new(DbBackend::Sqlite); - - schema - .create_table_from_entity(e) - .if_not_exists() - .to_owned() -} - -fn get_seaorm_drop_stmt(e: E) -> TableDropStatement { - Table::drop().table(e).if_exists().to_owned() -} - impl MigrationName for Migration { fn name(&self) -> &str { "m20220101_000001_create_table" @@ -26,22 +11,42 @@ impl MigrationName for Migration { #[async_trait::async_trait] impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - let stmts = vec![get_seaorm_create_stmt(note::Entity)]; - - for stmt in stmts { - manager.create_table(stmt.to_owned()).await?; - } - - Ok(()) + manager + .create_table( + Table::create() + .table(Notes::Table) + .if_not_exists() + .col( + ColumnDef::new(Notes::Id) + .integer() + .not_null() + .auto_increment() + .primary_key(), + ) + .col(ColumnDef::new(Notes::Title).string().not_null()) + .col(ColumnDef::new(Notes::Text).string().not_null()) + .to_owned(), + ) + .await } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { - let stmts = vec![get_seaorm_drop_stmt(note::Entity)]; - - for stmt in stmts { - manager.drop_table(stmt.to_owned()).await?; - } - - Ok(()) + manager + .drop_table(Table::drop().table(Notes::Table).to_owned()) + .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Notes { + Table, + Id, + Title, + Text, +} diff --git a/examples/jsonrpsee_example/migration/Cargo.toml b/examples/jsonrpsee_example/migration/Cargo.toml index 82e155f9f..d860e7e31 100644 --- a/examples/jsonrpsee_example/migration/Cargo.toml +++ b/examples/jsonrpsee_example/migration/Cargo.toml @@ -9,7 +9,6 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] diff --git a/examples/jsonrpsee_example/migration/src/m20220120_000001_create_post_table.rs b/examples/jsonrpsee_example/migration/src/m20220120_000001_create_post_table.rs index 097c22670..034cd9f6e 100644 --- a/examples/jsonrpsee_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/jsonrpsee_example/migration/src/m20220120_000001_create_post_table.rs @@ -1,4 +1,3 @@ -use entity::post::*; use sea_orm_migration::prelude::*; pub struct Migration; @@ -15,17 +14,17 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Entity) + .table(Post::Table) .if_not_exists() .col( - ColumnDef::new(Column::Id) + ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) - .col(ColumnDef::new(Column::Title).string().not_null()) - .col(ColumnDef::new(Column::Text).string().not_null()) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) .to_owned(), ) .await @@ -33,7 +32,21 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Entity).to_owned()) + .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/examples/poem_example/migration/Cargo.toml b/examples/poem_example/migration/Cargo.toml index 82e155f9f..d860e7e31 100644 --- a/examples/poem_example/migration/Cargo.toml +++ b/examples/poem_example/migration/Cargo.toml @@ -9,7 +9,6 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] diff --git a/examples/poem_example/migration/src/m20220120_000001_create_post_table.rs b/examples/poem_example/migration/src/m20220120_000001_create_post_table.rs index 097c22670..034cd9f6e 100644 --- a/examples/poem_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/poem_example/migration/src/m20220120_000001_create_post_table.rs @@ -1,4 +1,3 @@ -use entity::post::*; use sea_orm_migration::prelude::*; pub struct Migration; @@ -15,17 +14,17 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Entity) + .table(Post::Table) .if_not_exists() .col( - ColumnDef::new(Column::Id) + ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) - .col(ColumnDef::new(Column::Title).string().not_null()) - .col(ColumnDef::new(Column::Text).string().not_null()) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) .to_owned(), ) .await @@ -33,7 +32,21 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Entity).to_owned()) + .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/examples/rocket_example/migration/Cargo.toml b/examples/rocket_example/migration/Cargo.toml index 8e51eed63..757b5f299 100644 --- a/examples/rocket_example/migration/Cargo.toml +++ b/examples/rocket_example/migration/Cargo.toml @@ -9,7 +9,6 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } rocket = { version = "0.5.0-rc.1" } async-std = { version = "^1", features = ["attributes", "tokio1"] } diff --git a/examples/rocket_example/migration/src/m20220120_000001_create_post_table.rs b/examples/rocket_example/migration/src/m20220120_000001_create_post_table.rs index 097c22670..034cd9f6e 100644 --- a/examples/rocket_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/rocket_example/migration/src/m20220120_000001_create_post_table.rs @@ -1,4 +1,3 @@ -use entity::post::*; use sea_orm_migration::prelude::*; pub struct Migration; @@ -15,17 +14,17 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Entity) + .table(Post::Table) .if_not_exists() .col( - ColumnDef::new(Column::Id) + ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) - .col(ColumnDef::new(Column::Title).string().not_null()) - .col(ColumnDef::new(Column::Text).string().not_null()) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) .to_owned(), ) .await @@ -33,7 +32,21 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Entity).to_owned()) + .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/examples/tonic_example/migration/Cargo.toml b/examples/tonic_example/migration/Cargo.toml index a78ca8eb7..b3b55c135 100644 --- a/examples/tonic_example/migration/Cargo.toml +++ b/examples/tonic_example/migration/Cargo.toml @@ -9,7 +9,6 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] diff --git a/examples/tonic_example/migration/src/m20220120_000001_create_post_table.rs b/examples/tonic_example/migration/src/m20220120_000001_create_post_table.rs index 097c22670..034cd9f6e 100644 --- a/examples/tonic_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/tonic_example/migration/src/m20220120_000001_create_post_table.rs @@ -1,4 +1,3 @@ -use entity::post::*; use sea_orm_migration::prelude::*; pub struct Migration; @@ -15,17 +14,17 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Entity) + .table(Post::Table) .if_not_exists() .col( - ColumnDef::new(Column::Id) + ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) - .col(ColumnDef::new(Column::Title).string().not_null()) - .col(ColumnDef::new(Column::Text).string().not_null()) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) .to_owned(), ) .await @@ -33,7 +32,21 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Entity).to_owned()) + .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/sea-orm-cli/template/migration/_Cargo.toml b/sea-orm-cli/template/migration/_Cargo.toml index 70817c3c3..61a6f6b52 100644 --- a/sea-orm-cli/template/migration/_Cargo.toml +++ b/sea-orm-cli/template/migration/_Cargo.toml @@ -9,7 +9,14 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } +async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] version = "" +features = [ + # Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI. + # View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime. + # e.g. + # "runtime-tokio-rustls", # `ASYNC_RUNTIME` featrure + # "sqlx-postgres", # `DATABASE_DRIVER` feature +] diff --git a/sea-orm-cli/template/migration/src/m20220101_000001_create_table.rs b/sea-orm-cli/template/migration/src/m20220101_000001_create_table.rs index b4dc891e2..c114f9a84 100644 --- a/sea-orm-cli/template/migration/src/m20220101_000001_create_table.rs +++ b/sea-orm-cli/template/migration/src/m20220101_000001_create_table.rs @@ -11,10 +11,48 @@ impl MigrationName for Migration { #[async_trait::async_trait] impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - todo!() + // Replace the sample below with your own migration scripts + todo!(); + + manager + .create_table( + Table::create() + .table(Post::Table) + .if_not_exists() + .col( + ColumnDef::new(Post::Id) + .integer() + .not_null() + .auto_increment() + .primary_key(), + ) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) + .to_owned(), + ) + .await } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { - todo!() + // Replace the sample below with your own migration scripts + todo!(); + + manager + .drop_table(Table::drop().table(Post::Table).to_owned()) + .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/sea-orm-migration/tests/migrator/m20220118_000001_create_cake_table.rs b/sea-orm-migration/tests/migrator/m20220118_000001_create_cake_table.rs index bc70ba3b4..044fa264e 100644 --- a/sea-orm-migration/tests/migrator/m20220118_000001_create_cake_table.rs +++ b/sea-orm-migration/tests/migrator/m20220118_000001_create_cake_table.rs @@ -35,6 +35,12 @@ impl MigrationTrait for Migration { } } +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] pub enum Cake { Table, diff --git a/sea-orm-migration/tests/migrator/m20220118_000002_create_fruit_table.rs b/sea-orm-migration/tests/migrator/m20220118_000002_create_fruit_table.rs index 51c21321f..65a0857a4 100644 --- a/sea-orm-migration/tests/migrator/m20220118_000002_create_fruit_table.rs +++ b/sea-orm-migration/tests/migrator/m20220118_000002_create_fruit_table.rs @@ -54,6 +54,12 @@ impl MigrationTrait for Migration { } } +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] pub enum Fruit { Table, From 086b0f16450e6a623c79305835b2fb10164788de Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Sun, 12 Jun 2022 22:27:12 +0800 Subject: [PATCH 10/14] Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dd4a5126..8fdaf46cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## 0.9.0 - Pending +* Improve sea-orm-cli logging (#735) + ## sea-orm-migration 0.8.3 * Removed `async-std` from dependency https://github.com/SeaQL/sea-orm/pull/758 From 4301383b409737f85378a1da8a4c122478248ba0 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Sun, 12 Jun 2022 22:30:34 +0800 Subject: [PATCH 11/14] Tweaks --- .../migration/src/m20220120_000001_create_post_table.rs | 5 ----- .../migration/src/m20220120_000001_create_post_table.rs | 5 ----- .../migration/src/m20220120_000001_create_post_table.rs | 5 ----- .../migration/src/m20220101_000001_create_table.rs | 5 ----- .../migration/src/m20220120_000001_create_post_table.rs | 5 ----- .../migration/src/m20220120_000001_create_post_table.rs | 5 ----- .../migration/src/m20220120_000001_create_post_table.rs | 5 ----- .../migration/src/m20220120_000001_create_post_table.rs | 5 ----- .../template/migration/src/m20220101_000001_create_table.rs | 5 ----- .../tests/migrator/m20220118_000001_create_cake_table.rs | 5 ----- .../tests/migrator/m20220118_000002_create_fruit_table.rs | 5 ----- 11 files changed, 55 deletions(-) diff --git a/examples/actix3_example/migration/src/m20220120_000001_create_post_table.rs b/examples/actix3_example/migration/src/m20220120_000001_create_post_table.rs index 034cd9f6e..e544701e0 100644 --- a/examples/actix3_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/actix3_example/migration/src/m20220120_000001_create_post_table.rs @@ -37,11 +37,6 @@ impl MigrationTrait for Migration { } } -/// `Iden` is a trait for identifiers used in any query statement. -/// -/// Commonly implemented by Enum where each Enum represents a table found in a database, -/// and its variants include table name and column name. -/// /// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] enum Post { diff --git a/examples/actix_example/migration/src/m20220120_000001_create_post_table.rs b/examples/actix_example/migration/src/m20220120_000001_create_post_table.rs index 034cd9f6e..e544701e0 100644 --- a/examples/actix_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/actix_example/migration/src/m20220120_000001_create_post_table.rs @@ -37,11 +37,6 @@ impl MigrationTrait for Migration { } } -/// `Iden` is a trait for identifiers used in any query statement. -/// -/// Commonly implemented by Enum where each Enum represents a table found in a database, -/// and its variants include table name and column name. -/// /// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] enum Post { diff --git a/examples/axum_example/migration/src/m20220120_000001_create_post_table.rs b/examples/axum_example/migration/src/m20220120_000001_create_post_table.rs index 034cd9f6e..e544701e0 100644 --- a/examples/axum_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/axum_example/migration/src/m20220120_000001_create_post_table.rs @@ -37,11 +37,6 @@ impl MigrationTrait for Migration { } } -/// `Iden` is a trait for identifiers used in any query statement. -/// -/// Commonly implemented by Enum where each Enum represents a table found in a database, -/// and its variants include table name and column name. -/// /// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] enum Post { diff --git a/examples/graphql_example/migration/src/m20220101_000001_create_table.rs b/examples/graphql_example/migration/src/m20220101_000001_create_table.rs index 2bb20e11d..631cafbfd 100644 --- a/examples/graphql_example/migration/src/m20220101_000001_create_table.rs +++ b/examples/graphql_example/migration/src/m20220101_000001_create_table.rs @@ -37,11 +37,6 @@ impl MigrationTrait for Migration { } } -/// `Iden` is a trait for identifiers used in any query statement. -/// -/// Commonly implemented by Enum where each Enum represents a table found in a database, -/// and its variants include table name and column name. -/// /// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] enum Notes { diff --git a/examples/jsonrpsee_example/migration/src/m20220120_000001_create_post_table.rs b/examples/jsonrpsee_example/migration/src/m20220120_000001_create_post_table.rs index 034cd9f6e..e544701e0 100644 --- a/examples/jsonrpsee_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/jsonrpsee_example/migration/src/m20220120_000001_create_post_table.rs @@ -37,11 +37,6 @@ impl MigrationTrait for Migration { } } -/// `Iden` is a trait for identifiers used in any query statement. -/// -/// Commonly implemented by Enum where each Enum represents a table found in a database, -/// and its variants include table name and column name. -/// /// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] enum Post { diff --git a/examples/poem_example/migration/src/m20220120_000001_create_post_table.rs b/examples/poem_example/migration/src/m20220120_000001_create_post_table.rs index 034cd9f6e..e544701e0 100644 --- a/examples/poem_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/poem_example/migration/src/m20220120_000001_create_post_table.rs @@ -37,11 +37,6 @@ impl MigrationTrait for Migration { } } -/// `Iden` is a trait for identifiers used in any query statement. -/// -/// Commonly implemented by Enum where each Enum represents a table found in a database, -/// and its variants include table name and column name. -/// /// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] enum Post { diff --git a/examples/rocket_example/migration/src/m20220120_000001_create_post_table.rs b/examples/rocket_example/migration/src/m20220120_000001_create_post_table.rs index 034cd9f6e..e544701e0 100644 --- a/examples/rocket_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/rocket_example/migration/src/m20220120_000001_create_post_table.rs @@ -37,11 +37,6 @@ impl MigrationTrait for Migration { } } -/// `Iden` is a trait for identifiers used in any query statement. -/// -/// Commonly implemented by Enum where each Enum represents a table found in a database, -/// and its variants include table name and column name. -/// /// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] enum Post { diff --git a/examples/tonic_example/migration/src/m20220120_000001_create_post_table.rs b/examples/tonic_example/migration/src/m20220120_000001_create_post_table.rs index 034cd9f6e..e544701e0 100644 --- a/examples/tonic_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/tonic_example/migration/src/m20220120_000001_create_post_table.rs @@ -37,11 +37,6 @@ impl MigrationTrait for Migration { } } -/// `Iden` is a trait for identifiers used in any query statement. -/// -/// Commonly implemented by Enum where each Enum represents a table found in a database, -/// and its variants include table name and column name. -/// /// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] enum Post { diff --git a/sea-orm-cli/template/migration/src/m20220101_000001_create_table.rs b/sea-orm-cli/template/migration/src/m20220101_000001_create_table.rs index c114f9a84..12a3bec14 100644 --- a/sea-orm-cli/template/migration/src/m20220101_000001_create_table.rs +++ b/sea-orm-cli/template/migration/src/m20220101_000001_create_table.rs @@ -43,11 +43,6 @@ impl MigrationTrait for Migration { } } -/// `Iden` is a trait for identifiers used in any query statement. -/// -/// Commonly implemented by Enum where each Enum represents a table found in a database, -/// and its variants include table name and column name. -/// /// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] enum Post { diff --git a/sea-orm-migration/tests/migrator/m20220118_000001_create_cake_table.rs b/sea-orm-migration/tests/migrator/m20220118_000001_create_cake_table.rs index 044fa264e..b1b3d9cf7 100644 --- a/sea-orm-migration/tests/migrator/m20220118_000001_create_cake_table.rs +++ b/sea-orm-migration/tests/migrator/m20220118_000001_create_cake_table.rs @@ -35,11 +35,6 @@ impl MigrationTrait for Migration { } } -/// `Iden` is a trait for identifiers used in any query statement. -/// -/// Commonly implemented by Enum where each Enum represents a table found in a database, -/// and its variants include table name and column name. -/// /// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] pub enum Cake { diff --git a/sea-orm-migration/tests/migrator/m20220118_000002_create_fruit_table.rs b/sea-orm-migration/tests/migrator/m20220118_000002_create_fruit_table.rs index 65a0857a4..6ffd0a2c6 100644 --- a/sea-orm-migration/tests/migrator/m20220118_000002_create_fruit_table.rs +++ b/sea-orm-migration/tests/migrator/m20220118_000002_create_fruit_table.rs @@ -54,11 +54,6 @@ impl MigrationTrait for Migration { } } -/// `Iden` is a trait for identifiers used in any query statement. -/// -/// Commonly implemented by Enum where each Enum represents a table found in a database, -/// and its variants include table name and column name. -/// /// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] pub enum Fruit { From 73af72200ae39b9489862422f362f587dc3c34ea Mon Sep 17 00:00:00 2001 From: cache-missing Date: Mon, 13 Jun 2022 08:41:41 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=E2=9C=A8=20feat(sqlite3):=20support=20se?= =?UTF-8?q?t=20sqlcipher=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/mod.rs | 15 ++++++++++++++- src/driver/sqlx_sqlite.rs | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/database/mod.rs b/src/database/mod.rs index ea00f7426..879f7a371 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -13,6 +13,7 @@ pub use db_connection::*; #[cfg(feature = "mock")] pub use mock::*; pub use statement::*; +use std::borrow::Cow; pub use stream::*; use tracing::instrument; pub use transaction::*; @@ -24,7 +25,7 @@ use crate::DbErr; pub struct Database; /// Defines the configuration options of a database -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct ConnectOptions { /// The URI of the database pub(crate) url: String, @@ -41,6 +42,8 @@ pub struct ConnectOptions { pub(crate) max_lifetime: Option, /// Enable SQLx statement logging pub(crate) sqlx_logging: bool, + /// set sqlcipher key + pub(crate) sqlcipher_key: Option>, } impl Database { @@ -104,6 +107,7 @@ impl ConnectOptions { idle_timeout: None, max_lifetime: None, sqlx_logging: true, + sqlcipher_key: None, } } @@ -206,4 +210,13 @@ impl ConnectOptions { pub fn get_sqlx_logging(&self) -> bool { self.sqlx_logging } + + /// set key for sqlcipher + pub fn sqlcipher_key(&mut self, value: T) -> &mut Self + where + T: Into>, + { + self.sqlcipher_key = Some(value.into()); + self + } } diff --git a/src/driver/sqlx_sqlite.rs b/src/driver/sqlx_sqlite.rs index 9940b7fac..ae3edad24 100644 --- a/src/driver/sqlx_sqlite.rs +++ b/src/driver/sqlx_sqlite.rs @@ -47,6 +47,9 @@ impl SqlxSqliteConnector { .url .parse::() .map_err(|e| DbErr::Conn(e.to_string()))?; + if options.sqlcipher_key.is_some() { + opt = opt.pragma("key", options.sqlcipher_key.clone().unwrap()); + } if !options.sqlx_logging { use sqlx::ConnectOptions; opt.disable_statement_logging(); From 2eb02cfbe0dc4cf0de81dfc22bb7113c7bb4fc06 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 17 Jun 2022 12:20:16 +0800 Subject: [PATCH 13/14] Fix SeaSchema's SQLx version to ^0.5 (#798) --- sea-orm-cli/Cargo.toml | 2 +- sea-orm-migration/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sea-orm-cli/Cargo.toml b/sea-orm-cli/Cargo.toml index 1c09cc266..7f5c41c69 100644 --- a/sea-orm-cli/Cargo.toml +++ b/sea-orm-cli/Cargo.toml @@ -33,7 +33,7 @@ clap = { version = "^2.33.3" } dotenv = { version = "^0.15" } async-std = { version = "^1.9", features = [ "attributes", "tokio1" ] } sea-orm-codegen = { version = "^0.8.0", path = "../sea-orm-codegen", optional = true } -sea-schema = { version = "^0.8.0" } +sea-schema = { version = "^0.8.1" } sqlx = { version = "^0.5", default-features = false, features = [ "mysql", "postgres" ], optional = true } tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing = { version = "0.1" } diff --git a/sea-orm-migration/Cargo.toml b/sea-orm-migration/Cargo.toml index 45a421adb..9ca00c742 100644 --- a/sea-orm-migration/Cargo.toml +++ b/sea-orm-migration/Cargo.toml @@ -23,7 +23,7 @@ clap = { version = "^2.33" } dotenv = { version = "^0.15" } sea-orm = { version = "^0.8.0", path = "../", default-features = false, features = ["macros"] } sea-orm-cli = { version = "^0.8.1", path = "../sea-orm-cli", default-features = false } -sea-schema = { version = "^0.8.0" } +sea-schema = { version = "^0.8.1" } tracing = { version = "0.1", features = ["log"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } From 091a91fc0a352b897ddeeb5797543efdc5e1b53a Mon Sep 17 00:00:00 2001 From: Fumitake Kawasaki Date: Mon, 20 Jun 2022 05:40:44 +0200 Subject: [PATCH 14/14] add zapp to Open Source Project (#803) --- COMMUNITY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMMUNITY.md b/COMMUNITY.md index f31875920..f07c45040 100644 --- a/COMMUNITY.md +++ b/COMMUNITY.md @@ -37,3 +37,4 @@ If you have built an app using SeaORM and want to showcase it, feel free to open - [snmp-sim-rust](https://github.com/sonalake/snmp-sim-rust) | SNMP Simulator - [template_flow](https://github.com/hilary888/template_flow) | An experiment exploring replacing placeholders in pre-prepared templates with their actual values - [actix-react-starter-template](https://github.com/aslamplr/actix-react-starter-template) | Actix web + SeaORM + React + Redux + Redux Saga project starter template +- [ZAPP](https://zapp.epics.dev) ([repository](https://github.com/EpicsDAO/zapp)) | ZAPP is a serverless framework made by Rust. Quickly build a scalable GraphQL API web server.