packages/sql-semantics-mysql/src/Statement/Server/Storage/DropLogfileGroup.php

1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\MySql\Statement\Server\Storage;
6
7use SqlSemantics\Platform\MySql\Model\Construction\Derivation;
8use SqlSemantics\Platform\MySql\Model\Contract\NameUse;
9use SqlSemantics\Platform\MySql\Model\Rendering\Output;
10use SqlSemantics\Platform\MySql\Model\Statement\Identifier\Name;
11use SqlSemantics\Platform\MySql\Model\Statement\Snapshot;
12use SqlSemantics\Platform\MySql\Model\Statement\Statement;
13use SqlSemantics\Platform\MySql\Rules\Server\StorageOptions;
14use SqlSemantics\Platform\MySql\Statement\Server\Storage\Option\StorageOption;
15
16/**
17 * `DROP LOGFILE GROUP name [option …]`: a request to remove an NDB log file group.
18 *
19 * Mirrors PT_drop_logfile_group and the DROP_LOGFILE_GROUP command of st_alter_tablespace in MySQL 5.x. Rule: MYSQL-DROP-LOGFILE-GROUP-001.  The options are checked,
20 * kept and written in order by MYSQL-STORAGE-OPTIONS-001. A log file group is
21 * no relation, so the statement neither declares nor resolves one.
22 * Source: https://dev.mysql.com/doc/refman/8.4/en/drop-logfile-group.html.
23 * Status: Implemented.
24 *
25 * @visibility public
26 * @example Removing a log file group
27 *     $statement = (new \SqlSemantics\Platform\MySql\Semantics())->analyze("drop logfile group lg engine ndb");
28 *     [$statement->toString(), $statement->statement->name->value] // => ["DROP LOGFILE GROUP lg ENGINE `ndb`", 'lg']
29 */
30final class DropLogfileGroup implements Statement
31{
32    use Snapshot;
33
34    /**
35     * @var list<StorageOption> The options in written order
36     */
37    public readonly array $options;
38
39    /**
40     * @param Name $name The log file group name
41     * @param list<StorageOption> $options The options in written order
42     */
43    public function __construct(public readonly Name $name, array $options = [])
44    {
45        $this->options = (new StorageOptions())->checked($options, StorageOptions::DROP);
46    }
47
48    /**
49     * Reports the options the server rejects while it parses the statement.
50     */
51    public function deriveStatement(Derivation $derivation): void
52    {
53        (new StorageOptions())->derive($derivation, $this->options);
54    }
55
56    /**
57     * Writes the request.
58     */
59    public function render(Output $out): void
60    {
61        $out->keyword('DROP', 'LOGFILE', 'GROUP')->name($this->name, NameUse::Identifier);
62        (new StorageOptions())->render($out, $this->options);
63    }
64}
65