Skip to content

Suggestions on Database Field Length for Migration #2786

@Orefa

Description

@Orefa

Motivation

The current definition of the length and name of the database field is not in one position, and when the name and length are modified, it is very inconvenient to modify the name and length.

Proposed Solutions

Suggestions be changed to the following

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .create_table(
                Table::create()
                    .table(SysApp::Table)
                    .if_not_exists()
                    .col(string(SysApp::AppId).primary_key())
                    .col(string_uniq(SysApp::AppCode, 255))
                    .col(string_uniq(SysApp::AppName, 255))
                    .col(string_null(SysApp::AppDesc, 255))
                    .col(string_null(SysApp::AppUrl))
                    .index(
                        Index::create().unique()
                            .name("UK_SYS_APP_CODE")
                            .col(SysApp::AppCode)
                    )
                    .to_owned(),
            )
            .await?;
    }
}

#[derive(DeriveIden)]
pub enum SysApp {
    #[sea_orm(iden = "SYS_APP")]
    Table,
    #[sea_orm(iden = "APP_ID", len=36)]
    AppId,
    #[sea_orm(iden = "APP_CODE", len=255)]
    AppCode,
    #[sea_orm(iden = "APP_NAME", len=255)]
    AppName,
    #[sea_orm(iden = "APP_DESC", len=255)]
    AppDesc,
    #[sea_orm(iden = "APP_URL")]
    AppUrl,
}

Additional Information

The current definition is as follows:

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .create_table(
                Table::create()
                    .table(SysApp::Table)
                    .if_not_exists()
                    .col(string_len(SysApp::AppId, 36).primary_key())
                    .col(string_len_uniq(SysApp::AppCode, 255))
                    .col(string_len_uniq(SysApp::AppName, 255))
                    .col(string_len_null(SysApp::AppDesc, 255))
                    .col(string_null(SysApp::AppUrl))
                    .index(
                        Index::create().unique()
                            .name("UK_SYS_APP_CODE")
                            .col(SysApp::AppCode)
                    )
                    .to_owned(),
            )
            .await?;
}

#[derive(DeriveIden)]
pub enum SysApp {
    #[sea_orm(iden = "SYS_APP")]
    Table,
    #[sea_orm(iden = "APP_ID")]
    AppId,
    #[sea_orm(iden = "APP_CODE")]
    AppCode,
    #[sea_orm(iden = "APP_NAME")]
    AppName,
    #[sea_orm(iden = "APP_DESC")]
    AppDesc,
    #[sea_orm(iden = "APP_URL")]
    AppUrl,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions