forked from tempestphp/tempest-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDropConstraintStatement.php
More file actions
36 lines (29 loc) · 910 Bytes
/
DropConstraintStatement.php
File metadata and controls
36 lines (29 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
declare(strict_types=1);
namespace Tempest\Database\QueryStatements;
use Tempest\Database\Config\DatabaseDialect;
use Tempest\Database\QueryStatement;
final readonly class DropConstraintStatement implements QueryStatement
{
public function __construct(
private string $localTable,
private string $foreign,
) {}
public function compile(DatabaseDialect $dialect): string
{
[$foreignTable] = explode('.', $this->foreign);
$constraintName = sprintf(
'fk_%s_%s',
strtolower($foreignTable),
strtolower($this->localTable),
);
return match ($dialect) {
DatabaseDialect::MYSQL => sprintf(
'ALTER TABLE %s DROP CONSTRAINT %s',
$dialect->quoteIdentifier($foreignTable),
$constraintName,
),
default => '',
};
}
}