Skip to content

Commit

Permalink
refactor(database): use static function keyword in database migration…
Browse files Browse the repository at this point in the history
… files

Updated the database migrations to use 'static function' instead of 'function', following the best practice to avoid memory leaks, enhance performance, and improve code readability. The changes affect various tables including users, jobs, cache, oauth and tarfin cards.
  • Loading branch information
deligoez committed May 15, 2024
1 parent 8724eb6 commit 2b58355
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions database/migrations/0001_01_01_000000_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
public function up(): void
{
Schema::create(table: 'users', callback: function (Blueprint $table): void {
Schema::create(table: 'users', callback: static function (Blueprint $table): void {
$table->id();
$table->string(column: 'name');
$table->string(column: 'email')->unique();
Expand All @@ -22,13 +22,13 @@ public function up(): void
$table->timestamps();
});

Schema::create(table: 'password_reset_tokens', callback: function (Blueprint $table): void {
Schema::create(table: 'password_reset_tokens', callback: static function (Blueprint $table): void {
$table->string(column: 'email')->primary();
$table->string(column: 'token');
$table->timestamp(column: 'created_at')->nullable();
});

Schema::create(table: 'sessions', callback: function (Blueprint $table): void {
Schema::create(table: 'sessions', callback: static function (Blueprint $table): void {
$table->string(column: 'id')->primary();
$table->foreignId(column: 'user_id')->nullable()->index();
$table->string(column: 'ip_address', length: 45)->nullable();
Expand Down
4 changes: 2 additions & 2 deletions database/migrations/0001_01_01_000001_create_cache_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
*/
public function up(): void
{
Schema::create(table: 'cache', callback: function (Blueprint $table): void {
Schema::create(table: 'cache', callback: static function (Blueprint $table): void {
$table->string(column: 'key')->primary();
$table->mediumText(column: 'value');
$table->integer(column: 'expiration');
});

Schema::create(table: 'cache_locks', callback: function (Blueprint $table): void {
Schema::create(table: 'cache_locks', callback: static function (Blueprint $table): void {
$table->string(column: 'key')->primary();
$table->string(column: 'owner');
$table->integer(column: 'expiration');
Expand Down
6 changes: 3 additions & 3 deletions database/migrations/0001_01_01_000002_create_jobs_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
public function up(): void
{
Schema::create(table: 'jobs', callback: function (Blueprint $table): void {
Schema::create(table: 'jobs', callback: static function (Blueprint $table): void {
$table->id();
$table->string(column: 'queue')->index();
$table->longText(column: 'payload');
Expand All @@ -22,7 +22,7 @@ public function up(): void
$table->unsignedInteger(column: 'created_at');
});

Schema::create(table: 'job_batches', callback: function (Blueprint $table): void {
Schema::create(table: 'job_batches', callback: static function (Blueprint $table): void {
$table->string(column: 'id')->primary();
$table->string(column: 'name');
$table->integer(column: 'total_jobs');
Expand All @@ -35,7 +35,7 @@ public function up(): void
$table->integer(column: 'finished_at')->nullable();
});

Schema::create(table: 'failed_jobs', callback: function (Blueprint $table): void {
Schema::create(table: 'failed_jobs', callback: static function (Blueprint $table): void {
$table->id();
$table->string(column: 'uuid')->unique();
$table->text(column: 'connection');
Expand Down
10 changes: 5 additions & 5 deletions database/migrations/0001_01_01_000003_create_oauth_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
*/
public function up(): void
{
Schema::create(table: 'oauth_personal_access_clients', callback: function (Blueprint $table): void {
Schema::create(table: 'oauth_personal_access_clients', callback: static function (Blueprint $table): void {
$table->bigIncrements(column: 'id');
$table->uuid(column: 'client_id');
$table->timestamps();
});

Schema::create(table: 'oauth_auth_codes', callback: function (Blueprint $table): void {
Schema::create(table: 'oauth_auth_codes', callback: static function (Blueprint $table): void {
$table->string(column: 'id', length: 100)->primary();
$table->unsignedBigInteger(column: 'user_id')->index();
$table->uuid(column: 'client_id');
Expand All @@ -27,7 +27,7 @@ public function up(): void
$table->dateTime(column: 'expires_at')->nullable();
});

Schema::create(table: 'oauth_access_tokens', callback: function (Blueprint $table): void {
Schema::create(table: 'oauth_access_tokens', callback: static function (Blueprint $table): void {
$table->string(column: 'id', length: 100)->primary();
$table->unsignedBigInteger(column: 'user_id')->nullable()->index();
$table->uuid(column: 'client_id');
Expand All @@ -38,7 +38,7 @@ public function up(): void
$table->dateTime(column: 'expires_at')->nullable();
});

Schema::create(table: 'oauth_clients', callback: function (Blueprint $table): void {
Schema::create(table: 'oauth_clients', callback: static function (Blueprint $table): void {
$table->uuid(column: 'id')->primary();
$table->unsignedBigInteger(column: 'user_id')->nullable()->index();
$table->string(column: 'name');
Expand All @@ -51,7 +51,7 @@ public function up(): void
$table->timestamps();
});

Schema::create(table: 'oauth_refresh_tokens', callback: function (Blueprint $table): void {
Schema::create(table: 'oauth_refresh_tokens', callback: static function (Blueprint $table): void {
$table->string(column: 'id', length: 100)->primary();
$table->string(column: 'access_token_id', length: 100)->index();
$table->boolean(column: 'revoked');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
public function up(): void
{
Schema::create(table: 'tarfin_cards', callback: function (Blueprint $table): void {
Schema::create(table: 'tarfin_cards', callback: static function (Blueprint $table): void {
$table->id();

$table->foreignIdFor(model: User::class)->constrained();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
public function up(): void
{
Schema::create(table: 'tarfin_card_transactions', callback: function (Blueprint $table): void {
Schema::create(table: 'tarfin_card_transactions', callback: static function (Blueprint $table): void {
$table->id();

$table->foreignIdFor(model: TarfinCard::class)->constrained();
Expand Down

0 comments on commit 2b58355

Please sign in to comment.