refactor: enforce unique constraints on account and account_category names; update foreign key actions
This commit is contained in:
@@ -12,7 +12,7 @@ impl MigrationTrait for Migration {
|
||||
.table("account_category")
|
||||
.if_not_exists()
|
||||
.col(pk_auto("id").not_null())
|
||||
.col(string("name").not_null())
|
||||
.col(string("name").not_null().unique_key())
|
||||
.col(string("account_type").not_null())
|
||||
.col(string("created_at").not_null())
|
||||
.col(string("updated_at").not_null())
|
||||
@@ -27,7 +27,7 @@ impl MigrationTrait for Migration {
|
||||
.if_not_exists()
|
||||
.col(pk_auto("id").not_null())
|
||||
//
|
||||
.col(string("name").not_null())
|
||||
.col(string("name").not_null().unique_key())
|
||||
.col(integer("account_category_id").not_null())
|
||||
//
|
||||
.col(string("created_at").not_null())
|
||||
@@ -37,7 +37,9 @@ impl MigrationTrait for Migration {
|
||||
ForeignKey::create()
|
||||
.name("fk-account-category")
|
||||
.from("account", "account_category_id")
|
||||
.to("account_category", "id"),
|
||||
.to("account_category", "id")
|
||||
.on_delete(ForeignKeyAction::NoAction)
|
||||
.on_update(ForeignKeyAction::Restrict),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i64,
|
||||
#[sea_orm(unique)]
|
||||
pub name: String,
|
||||
pub account_category_id: i64,
|
||||
pub created_at: String,
|
||||
@@ -21,7 +22,7 @@ pub enum Relation {
|
||||
belongs_to = "super::account_category::Entity",
|
||||
from = "Column::AccountCategoryId",
|
||||
to = "super::account_category::Column::Id",
|
||||
on_update = "NoAction",
|
||||
on_update = "Restrict",
|
||||
on_delete = "NoAction"
|
||||
)]
|
||||
AccountCategory,
|
||||
|
||||
@@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i64,
|
||||
#[sea_orm(unique)]
|
||||
pub name: String,
|
||||
pub account_type: String,
|
||||
pub created_at: String,
|
||||
|
||||
Reference in New Issue
Block a user