refactor: enforce unique constraints on account and account_category names; update foreign key actions

This commit is contained in:
GW_MC
2026-05-27 11:19:02 +00:00
parent 1b1f9777ec
commit 517fb37818
3 changed files with 8 additions and 4 deletions

View File

@@ -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(),
)