Replies: 4 comments 11 replies
-
You talking about this issue: #773? |
Beta Was this translation helpful? Give feedback.
-
Have you figured this out? |
Beta Was this translation helpful? Give feedback.
-
I played around with the failing migration. Im not 100% sure this is a good solution but it seems to work. use sea_orm_migration::{prelude::*, schema::*};
use crate::sea_orm::{DbBackend, DeriveActiveEnum, EnumIter, Schema};
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Create a new enum type `roles_name` with the values `Admin` and `User`
let db = SchemaManager::get_database_backend(manager);
let schema = Schema::new(db);
// If the database backend is Postgres, create a new enum type `roles_name` with the values `Admin` and `User`
if let DbBackend::Postgres = db {
manager
.create_type(schema.create_enum_from_active_enum::<RolesName>())
.await?;
};
// Create a new table `roles` with the columns `id`, `pid`, and `name`
manager
.create_table(
table_auto(Roles::Table)
.col(pk_auto(Roles::Id))
.col(uuid_uniq(Roles::Pid))
.col(
ColumnDef::new(Roles::Name)
.custom(Alias::new("roles_name")) // Use the enum type name
.not_null()
.to_owned(),
)
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Drop the table `roles`
manager
.drop_table(Table::drop().table(Roles::Table).to_owned())
.await?;
//
// Drop the enum type `roles_name` if db backend is Postgres
let db = SchemaManager::get_database_backend(manager);
if let DbBackend::Postgres = db {
manager
.drop_type(
extension::postgres::Type::drop()
.if_exists()
.name(RolesNameEnum)
.restrict()
.to_owned(),
)
.await?;
}
Ok(())
}
}
#[derive(DeriveIden)]
enum Roles {
Table,
Id,
Pid,
Name,
}
// Create a new enum for the roles_name
#[derive(EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "roles_name")]
pub enum RolesName {
#[sea_orm(string_value = "Admin")]
Admin,
#[sea_orm(string_value = "User")]
User,
} |
Beta Was this translation helpful? Give feedback.
-
Im gonna close this discussion because its not specific enough. I opened one regarding migrations: #865 I will see if it makes sense to also test sqlite in CI/CD instead of just testing postgres |
Beta Was this translation helpful? Give feedback.
-
I would love to add better Sqlite defaults to loco. Same as the official Ruby adapter but im unsure how to test it. the examples/demo project uses postgres and just changing the config yaml to sqlite and running cargo loco db reset fails.
2024-10-13T20:46:01.619611Z INFO app: sea_orm_migration::migrator: Applying migration 'm20240416_071825_roles' environment=development thread 'main' panicked at /home/silvan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sea-orm-1.0.0/src/database/statement.rs:146:1: not implemented
I think this might be a general issue even tho migrating from postgres to sqlite is probably rather rare. Would still be nice if its possible
Beta Was this translation helpful? Give feedback.
All reactions