Skip to content

Commit

Permalink
Less verbose migration (SeaQL/sea-orm#2084)
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Feb 6, 2024
1 parent 615243f commit 4b7f28b
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 58 deletions.
8 changes: 4 additions & 4 deletions docs-site/content/docs/getting-started/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ impl MigrationTrait for Migration {
manager
.create_table(
table_auto(Articles::Table)
.col(pk_auto(Articles::Id).borrow_mut())
.col(string_null(Articles::Title).borrow_mut())
.col(text(Articles::Content).borrow_mut())
.col(pk_auto(Articles::Id))
.col(string_null(Articles::Title))
.col(text(Articles::Content))
.to_owned(),
)
.await
Expand Down Expand Up @@ -649,7 +649,7 @@ If you peek into the new migration, you'll discover a new database relation in t
```rust
..
..
.col(integer(Comments::ArticleId).borrow_mut())
.col(integer(Comments::ArticleId))
.foreign_key(
ForeignKey::create()
.name("fk-comments-articles")
Expand Down
2 changes: 1 addition & 1 deletion docs-site/content/docs/the-app/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Adding a column:
.alter_table(
Table::alter()
.table(Movies::Table)
.add_column_if_not_exists(integer(Movies::Rating).borrow_mut())
.add_column_if_not_exists(integer(Movies::Rating))
.to_owned(),
)
.await
Expand Down
22 changes: 11 additions & 11 deletions examples/demo/migration/src/m20220101_000001_users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ pub struct Migration;
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let table = table_auto(Users::Table)
.col(pk_auto(Users::Id).borrow_mut())
.col(uuid(Users::Pid).borrow_mut())
.col(string_uniq(Users::Email).borrow_mut())
.col(string(Users::Password).borrow_mut())
.col(string(Users::ApiKey).borrow_mut().unique_key())
.col(string(Users::Name).borrow_mut())
.col(string_null(Users::ResetToken).borrow_mut())
.col(timestamp_null(Users::ResetSentAt).borrow_mut())
.col(string_null(Users::EmailVerificationToken).borrow_mut())
.col(timestamp_null(Users::EmailVerificationSentAt).borrow_mut())
.col(timestamp_null(Users::EmailVerifiedAt).borrow_mut())
.col(pk_auto(Users::Id))
.col(uuid(Users::Pid))
.col(string_uniq(Users::Email))
.col(string(Users::Password))
.col(string(Users::ApiKey).unique_key())
.col(string(Users::Name))
.col(string_null(Users::ResetToken))
.col(timestamp_null(Users::ResetSentAt))
.col(string_null(Users::EmailVerificationToken))
.col(timestamp_null(Users::EmailVerificationSentAt))
.col(timestamp_null(Users::EmailVerifiedAt))
.to_owned();
manager.create_table(table).await?;
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions examples/demo/migration/src/m20231103_114510_notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ impl MigrationTrait for Migration {
manager
.create_table(
table_auto(Notes::Table)
.col(pk_auto(Notes::Id).borrow_mut())
.col(string_null(Notes::Title).borrow_mut())
.col(string_null(Notes::Content).borrow_mut())
.col(pk_auto(Notes::Id))
.col(string_null(Notes::Title))
.col(string_null(Notes::Content))
.to_owned(),
)
.await
Expand Down
2 changes: 1 addition & 1 deletion src/gen/templates/migration.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl MigrationTrait for Migration {
.alter_table(
Table::alter()
.table(Movies::Table)
.add_column_if_not_exists(integer(Movies::Rating).borrow_mut())
.add_column_if_not_exists(integer(Movies::Rating))
.to_owned(),
)
.await
Expand Down
6 changes: 3 additions & 3 deletions src/gen/templates/model.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ impl MigrationTrait for Migration {
{% for ref in references -%}
.col({{model}}::{{ref.1 | pascal_case}})
{% endfor -%}
.borrow_mut(),
,
)
{% else -%}
.col(pk_auto({{model}}::Id).borrow_mut())
.col(pk_auto({{model}}::Id))
{% endif -%}
{% for column in columns -%}
.col({{column.1}}({{model}}::{{column.0 | pascal_case}}).borrow_mut())
.col({{column.1}}({{model}}::{{column.0 | pascal_case}}))
{% endfor -%}
{% for ref in references -%}
.foreign_key(
Expand Down
14 changes: 7 additions & 7 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
//! impl MigrationTrait for Migration {
//! async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
//! let table = table_auto(Users::Table)
//! .col(pk_auto(Users::Id).borrow_mut())
//! .col(uuid(Users::Pid).borrow_mut())
//! .col(string_uniq(Users::Email).borrow_mut())
//! .col(string(Users::Password).borrow_mut())
//! .col(string(Users::Name).borrow_mut())
//! .col(string_null(Users::ResetToken).borrow_mut())
//! .col(timestamp_null(Users::ResetSentAt).borrow_mut())
//! .col(pk_auto(Users::Id))
//! .col(uuid(Users::Pid))
//! .col(string_uniq(Users::Email))
//! .col(string(Users::Password))
//! .col(string(Users::Name))
//! .col(string_null(Users::ResetToken))
//! .col(timestamp_null(Users::ResetSentAt))
//! .to_owned();
//! manager.create_table(table).await?;
//! Ok(())
Expand Down
22 changes: 11 additions & 11 deletions starters/rest-api/migration/src/m20220101_000001_users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ pub struct Migration;
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let table = table_auto(Users::Table)
.col(pk_auto(Users::Id).borrow_mut())
.col(uuid(Users::Pid).borrow_mut())
.col(string_uniq(Users::Email).borrow_mut())
.col(string(Users::Password).borrow_mut())
.col(string(Users::ApiKey).borrow_mut().unique_key())
.col(string(Users::Name).borrow_mut())
.col(string_null(Users::ResetToken).borrow_mut())
.col(timestamp_null(Users::ResetSentAt).borrow_mut())
.col(string_null(Users::EmailVerificationToken).borrow_mut())
.col(timestamp_null(Users::EmailVerificationSentAt).borrow_mut())
.col(timestamp_null(Users::EmailVerifiedAt).borrow_mut())
.col(pk_auto(Users::Id))
.col(uuid(Users::Pid))
.col(string_uniq(Users::Email))
.col(string(Users::Password))
.col(string(Users::ApiKey).unique_key())
.col(string(Users::Name))
.col(string_null(Users::ResetToken))
.col(timestamp_null(Users::ResetSentAt))
.col(string_null(Users::EmailVerificationToken))
.col(timestamp_null(Users::EmailVerificationSentAt))
.col(timestamp_null(Users::EmailVerifiedAt))
.to_owned();
manager.create_table(table).await?;
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions starters/rest-api/migration/src/m20231103_114510_notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ impl MigrationTrait for Migration {
manager
.create_table(
table_auto(Notes::Table)
.col(pk_auto(Notes::Id).borrow_mut())
.col(string_null(Notes::Title).borrow_mut())
.col(string_null(Notes::Content).borrow_mut())
.col(pk_auto(Notes::Id))
.col(string_null(Notes::Title))
.col(string_null(Notes::Content))
.to_owned(),
)
.await
Expand Down
22 changes: 11 additions & 11 deletions starters/saas/migration/src/m20220101_000001_users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ pub struct Migration;
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let table = table_auto(Users::Table)
.col(pk_auto(Users::Id).borrow_mut())
.col(uuid(Users::Pid).borrow_mut())
.col(string_uniq(Users::Email).borrow_mut())
.col(string(Users::Password).borrow_mut())
.col(string(Users::ApiKey).borrow_mut().unique_key())
.col(string(Users::Name).borrow_mut())
.col(string_null(Users::ResetToken).borrow_mut())
.col(timestamp_null(Users::ResetSentAt).borrow_mut())
.col(string_null(Users::EmailVerificationToken).borrow_mut())
.col(timestamp_null(Users::EmailVerificationSentAt).borrow_mut())
.col(timestamp_null(Users::EmailVerifiedAt).borrow_mut())
.col(pk_auto(Users::Id))
.col(uuid(Users::Pid))
.col(string_uniq(Users::Email))
.col(string(Users::Password))
.col(string(Users::ApiKey).unique_key())
.col(string(Users::Name))
.col(string_null(Users::ResetToken))
.col(timestamp_null(Users::ResetSentAt))
.col(string_null(Users::EmailVerificationToken))
.col(timestamp_null(Users::EmailVerificationSentAt))
.col(timestamp_null(Users::EmailVerifiedAt))
.to_owned();
manager.create_table(table).await?;
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions starters/saas/migration/src/m20231103_114510_notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ impl MigrationTrait for Migration {
manager
.create_table(
table_auto(Notes::Table)
.col(pk_auto(Notes::Id).borrow_mut())
.col(string_null(Notes::Title).borrow_mut())
.col(string_null(Notes::Content).borrow_mut())
.col(pk_auto(Notes::Id))
.col(string_null(Notes::Title))
.col(string_null(Notes::Content))
.to_owned(),
)
.await
Expand Down

0 comments on commit 4b7f28b

Please sign in to comment.