In migration use enumeration #2224
Unanswered
fan-tastic-z
asked this question in
Q&A
Replies: 2 comments 2 replies
-
You can create the types as stated in https://www.sea-ql.org/SeaORM/docs/generate-entity/enumeration/#postgres |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'm running into a similar issue, and I think it could be because when creating the table, the type should be quoted. Here's what I'm seeing on my end: If I run the following raw SQL that's generated from the SeaQL builder: CREATE TYPE "PermissionState" AS ENUM ('unset', 'allow', 'deny');
CREATE TABLE "authPermissionGroup" (
"permission_id" uuid NOT NULL PRIMARY KEY,
"group_id" uuid NOT NULL,
"permission_state" PermissionState NOT NULL
); Then it fails. But, if I comment out the CREATE TYPE "PermissionState" AS ENUM ('unset', 'allow', 'deny');
CREATE TABLE "authPermissionGroup" (
"permission_id" uuid NOT NULL PRIMARY KEY,
"group_id" uuid NOT NULL,
"permission_state" "PermissionState" NOT NULL
); The Rust code in the migrations looks something like this: #[derive(DeriveIden)]
enum PermissionState {
#[sea_orm(iden = "PermissionState")]
Enum,
#[sea_orm(iden = "unset")]
Unset,
#[sea_orm(iden = "allow")]
Allow,
#[sea_orm(iden = "deny")]
Deny,
}
#[derive(DeriveIden)]
enum AuthPermissionGroup {
#[sea_orm(iden = "authPermissionGroup")]
Table,
PermissionId,
GroupId,
PermissionState,
}
manager
.create_type(
Type::create()
.as_enum(PermissionState::Enum)
.values([
PermissionState::Unset,
PermissionState::Allow,
PermissionState::Deny,
])
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
.table(AuthPermissionGroup::Table)
.col(
ColumnDef::new(AuthPermissionGroup::PermissionId)
.uuid()
.not_null(),
)
.col(
ColumnDef::new(AuthPermissionGroup::GroupId)
.uuid()
.not_null(),
)
.col(
ColumnDef::new(AuthPermissionGroup::PermissionState)
.enumeration(
PermissionState::Enum,
[
PermissionState::Unset,
PermissionState::Allow,
PermissionState::Deny,
],
)
.not_null(),
)
.to_owned(),
)
.await?; |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
According to the example in the document, using enumeration in migration will prompt an error
https://www.sea-ql.org/SeaORM/docs/migration/writing-migration/#schema-creation-methods
Execute
sea-orm-cli migrate up
sea-orm-cli version: sea-orm-cli 0.12.10
sea-orm-migration: 0.12.0
database: postgres
Beta Was this translation helpful? Give feedback.
All reactions