Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Create Data Type section in 02-writing-migration.md #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lynxlevin
Copy link

@lynxlevin lynxlevin commented Sep 26, 2024

This is to fix 2 compile errors.

  • Add Type import to fix the following error:
    • error[E0433]: failed to resolve: use of undeclared type Type
  • Add to_owned() method to fix the following error:
    • expected TypeCreateStatement, found &mut TypeCreateStatement

Changes

  • Fixes 2 compile errors in sample code in document.

This is to fix 2 compile errors.
- Add Type import to fix `error[E0433]: failed to resolve: use of undeclared type `Type``.
- Add `to_owned()` method to fix `expected `TypeCreateStatement`, found `&mut TypeCreateStatement``
@lynxlevin
Copy link
Author

Sea-orm version

[dependencies.sea-orm-migration]
version = "~1.0"
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-native-tls", # `ASYNC_RUNTIME` feature
  "sqlx-postgres",            # `DATABASE_DRIVER` feature
  "with-uuid",
  "with-chrono",
  "with-json",
]

@lynxlevin
Copy link
Author

lynxlevin commented Sep 26, 2024

About the first error.
Code

use sea_orm::{EnumIter, Iterable};
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .create_type(
                Type::create()
                    .as_enum(TimezoneEnum)
                    .values(TimezoneVariants::iter()),
            )
            .await
    }
}

#[derive(DeriveIden)]
struct TimezoneEnum;

#[derive(DeriveIden, EnumIter)]
pub enum TimezoneVariants {
    #[sea_orm(iden = "Asia/Tokyo")]
    AsiaTokyo,
    #[sea_orm(iden = "UTC")]
    Utc,
}

Error message on sea-orm-cli migrate fresh

Running `cargo run --manifest-path ./migration/Cargo.toml -- fresh -u postgresql://test_user:xxxxxx@localhost:5432/test`
   Compiling migration v0.1.0 (/migration)
error[E0433]: failed to resolve: use of undeclared type `Type`
  --> src/m20240926_000001_create_users_table.rs:12:17
   |
12 |                 Type::create()
   |                 ^^^^ use of undeclared type `Type`
   |
help: consider importing one of these items
   |
1  + use crate::extension::postgres::Type;
   |
1  + use sea_orm_migration::prelude::extension::postgres::Type;
   |

For more information about this error, try `rustc --explain E0433`.
error: could not compile `migration` (lib) due to 1 previous error
Fail to run migration

@lynxlevin
Copy link
Author

lynxlevin commented Sep 26, 2024

The second error.
Code:

use sea_orm_migration::prelude::extension::postgres::Type;
// No other changes to the code above.

Error:

Running `cargo run --manifest-path ./migration/Cargo.toml -- fresh -u postgresql://test_user:xxxxxx@localhost:5432/test`
   Compiling migration v0.1.0 (/migration)
error[E0308]: mismatched types
  --> src/m20240926_000001_create_users_table.rs:13:17
   |
12 |               .create_type(
   |                ----------- arguments to this method are incorrect
13 | /                 Type::create()
14 | |                     .as_enum(TimezoneEnum)
15 | |                     .values(TimezoneVariants::iter()),
   | |_____________________________________________________^ expected `TypeCreateStatement`, found `&mut TypeCreateStatement`
   |
note: method defined here
  --> /.cargo/registry/src/index.crates.io-6f17d22bba15001f/sea-orm-migration-1.0.0/src/manager.rs:57:18
   |
57 |     pub async fn create_type(&self, stmt: TypeCreateStatement) -> Result<(), DbErr> {
   |                  ^^^^^^^^^^^

For more information about this error, try `rustc --explain E0308`.
error: could not compile `migration` (lib) due to 1 previous error
Fail to run migration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant