packages/sql-semantics-mysql/src/Statement/Alter/Modifier/ValidationOption.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\MySql\Statement\Alter\Modifier;
6
7use SqlSemantics\Platform\MySql\Model\Construction\Derivation;
8use SqlSemantics\Platform\MySql\Model\Rendering\Output;
9use SqlSemantics\Platform\MySql\Model\Resolution\Environment;
10use SqlSemantics\Platform\MySql\Model\Statement\Snapshot;
11
12/**
13 * `WITH VALIDATION` or `WITHOUT VALIDATION` (5.7 and later): whether the server checks rows against generated columns or an exchanged partition.
14 *
15 * Source: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html,
16 * https://dev.mysql.com/doc/refman/8.4/en/partitioning-management-exchange.html.
17 *
18 * @visibility public
19 * @example Skipping the row validation
20 * (new \SqlSemantics\Platform\MySql\Statement\Alter\Modifier\ValidationOption(false))->validate // => false
21 */
22final class ValidationOption implements AlterModifier
23{
24 use Snapshot;
25
26 /**
27 * @param bool $validate Whether WITH (true) or WITHOUT (false) is written
28 */
29 public function __construct(public readonly bool $validate)
30 {
31 }
32
33 /**
34 * Derives nothing: the option holds no expression.
35 */
36 public function deriveCommand(Derivation $derivation, Environment $scope): void
37 {
38 }
39
40 /**
41 * Writes the option.
42 */
43 public function render(Output $out): void
44 {
45 $out->keyword($this->validate ? 'WITH' : 'WITHOUT', 'VALIDATION');
46 }
47}
48