public class PostgreSQLTableMigrator
extends java.lang.Object
This class is responsible for the structural table and column migration. It compares
the in-memory MyTISM schema (SchemaI) against the physical database schema and
computes the necessary DDL operations (CREATE TABLE, ALTER TABLE ADD/DROP/ALTER COLUMN)
to synchronize them.
It enforces the Separation of Concerns principle by:
PostgreSQLCatalogInspector.PostgreSQLInheritanceManager.PostgreSQLDDLBuilder to construct safe, SQL-injection-free queries.| Constructor and Description |
|---|
PostgreSQLTableMigrator(PostgreSQL pg,
PostgreSQLMigrationContext ctx,
PostgreSQLCatalogInspector inspector) |
| Modifier and Type | Method and Description |
|---|---|
void |
addSqlColumnsFromEntity(CBOEntityI entity,
java.util.List<PostgreSQLColumn> toAdd)
Adds the given new columns to the table for the entity via ALTER TABLE.
|
void |
assureColHasNotNullConstraint(CBOEntityI entity,
java.lang.String colName)
Ensures that the specified column has a "NOT NULL" constraint.
|
void |
checkConstraintNames(SchemaI schema)
Checks for ill-named constraints in the database and drops them if they
belong to an actively managed entity in the schema.
|
void |
checkTableColumnsForSchema(SchemaI schema,
java.lang.String remark,
boolean noAlter,
boolean nonDestructive)
Checks that the tables for all entities exist and contain the set of columns matching their current attributes and
creates them if required.
|
java.util.Map<java.lang.String,PostgreSQLColumn> |
getColumnsForEntity(CBOEntityI entity)
Gets the columns we *need* for the given entity according to the in-memory schema.
|
public PostgreSQLTableMigrator(PostgreSQL pg, PostgreSQLMigrationContext ctx, PostgreSQLCatalogInspector inspector)
public void checkConstraintNames(SchemaI schema)
schema - The target schema definition.public void checkTableColumnsForSchema(SchemaI schema, java.lang.String remark, boolean noAlter, boolean nonDestructive)
schema - the SchemaI whose entities should be usedremark - informative remark only added to the log messagesnoAlter - if true an already existing table for an entity will not be modified; only missing tables will
be creatednonDestructive - if true no existing columns will be removed or altered, only missing columns will be addedpublic void assureColHasNotNullConstraint(CBOEntityI entity, java.lang.String colName)
This method checks if the column with the given name in the table for the specified entity has a "NOT NULL" constraint. If the constraint is not present, it is added to the column definition.
entity - The entity for the table containing the column.colName - The name of the column to check.public void addSqlColumnsFromEntity(CBOEntityI entity, java.util.List<PostgreSQLColumn> toAdd)
entity - The entity whose table needs to be altered.toAdd - The list of missing columns to add.public java.util.Map<java.lang.String,PostgreSQLColumn> getColumnsForEntity(CBOEntityI entity)
entity - The entity definition to process.Copyright © 2000-2026 OAshi S.à r.l. All Rights Reserved.