Skip to content

Commit

Permalink
app(api-keys): add new expires_at column
Browse files Browse the repository at this point in the history
The `expires_at` column has been added as per Laravel Sanctum's
v3 upgrade guide.

ref; https://github.com/laravel/sanctum/blob/3.x/UPGRADE.md#new-expires_at-column
  • Loading branch information
matthewpi committed Feb 23, 2023
1 parent ea9c45b commit 6680f40
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/Models/ApiKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @property array|null $allowed_ips
* @property string|null $memo
* @property \Illuminate\Support\Carbon|null $last_used_at
* @property \Illuminate\Support\Carbon|null $expires_at
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int $r_servers
Expand Down Expand Up @@ -97,9 +98,10 @@ class ApiKey extends Model
protected $casts = [
'allowed_ips' => 'array',
'user_id' => 'int',
'last_used_at' => 'datetime',
'expires_at' => 'datetime',
self::CREATED_AT => 'datetime',
self::UPDATED_AT => 'datetime',
'last_used_at' => 'datetime',
'r_' . AdminAcl::RESOURCE_USERS => 'int',
'r_' . AdminAcl::RESOURCE_ALLOCATIONS => 'int',
'r_' . AdminAcl::RESOURCE_DATABASE_HOSTS => 'int',
Expand All @@ -120,6 +122,7 @@ class ApiKey extends Model
'allowed_ips',
'memo',
'last_used_at',
'expires_at',
];

/**
Expand All @@ -140,6 +143,7 @@ class ApiKey extends Model
'allowed_ips' => 'nullable|array',
'allowed_ips.*' => 'string',
'last_used_at' => 'nullable|date',
'expires_at' => 'nullable|date',
'r_' . AdminAcl::RESOURCE_USERS => 'integer|min:0|max:3',
'r_' . AdminAcl::RESOURCE_ALLOCATIONS => 'integer|min:0|max:3',
'r_' . AdminAcl::RESOURCE_DATABASE_HOSTS => 'integer|min:0|max:3',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('api_keys', function (Blueprint $table) {
$table->timestamp('expires_at')->nullable()->after('last_used_at');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('api_keys', function (Blueprint $table) {
$table->dropColumn('expires_at');
});
}
};

0 comments on commit 6680f40

Please sign in to comment.