Suggestions on Database Field Length for Migration
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 9.9k
- Forks
- 734
- Avg merge
- 6h 36m
- Merged PRs (30d)
- 8
Description
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,
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the migration API around MigrationTrait, SchemaManager, Table::create, the string_len helpers, and DeriveIden attributes. Compare the proposed centralized length declarations with the current migration example, then determine the required API and derive-macro changes. Done means field names and lengths can be maintained in one place while preserving the shown table and index behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100