Skip to content

Commit

Permalink
internal(modifier): ensure consistent constraint name
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Oct 21, 2023
1 parent cc8b44e commit 2412994
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
22 changes: 18 additions & 4 deletions app/Database/Migrations/2023-07-26-022116_CreateModifiersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function up()
"name" => [
"type" => "VARCHAR",
"constraint" => "255",
"unique" => true,
],
"description" => [
"type" => "TEXT",
Expand All @@ -49,9 +48,24 @@ public function up()
"null" => true,
]
]);
$this->forge->addPrimaryKey("id");
$this->forge->addForeignKey("debit_account_id", "accounts", "id", "CASCADE", "CASCADE");
$this->forge->addForeignKey("credit_account_id", "accounts", "id", "CASCADE", "CASCADE");
$this->forge->addPrimaryKey("id", "pk_modifiers");
$this->forge->addUniqueKey("name", "modifiers_name_key");
$this->forge->addForeignKey(
"debit_account_id",
"accounts",
"id",
"CASCADE",
"CASCADE",
"modifiers_debit_account_id_foreign"
);
$this->forge->addForeignKey(
"credit_account_id",
"accounts",
"id",
"CASCADE",
"CASCADE",
"modifiers_credit_account_id_foreign"
);
$this->forge->createTable("modifiers");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ public function up()
if ($database->DBDriver === "SQLite3") return;

$this->forge->dropKey("modifiers", "modifiers_name_key", false);
$this->forge->addUniqueKey([ "debit_account_id", "credit_account_id", "name" ]);
$this->forge->addUniqueKey(
[
"debit_account_id",
"credit_account_id",
"name"
],
"modifiers_debit_account_id_credit_account_id_name"
);
$this->forge->processIndexes("modifiers");
}

Expand Down

0 comments on commit 2412994

Please sign in to comment.