Skip to content

Commit

Permalink
Pr/471 (#583)
Browse files Browse the repository at this point in the history
* Add Poem example

* Name conflict of foreign key constraints when two entities have more than one foreign keys (#417)

* fix: name conflict of foreign key constraints when two entities have more than one fk

* test: update test case's foreign keys

* feat: override default name of foreign key constraint

* Add `max_lifetime` connection option

* Remove `r#` prefix from column name when field has a raw identifier

* Fix FromQueryResult when Result is redefined

Macros should only ever use absolute import paths.
Shorthands can clash (as they have in my case).

* Support the use of chrono::DateTime<Utc> in sea-orm

Add documentation for this

Temporarily use a fork to include new Sea-query code

Add tests for DateTimeUtc

Solve Github actions error by add the code to create a table

Assertion accuracy tests

Rectify incorrect format

* Refactoring

`ColumnDef` with default value

Cargo fmt

Update docs

Fixup

Support `DateTimeLocal`

Update docs

Codegen write db timestamp column as `DateTimeUtc` type

Update dependency

Merge branch 'sea-query/add-new-column-ref' into pr/429

feat: apply alias on `ColumnRef::SchemaTableColumn`

* Update sea-query dependency

* Fully quantity `std::result::Result` in proc_maros

* Migration (#335)

* Refactor `ConnectionTrait`

* Refactoring

* Build index & foreign key statements

* Fix imports

* Fixup

* Rocket example with migration

* async-std compatible with the tokio 1.0 runtime

* Use reexported dependency

* Compile without selecting any db backend

* Updating sea-orm-cli dep

* sea-orm-cli migrate commands

* cargo fmt

* Test [cli]

* Refactoring

* Clap app name should be "sea-orm-cli"

* Correctly capture MIGRATION_DIR

* Rename README

* Add `sea-orm-cli migrate init` command

* Update README

* Try restructured sea-query dependency (SeaQL/sea-schema#41)

* Set `DATABASE_URL` environment variable

* Fix sea-schema dependency

* Codegen `column_name` proc_macro attribute (#433)

* feat: codegen `column_name` proc_macro attribute

* test: codegen `column_name`

* Temporary fix

* Fix sea-orm dependency

* Insert Default - Inserting `ActiveModel` with all attributes `NotSet` (#432)

* feat: apply alias on `ColumnRef::SchemaTableColumn`

* build: update sea-query dependency

* feat: insert default

* Use sea-query 0.21

Co-authored-by: Billy Chan <[email protected]>

* Easy joins with MockDatabase #447 (#455)

* Easy joins with MockDatabase #447

* fix MR

* add unit test

* Add test cases

* Cargo fmt

Co-authored-by: Bastian Schubert <[email protected]>
Co-authored-by: Billy Chan <[email protected]>
Co-authored-by: Chris Tsang <[email protected]>

* cargo fmt

* Revert "Insert Default - Inserting `ActiveModel` with all attributes `NotSet` (#432)"

This reverts commit 33a87d7.

* Prepare release

* sea-orm-codegen 0.6.0

* sea-orm-cli 0.6.0

* sea-orm-macros 0.6.0

* 0.6.0

* Optimize GitHub actions

* Update examples sea-orm version

Update example sea-schema version

Update [cli] sea-schema version

* Fix [cli] cargo publish failed

* Update CHANGELOG

* Use sea-schema 0.5.1

* use sea_schema::migration::prelude

* Use caret requirements

* Fix build error

* Examples with migration (#509)

* Update examples sea-orm version

* Update example sea-schema version

* Update [cli] sea-schema version

* Fix [cli] cargo publish failed

* Update CHANGELOG

* Edit rocket example

* Poem example with migration

* Axum example with migration

* Refactoring

* Actix4 example with migration

* Actix example with migration

* Use sea_schema::migration::prelude

Co-authored-by: Sunli <[email protected]>
Co-authored-by: Billy Chan <[email protected]>
Co-authored-by: Billy Chan <[email protected]>
Co-authored-by: Szepesi Tibor <[email protected]>
Co-authored-by: Tom Hacohen <[email protected]>
Co-authored-by: Charles Chege <[email protected]>
Co-authored-by: Bastian <[email protected]>
Co-authored-by: Bastian Schubert <[email protected]>
  • Loading branch information
9 people authored Mar 6, 2022
1 parent ccd0d97 commit 566c8c6
Show file tree
Hide file tree
Showing 139 changed files with 2,928 additions and 396 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
runtime: [async-std, actix, tokio]
runtime: [async-std]
tls: [native-tls, rustls]
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -165,7 +165,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
runtime: [async-std, actix, tokio]
runtime: [actix]
tls: [native-tls, rustls]
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -204,7 +204,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
runtime: [async-std, actix, tokio]
runtime: [tokio]
tls: [native-tls, rustls]
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -293,7 +293,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
path: [basic, actix_example, actix4_example, axum_example, rocket_example]
path: [basic, actix_example, actix4_example, axum_example, rocket_example, poem_example]
steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -356,7 +356,7 @@ jobs:
strategy:
fail-fast: false
matrix:
runtime: [async-std, actix, tokio]
runtime: [async-std]
tls: [native-tls, rustls]
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -400,7 +400,7 @@ jobs:
fail-fast: false
matrix:
version: [8.0, 5.7]
runtime: [async-std, actix, tokio]
runtime: [actix]
tls: [native-tls]
services:
mysql:
Expand Down Expand Up @@ -461,7 +461,7 @@ jobs:
fail-fast: false
matrix:
version: [10.6, 10.5, 10.4]
runtime: [async-std, actix, tokio]
runtime: [actix]
tls: [native-tls]
services:
mysql:
Expand Down
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,40 @@ 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.6.0 - 2022-02-07

### New Features
* Migration Support by @billy1624 in https://github.com/SeaQL/sea-orm/pull/335
* Support `DateTime<Utc>` & `DateTime<Local>` by @billy1624 in https://github.com/SeaQL/sea-orm/pull/489
* Add `max_lifetime` connection option by @billy1624 in https://github.com/SeaQL/sea-orm/pull/493

### Enhancements
* Model with Generics by @billy1624 in https://github.com/SeaQL/sea-orm/pull/400
* Add Poem example by @sunli829 in https://github.com/SeaQL/sea-orm/pull/446
* Codegen `column_name` proc_macro attribute by @billy1624 in https://github.com/SeaQL/sea-orm/pull/433
* Easy joins with MockDatabase #447 by @cemoktra in https://github.com/SeaQL/sea-orm/pull/455

### Bug Fixes
* CLI allow generate entity with url without password by @billy1624 in https://github.com/SeaQL/sea-orm/pull/436
* Support up to 6-ary composite primary key by @billy1624 in https://github.com/SeaQL/sea-orm/pull/423
* Fix FromQueryResult when Result is redefined by @tasn in https://github.com/SeaQL/sea-orm/pull/495
* Remove `r#` prefix when deriving `FromQueryResult` by @smrtrfszm in https://github.com/SeaQL/sea-orm/pull/494

### Breaking Changes
* Name conflict of foreign key constraints when two entities have more than one foreign keys by @billy1624 in https://github.com/SeaQL/sea-orm/pull/417

### Fixed Issues
* Is it possible to have 4 values Composite Key? https://github.com/SeaQL/sea-orm/issues/352
* Support `DateTime<Utc>` & `DateTime<Local>` https://github.com/SeaQL/sea-orm/issues/381
* Codegen `column_name` proc_macro attribute if column name isn't in snake case https://github.com/SeaQL/sea-orm/issues/395
* Model with Generics https://github.com/SeaQL/sea-orm/issues/402
* Foreign key constraint collision when multiple keys exist between the same two tables https://github.com/SeaQL/sea-orm/issues/405
* sea-orm-cli passwordless database user causes "No password was found in the database url" error https://github.com/SeaQL/sea-orm/issues/435
* Testing joins with MockDatabase https://github.com/SeaQL/sea-orm/issues/447
* Surface max_lifetime connection option https://github.com/SeaQL/sea-orm/issues/475

**Full Changelog**: https://github.com/SeaQL/sea-orm/compare/0.5.0...0.6.0

## 0.5.0 - 2022-01-01

### Fixed Issues
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = [".", "sea-orm-macros", "sea-orm-codegen"]

[package]
name = "sea-orm"
version = "0.5.0"
version = "0.6.0"
authors = ["Chris Tsang <[email protected]>"]
edition = "2021"
description = "🐚 An async & dynamic ORM for Rust"
Expand All @@ -29,8 +29,8 @@ futures = { version = "^0.3" }
futures-util = { version = "^0.3" }
tracing = { version = "0.1", features = ["log"] }
rust_decimal = { version = "^1", optional = true }
sea-orm-macros = { version = "^0.5.0", path = "sea-orm-macros", optional = true }
sea-query = { version = "^0.20.0", features = ["thread-safe"] }
sea-orm-macros = { version = "^0.6.0", path = "sea-orm-macros", optional = true }
sea-query = { version = "^0.21.0", features = ["thread-safe"] }
sea-strum = { version = "^0.23", features = ["derive", "sea-orm"] }
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1", optional = true }
Expand All @@ -43,7 +43,7 @@ once_cell = "1.8"
[dev-dependencies]
smol = { version = "^1.2" }
smol-potat = { version = "^1.1" }
async-std = { version = "^1.9", features = ["attributes"] }
async-std = { version = "^1.9", features = ["attributes", "tokio1"] }
tokio = { version = "^1.6", features = ["full"] }
actix-rt = { version = "2.2.0" }
maplit = { version = "^1" }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Join our Discord server to chat with others in the SeaQL community!
+ [Rocket Example](https://github.com/SeaQL/sea-orm/tree/master/examples/rocket_example)
+ [Actix Example](https://github.com/SeaQL/sea-orm/tree/master/examples/actix_example)
+ [Axum Example](https://github.com/SeaQL/sea-orm/tree/master/examples/axum_example)
+ [Poem Example](https://github.com/SeaQL/sea-orm/tree/master/examples/poem_example)

## Features

Expand Down
2 changes: 1 addition & 1 deletion build-tools/cargo-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cd sea-orm-cli
sed -i 's/^version.*$/'"version = \"$1\"/" Cargo.toml
sed -i 's/^sea-orm-codegen [^,]*,/sea-orm-codegen = { version = "\^'$1'",/' Cargo.toml
git commit -am "sea-orm-cli $1"
cargo publish
# cargo publish
cd ..
sleep 30
cd sea-orm-macros
Expand Down
2 changes: 1 addition & 1 deletion examples/actix4_example/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
HOST=127.0.0.1
PORT=8000
DATABASE_URL="mysql://root:@localhost/actix_example"
DATABASE_URL="mysql://root:root@localhost/actix_example"
14 changes: 3 additions & 11 deletions examples/actix4_example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
publish = false

[workspace]
members = [".", "entity", "migration"]

[dependencies]
actix-files = "0.6.0-beta.4"
Expand All @@ -19,14 +20,5 @@ dotenv = "0.15"
listenfd = "0.3.3"
serde = "1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[dependencies.sea-orm]
path = "../../" # remove this line in your own project
version = "^0.5.0"
features = ["macros", "runtime-actix-native-tls", "debug-print"]
default-features = false

[features]
default = ["sqlx-mysql"]
sqlx-mysql = ["sea-orm/sqlx-mysql"]
sqlx-postgres = ["sea-orm/sqlx-postgres"]
entity = { path = "entity" }
migration = { path = "migration" }
13 changes: 7 additions & 6 deletions examples/actix4_example/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
![screenshot](Screenshot.png)

# Actix 4 Beta with SeaORM example app

Edit `Cargo.toml` to use `sqlx-mysql` or `sqlx-postgres`.
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database

```toml
[features]
default = ["sqlx-$DATABASE"]
```
1. Turn on the appropriate database feature for your chosen db in `entity/Cargo.toml` (the `"sqlx-mysql",` line)

1. Execute `cargo run` to start the server

Edit `.env` to point to your database.
1. Visit [localhost:8000](http://localhost:8000) in browser

Run server with auto-reloading:

Expand Down
Binary file added examples/actix4_example/Screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions examples/actix4_example/entity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "entity"
version = "0.1.0"
edition = "2021"
publish = false

[lib]
name = "entity"
path = "src/lib.rs"

[dependencies]
serde = { version = "1", features = ["derive"] }

[dependencies.sea-orm]
# path = "../../../" # remove this line in your own project
version = "^0.6.0"
features = [
"macros",
"debug-print",
"runtime-actix-native-tls",
"sqlx-mysql",
# "sqlx-postgres",
# "sqlx-sqlite",
]
default-features = false
3 changes: 3 additions & 0 deletions examples/actix4_example/entity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod post;

pub use sea_orm;
File renamed without changes.
13 changes: 13 additions & 0 deletions examples/actix4_example/migration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "migration"
version = "0.1.0"
edition = "2021"
publish = false

[lib]
name = "migration"
path = "src/lib.rs"

[dependencies]
sea-schema = { version = "^0.5.0", default-features = false, features = [ "migration", "debug-print" ] }
entity = { path = "../entity" }
37 changes: 37 additions & 0 deletions examples/actix4_example/migration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Running Migrator CLI

- Apply all pending migrations
```sh
cargo run
```
```sh
cargo run -- up
```
- Apply first 10 pending migrations
```sh
cargo run -- up -n 10
```
- Rollback last applied migrations
```sh
cargo run -- down
```
- Rollback last 10 applied migrations
```sh
cargo run -- down -n 10
```
- Drop all tables from the database, then reapply all migrations
```sh
cargo run -- fresh
```
- Rollback all applied migrations, then reapply all migrations
```sh
cargo run -- refresh
```
- Rollback all applied migrations
```sh
cargo run -- reset
```
- Check the status of all migrations
```sh
cargo run -- status
```
12 changes: 12 additions & 0 deletions examples/actix4_example/migration/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pub use sea_schema::migration::prelude::*;

mod m20220120_000001_create_post_table;

pub struct Migrator;

#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(m20220120_000001_create_post_table::Migration)]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use entity::post::*;
use sea_schema::migration::prelude::*;

pub struct Migration;

impl MigrationName for Migration {
fn name(&self) -> &str {
"m20220120_000001_create_post_table"
}
}

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(Entity)
.if_not_exists()
.col(
ColumnDef::new(Column::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Column::Title).string().not_null())
.col(ColumnDef::new(Column::Text).string().not_null())
.to_owned(),
)
.await
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Entity).to_owned())
.await
}
}
7 changes: 7 additions & 0 deletions examples/actix4_example/migration/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use migration::Migrator;
use sea_schema::migration::*;

#[async_std::main]
async fn main() {
cli::run_cli(Migrator).await;
}
Loading

0 comments on commit 566c8c6

Please sign in to comment.