classAlterKinds
final class AlterKinds
Checks the actions of ALTER TABLE against the kind of the altered relation.
Rule: PG-ALTER-KIND-001. Each action accepts only some kinds of relation (ATPrepCmd / ATSimplePermissions): for example ADD COLUMN, DROP COLUMN, SET DATA TYPE, ADD CONSTRAINT and the trigger actions a base table or a foreign table; ALTER COLUMN ... SET DEFAULT and the identity actions also a view; SET STATISTICS, column SET/RESET and SET STORAGE also a materialized view; SET ( storage parameters ) a base table, a view or a materialized view; SET LOGGED and SET UNLOGGED a base table or a sequence; the OPTIONS actions only a foreign table; ADD CONSTRAINT ... USING INDEX, ALTER CONSTRAINT, OF, NOT OF, the row security and rule actions and the partition actions only a base table; OWNER TO every kind. An action on a relation of another declared kind is reported as ALTER action %s cannot be performed on relation "%s" with the server's name for the action. The parent of INHERIT and NO INHERIT must itself be a base table or a foreign table, and a foreign table takes no primary key, unique, exclusion or foreign key constraint. Source: https://www.postgresql.org/docs/17/sql-altertable.html, tablecmds.c (ATPrepCmd, alter_table_type_to_string, ATExecAddInherit). Termination: one check per action. Status: Implemented.
Methods§
public function check(
Derivation $derivation,
?RelationKind $kind,
Name $relation,
list<AlterCommand> $commands,
): voidReports the actions the declared kind of the relation does not accept.
Parameters
$derivation | Derivation | |
$kind | ?RelationKind | |
$relation | Name | |
$commands | list<AlterCommand> |
Called from 1
Calls 6
- method-call AlterKinds::accepted() line 91
- function-call
in_arrayline 92 - method-call Derivation::report() line 93
- new KindProblem line 93
- class-const KindRule::AlterAction() line 93
- method-call AlterKinds::parent() line 98
public function foreign(Derivation $derivation, list<AlterCommand> $commands): voidReports the constraints the added columns and constraints would give a foreign table (PG-RELATION-KIND-001).
Parameters
$derivation | Derivation | |
$commands | list<AlterCommand> |
Called from 1
Calls 2
- method-call RelationKinds::foreign() line 118
- new RelationKinds line 118
public function parent(Derivation $derivation, InheritanceChange $command): voidReports a new parent of INHERIT that is neither a base table nor a foreign table.
Parameters
$derivation | Derivation | |
$command | InheritanceChange |
Called from 1
Calls 8
- method-call RelationKinds::declared() line 126
- new RelationKinds line 126
- function-call
in_arrayline 127 - class-const AlterKinds::TABLE_OR_FOREIGN() line 127
- method-call Derivation::report() line 128
- new KindProblem line 128
- class-const KindRule::AlterAction() line 128
- class-const AlterAction::Inherit() line 128
public function accepted(AlterCommand $command): array{AlterAction, list<RelationKind>}|nullAnswers the server's name of an action and the kinds of relation it accepts; null for an action every kind accepts.
Parameters
$command | AlterCommand |
Returns
array{AlterAction, list<RelationKind>}|nullTest cases 2
Called from 1
Calls 4
- method-call AlterKinds::column() line 140
- method-call AlterKinds::table() line 141
- method-call AlterKinds::named() line 142
- method-call AlterKinds::other() line 143
public function other(AlterCommand $command): array{AlterAction, list<RelationKind>}|nullAnswers the name and the accepted kinds of the actions that are neither column, table nor named actions.
Parameters
$command | AlterCommand |
Returns
array{AlterAction, list<RelationKind>}|nullTest cases 1
Called from 1
Calls 18
- class-const AlterAction::AddColumn() line 155
- class-const AlterKinds::TABLE_OR_FOREIGN() line 155
- class-const AlterAction::DropColumn() line 156
- class-const AlterAction::SetDataType() line 157
- class-const AlterAction::SetDefault() line 158
- class-const AlterKinds::TABLE_VIEW_OR_FOREIGN() line 158
- class-const AlterAction::AddIdentity() line 159
- class-const AlterAction::SetColumnAttributes() line 160
- class-const AlterAction::SetExpression() line 161
- class-const AlterAction::SetStatistics() line 162
- class-const AlterKinds::TABLE_MATERIALIZED_OR_FOREIGN() line 162
- class-const AlterAction::ResetOptions() line 163
- class-const AlterAction::SetStorage() line 164
- class-const AlterAction::SetCompression() line 164
- class-const AlterKinds::TABLE_OR_MATERIALIZED() line 164
- class-const AlterAction::ColumnOptions() line 165
- class-const RelationKind::ForeignTable() line 165
- method-call AlterKinds::relationWide() line 166
public function relationWide(AlterCommand $command): array{AlterAction, list<RelationKind>}|nullAnswers the name and the accepted kinds of the actions on the relation as a whole.
Parameters
$command | AlterCommand |
Returns
array{AlterAction, list<RelationKind>}|nullTest cases 1
Called from 1
Calls 22
- class-const AlterAction::AddConstraint() line 178
- class-const AlterKinds::TABLE() line 178
- class-const AlterKinds::TABLE_OR_FOREIGN() line 178
- class-const AlterAction::DropConstraint() line 179
- class-const AlterAction::AlterConstraint() line 180
- class-const AlterAction::NoInherit() line 181
- class-const AlterAction::Inherit() line 181
- class-const AlterAction::Of() line 182
- class-const AlterAction::ReplicaIdentity() line 183
- class-const AlterKinds::TABLE_OR_MATERIALIZED() line 183
- class-const AlterAction::ResetRelationOptions() line 184
- class-const AlterAction::SetRelationOptions() line 184
- class-const RelationKind::BaseTable() line 184
- class-const RelationKind::View() line 184
- class-const RelationKind::MaterializedView() line 184
- class-const AlterAction::SetAccessMethod() line 185
- class-const AlterAction::Options() line 186
- class-const RelationKind::ForeignTable() line 186
- class-const AlterAction::AttachPartition() line 187
- class-const DetachMode::Finalize() line 189
- class-const AlterAction::DetachPartitionFinalize() line 189
- class-const AlterAction::DetachPartition() line 189
public function column(ColumnActionKind $kind): array{AlterAction, list<RelationKind>}Answers the name and the accepted kinds of a column action without operand.
Parameters
$kind | ColumnActionKind |
Returns
array{AlterAction, list<RelationKind>}Test cases 1
Called from 1
Calls 14
- class-const ColumnActionKind::SetNotNull() line 202
- class-const AlterAction::SetNotNull() line 202
- class-const AlterKinds::TABLE_OR_FOREIGN() line 202
- class-const ColumnActionKind::DropNotNull() line 203
- class-const AlterAction::DropNotNull() line 203
- class-const ColumnActionKind::DropDefault() line 204
- class-const AlterAction::SetDefault() line 204
- class-const AlterKinds::TABLE_VIEW_OR_FOREIGN() line 204
- class-const ColumnActionKind::DropExpression() line 205
- class-const ColumnActionKind::DropExpressionIfExists() line 205
- class-const AlterAction::DropExpression() line 205
- class-const ColumnActionKind::DropIdentity() line 206
- class-const ColumnActionKind::DropIdentityIfExists() line 206
- class-const AlterAction::DropIdentity() line 206
public function table(TableActionKind $kind): array{AlterAction, list<RelationKind>}Answers the name and the accepted kinds of an action on the relation without operand.
Parameters
$kind | TableActionKind |
Returns
array{AlterAction, list<RelationKind>}Test cases 1
Called from 1
Calls 31
- class-const TableActionKind::SetWithoutOids() line 218
- class-const AlterAction::SetWithoutOids() line 218
- class-const AlterKinds::TABLE_OR_FOREIGN() line 218
- class-const TableActionKind::SetWithoutCluster() line 219
- class-const AlterAction::SetWithoutCluster() line 219
- class-const AlterKinds::TABLE_OR_MATERIALIZED() line 219
- class-const TableActionKind::SetLogged() line 220
- class-const AlterAction::SetLogged() line 220
- class-const RelationKind::BaseTable() line 220
- class-const RelationKind::Sequence() line 220
- class-const TableActionKind::SetUnlogged() line 221
- class-const AlterAction::SetUnlogged() line 221
- class-const TableActionKind::NotOf() line 222
- class-const AlterAction::NotOf() line 222
- class-const AlterKinds::TABLE() line 222
- class-const TableActionKind::EnableRowSecurity() line 223
- class-const AlterAction::EnableRowSecurity() line 223
- class-const TableActionKind::DisableRowSecurity() line 224
- class-const AlterAction::DisableRowSecurity() line 224
- class-const TableActionKind::ForceRowSecurity() line 225
- class-const AlterAction::ForceRowSecurity() line 225
- class-const TableActionKind::NoForceRowSecurity() line 226
- class-const AlterAction::NoForceRowSecurity() line 226
- class-const TableActionKind::EnableAllTriggers() line 227
- class-const AlterAction::EnableAllTriggers() line 227
- class-const TableActionKind::EnableUserTriggers() line 228
- class-const AlterAction::EnableUserTriggers() line 228
- class-const TableActionKind::DisableAllTriggers() line 229
- class-const AlterAction::DisableAllTriggers() line 229
- class-const TableActionKind::DisableUserTriggers() line 230
- class-const AlterAction::DisableUserTriggers() line 230
public function named(NamedActionKind $kind): array{AlterAction, list<RelationKind>}Answers the name and the accepted kinds of an action on a named object of the relation.
Parameters
$kind | NamedActionKind |
Returns
array{AlterAction, list<RelationKind>}Test cases 1
Called from 1
Calls 25
- class-const NamedActionKind::ClusterOn() line 242
- class-const AlterAction::ClusterOn() line 242
- class-const AlterKinds::TABLE_OR_MATERIALIZED() line 242
- class-const NamedActionKind::ValidateConstraint() line 243
- class-const AlterAction::ValidateConstraint() line 243
- class-const AlterKinds::TABLE_OR_FOREIGN() line 243
- class-const NamedActionKind::SetTablespace() line 244
- class-const AlterAction::SetTablespace() line 244
- class-const NamedActionKind::EnableTrigger() line 245
- class-const AlterAction::EnableTrigger() line 245
- class-const NamedActionKind::EnableAlwaysTrigger() line 246
- class-const AlterAction::EnableAlwaysTrigger() line 246
- class-const NamedActionKind::EnableReplicaTrigger() line 247
- class-const AlterAction::EnableReplicaTrigger() line 247
- class-const NamedActionKind::DisableTrigger() line 248
- class-const AlterAction::DisableTrigger() line 248
- class-const NamedActionKind::EnableRule() line 249
- class-const AlterAction::EnableRule() line 249
- class-const AlterKinds::TABLE() line 249
- class-const NamedActionKind::EnableAlwaysRule() line 250
- class-const AlterAction::EnableAlwaysRule() line 250
- class-const NamedActionKind::EnableReplicaRule() line 251
- class-const AlterAction::EnableReplicaRule() line 251
- class-const NamedActionKind::DisableRule() line 252
- class-const AlterAction::DisableRule() line 252
Private surface 5§
Implementation details, listed for orientation only.
private const TABLE = [\SqlSemantics\Platform\PostgreSql\Model\Statement\Declaration\RelationKind::Ba…private const TABLE_OR_FOREIGN = [\SqlSemantics\Platform\PostgreSql\Model\Statement\Declaration\RelationKind::Ba…private const TABLE_VIEW_OR_FOREIGN = [\SqlSemantics\Platform\PostgreSql\Model\Statement\Declaration\RelationKind::Ba…private const TABLE_OR_MATERIALIZED = [\SqlSemantics\Platform\PostgreSql\Model\Statement\Declaration\RelationKind::Ba…private const TABLE_MATERIALIZED_OR_FOREIGN = [\SqlSemantics\Platform\PostgreSql\Model\Statement\Declaration\RelationKind::Ba…Test cases 6§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 6
AlterKindsTest::testAcceptedAnswersNullForOwnerTocallsAlterKindsTest::testColumnAnswersTheActionOfAColumnActioncallsAlterKindsTest::testNamedAnswersTheActionOfANamedActioncallsAlterKindsTest::testOtherAnswersTheActionOfAColumnChangecallsAlterKindsTest::testRelationWideAnswersTheActionOfARelationOptioncallsAlterKindsTest::testTableAnswersTheActionOfATableActioncalls
Relations§
Instantiated in 2
- new SqlSemantics\Platform\PostgreSql\Rules\Table\Command\Alterations::derive() packages/sql-semantics-postgres/src/Rules/Table/Command/Alterations.php:71
- new SqlSemantics\Platform\PostgreSql\Rules\Table\Command\Alterations::derive() packages/sql-semantics-postgres/src/Rules/Table/Command/Alterations.php:74
Method calls 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Table\Command\Alterations::derive() packages/sql-semantics-postgres/src/Rules/Table/Command/Alterations.php:71
- method-call SqlSemantics\Platform\PostgreSql\Rules\Table\Command\Alterations::derive() packages/sql-semantics-postgres/src/Rules/Table/Command/Alterations.php:74