generated from KennethTrecy/web_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal(cash flow group): make migration
- Loading branch information
1 parent
2d53d42
commit 28cd7f0
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
app/Database/Migrations/2024-05-11-061554_CreateCashFlowGroups.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace App\Database\Migrations; | ||
|
||
use CodeIgniter\Database\Migration; | ||
use CodeIgniter\Database\RawSql; | ||
|
||
use Config\Database; | ||
|
||
class CreateCashFlowGroups extends Migration | ||
{ | ||
public function up() | ||
{ | ||
$database = Database::connect(); | ||
|
||
$this->forge->addField([ | ||
"id" => [ | ||
"type" => "BIGINT", | ||
"unsigned" => true, | ||
"auto_increment" => true, | ||
], | ||
"user_id" => [ | ||
"type" => "INT", | ||
"unsigned" => true, | ||
], | ||
"name" => [ | ||
"type" => "VARCHAR", | ||
"constraint" => "255", | ||
], | ||
"description" => [ | ||
"type" => "TEXT", | ||
"null" => true, | ||
], | ||
"kind" => [ | ||
"type" => "INT", | ||
"unsigned" => true, | ||
], | ||
"created_at" => [ | ||
"type" => "DATETIME", | ||
"default" => new RawSql("CURRENT_TIMESTAMP"), | ||
], | ||
"updated_at" => [ | ||
"type" => "DATETIME", | ||
"default" => new RawSql("CURRENT_TIMESTAMP"), | ||
], | ||
"deleted_at" => [ | ||
"type" => "DATETIME", | ||
"null" => true, | ||
] | ||
]); | ||
$this->forge->addPrimaryKey("id", "pk_cash_flow_groups"); | ||
if ($database->DBDriver !== "SQLite3") { | ||
$this->forge->addUniqueKey([ "user_id", "name" ], "cash_flow_groups_user_id_name"); | ||
$this->forge->addForeignKey( | ||
"user_id", | ||
"users", | ||
"id", | ||
"CASCADE", | ||
"CASCADE", | ||
"cash_flow_groups_user_id_foreign" | ||
); | ||
} | ||
$this->forge->createTable("cash_flow_groups"); | ||
} | ||
|
||
public function down() | ||
{ | ||
$this->forge->dropTable("cash_flow_groups"); | ||
} | ||
} |