fix(db): SSL certificates table and model

- server_id is a foreign id
- server_id must be unique as each server can only have 1 CA cert
- resource_id must be unique as each resource can only have 1 SSL cert
This commit is contained in:
peaklabs-dev
2025-01-31 12:35:34 +01:00
parent 0915303769
commit 34216af497
2 changed files with 10 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ class SslCertificate extends Model
'ssl_private_key',
'resource_type',
'resource_id',
'server_id',
'valid_until',
];
@@ -24,4 +25,9 @@ class SslCertificate extends Model
{
return $this->morphTo();
}
public function server()
{
return $this->belongsTo(Server::class);
}
}

View File

@@ -14,10 +14,12 @@ return new class extends Migration
$table->text('ssl_private_key');
$table->string('resource_type')->nullable();
$table->unsignedBigInteger('resource_id')->nullable();
$table->timestamp('valid_until')->nullable();
$table->unsignedBigInteger('server_id')->nullable();
$table->timestamp('valid_until');
$table->timestamps();
$table->index(['resource_type', 'resource_id']);
$table->foreign('server_id')->references('id')->on('servers');
$table->unique(['server_id', 'resource_id']);
});
}