packages/sql-semantics-postgres/src/Statement/Catalog/Database/RefreshDatabaseCollation.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\PostgreSql\Statement\Catalog\Database;
6
7use SqlSemantics\Platform\PostgreSql\Model\Construction\Derivation;
8use SqlSemantics\Platform\PostgreSql\Model\Contract\NameUse;
9use SqlSemantics\Platform\PostgreSql\Model\Rendering\Output;
10use SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name;
11use SqlSemantics\Platform\PostgreSql\Model\Statement\Snapshot;
12use SqlSemantics\Platform\PostgreSql\Model\Statement\Statement;
13
14/**
15 * A request to record the current collation version of a database: `ALTER DATABASE name REFRESH COLLATION VERSION`.
16 *
17 * Rule: PG-ALTERDB-003. Mirrors `AlterDatabaseRefreshCollStmt`.
18 * Source: https://www.postgresql.org/docs/17/sql-alterdatabase.html. Status: Implemented.
19 *
20 * @visibility public
21 * @example Reading the database
22 * $operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('ALTER DATABASE d REFRESH COLLATION VERSION');
23 * $operation->statement->name->value // => 'd'
24 */
25final class RefreshDatabaseCollation implements Statement
26{
27 use Snapshot;
28
29 /**
30 * @param Name $name The database name
31 */
32 public function __construct(public readonly Name $name)
33 {
34 }
35
36 /**
37 * Derives nothing: a database is not part of a declaration context.
38 */
39 public function deriveStatement(Derivation $derivation): void
40 {
41 }
42
43 /**
44 * Writes the request.
45 */
46 public function render(Output $out): void
47 {
48 $out->keyword('ALTER', 'DATABASE')->name($this->name, NameUse::Column)->keyword('REFRESH', 'COLLATION', 'VERSION');
49 }
50}
51