Top Description Fields Constructors Methods
liquibase.change.core

public Class AddForeignKeyConstraintChange

extends AbstractChange
Class Inheritance
Annotations
@DatabaseChange
name:addForeignKeyConstraint
description:Adds a foreign key constraint to an existing column
priority:1
appliesTo:column
Imports
liquibase.change.*, liquibase.database.Database, .DatabaseFactory, liquibase.exception.UnexpectedLiquibaseException, liquibase.snapshot.SnapshotGeneratorFactory, liquibase.statement.SqlStatement, liquibase.statement.core.AddForeignKeyConstraintStatement, liquibase.structure.core.Column, .ForeignKey, .ForeignKeyConstraintType, .Table, java.util.ArrayList, .List

Adds a foreign key constraint to an existing column.

Field Summary

Modifier and TypeField and Description
private String
private String
private String
private String
private String
private Boolean
private Boolean
private String
private String
private String
private String
private String
private String
private Boolean
Inherited from liquibase.change.AbstractChange:
NODENAME_COLUMN

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private boolean
public ChangeStatus
checkStatus(Database database)

Overrides liquibase.change.AbstractChange.checkStatus.

Implements liquibase.change.Change.checkStatus.

Validate that this change executed successfully against the given database.

protected Change[]
createInverses()

Overrides liquibase.change.AbstractChange.createInverses.

Create inverse changes that can roll back this change.

protected String[]
public SqlStatement[]
generateStatements(Database database)

Implements liquibase.change.Change.generateStatements.

Generates the SqlStatement objects required to run the change for the given database.

public String
public String
public String
public String
public String
getConfirmationMessage()

Implements liquibase.change.Change.getConfirmationMessage.

Confirmation message to be displayed after the change is executed.

public String
public Boolean
public Boolean
getDeleteCascade()
Deprecated Use getOnDelete().

public Boolean
public String
public String
public String
public String
public String
public String
public Boolean
getReferencesUniqueColumn()
Deprecated No longer supported in 3.0

public String
public Boolean

Returns:

true if ENABLE VALIDATE (this is the default), or false if ENABLE NOVALIDATE.
getValidate
()

the VALIDATE keyword defines whether to check if a foreign key constraint on a column in a table refers to a valid row or not.

public void
setBaseColumnNames(String baseColumnNames)

public void
setBaseTableCatalogName(String baseTableCatalogName)

public void
setBaseTableName(String baseTableName)

public void
setBaseTableSchemaName(String baseTableSchemaName)

public void
setConstraintName(String constraintName)

public void
setDeferrable(Boolean deferrable)

public void
setDeleteCascade(Boolean deleteCascade)

public void
setInitiallyDeferred(Boolean initiallyDeferred)

public void
setOnDelete(String onDelete)

public void
public void
public void
public void
setReferencedColumnNames(String referencedColumnNames)

public void
setReferencedTableCatalogName(String referencedTableCatalogName)

public void
setReferencedTableName(String referencedTableName)

public void
setReferencedTableSchemaName(String referencedTableSchemaName)

public void
setReferencesUniqueColumn(Boolean referencesUniqueColumn)

public void
setValidate(Boolean
- if shouldValidate is set to FALSE then the constraint will be created with the 'ENABLE NOVALIDATE' mode. This means the constraint would be created, but that no check will be done to ensure old data has valid foreign keys - only new data would be checked to see if it complies with the constraint logic. The default state for foreign keys is to have 'ENABLE VALIDATE' set.
shouldValidate
)

Inherited from liquibase.change.AbstractChange:
createChangeMetaDatacreateChangeParameterMetadatacreateDescriptionMetaDatacreateEmptyColumnConfigcreateExampleValueMetaDatacreateMustEqualExistingMetaDatacreateRequiredDatabasesMetaDatacreateSerializationTypeMetaDatacreateSinceMetaDatacustomLoadLogicequalsfinishInitializationgenerateCheckSumgenerateRollbackStatementsgenerateRollbackStatementsVolatilegenerateStatementsVolatilegetAffectedDatabaseObjectsgetChangeSetgetDescriptiongetExcludedFieldFiltersgetResourceAccessorgetSerializableFieldNamespacegetSerializableFieldsgetSerializableFieldTypegetSerializableFieldValuegetSerializedObjectNamehashCodeisInvalidPropertyloadmodifyserializeserializeValuesetChangeSetsetResourceAccessorshouldExecuteChangesupportssupportsRollbacktoStringvalidatewarn

Field Detail

baseColumnNamesback to summary
private String baseColumnNames
baseTableCatalogNameback to summary
private String baseTableCatalogName
baseTableNameback to summary
private String baseTableName
baseTableSchemaNameback to summary
private String baseTableSchemaName
constraintNameback to summary
private String constraintName
deferrableback to summary
private Boolean deferrable
initiallyDeferredback to summary
private Boolean initiallyDeferred
onDeleteback to summary
private String onDelete
onUpdateback to summary
private String onUpdate
referencedColumnNamesback to summary
private String referencedColumnNames
referencedTableCatalogNameback to summary
private String referencedTableCatalogName
referencedTableNameback to summary
private String referencedTableName
referencedTableSchemaNameback to summary
private String referencedTableSchemaName
shouldValidateback to summary
private Boolean shouldValidate

Constructor Detail

AddForeignKeyConstraintChangeback to summary
public AddForeignKeyConstraintChange()

Method Detail

checkDefferableback to summary
private boolean checkDefferable(Database database)
checkStatusback to summary
public ChangeStatus checkStatus(Database database)

Overrides liquibase.change.AbstractChange.checkStatus.

Implements liquibase.change.Change.checkStatus.

Doc from liquibase.change.Change.checkStatus.

Validate that this change executed successfully against the given database. This will check that the update completed at a high level plus check details of the change. For example, a change to add a column will check that the column exists plus data type, default values, etc.

Annotations
@Override
createInversesback to summary
protected Change[] createInverses()

Overrides liquibase.change.AbstractChange.createInverses.

Doc from liquibase.change.AbstractChange.createInverses.

Create inverse changes that can roll back this change. This method is intended to be overridden by Change implementations that have a logical inverse operation. Default implementation returns null.

If generateRollbackStatements(liquibase.database.Database) is overridden, this method may not be called.

Returns:Change[]

Return null if there is no corresponding inverse and therefore automatic rollback is not possible. Return an empty array to have a no-op rollback.

Annotations
@Override
createSupportedDatabasesMetaDataback to summary
protected String[] createSupportedDatabasesMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)

Overrides liquibase.change.AbstractChange.createSupportedDatabasesMetaData.

Doc from liquibase.change.AbstractChange.createSupportedDatabasesMetaData.

Create the ChangeParameterMetaData "supportedDatabase" value. Uses the value on the DatabaseChangeProperty annotation or returns an array containing the string "COMPUTE" as a default. "COMPUTE" will cause ChangeParameterMetaData to attempt to determine the required databases based on the generated Statements

Annotations
@Override
generateStatementsback to summary
public SqlStatement[] generateStatements(Database database)

Implements liquibase.change.Change.generateStatements.

Doc from liquibase.change.Change.generateStatements.

Generates the SqlStatement objects required to run the change for the given database.

NOTE: This method may be called multiple times throughout the changelog execution process and may be called in documentation generation and other integration points as well.

If this method reads from the current database state or uses any other logic that will be affected by whether previous changeSets have ran or not, you must return true from generateStatementsVolatile.
Annotations
@Override
getBaseColumnNamesback to summary
public String getBaseColumnNames()
Annotations
@DatabaseChangeProperty
description:Name of the column(s) to place the foreign key constraint on. Comma-separate if multiple
exampleValue:person_id
mustEqualExisting:column
getBaseTableCatalogNameback to summary
public String getBaseTableCatalogName()
Annotations
@DatabaseChangeProperty
since:3.0
mustEqualExisting:column.relation.catalog
description:Name of the database catalog of the base table
getBaseTableNameback to summary
public String getBaseTableName()
Annotations
@DatabaseChangeProperty
description:Name of the table containing the column to constrain
exampleValue:address
mustEqualExisting:column.relation
getBaseTableSchemaNameback to summary
public String getBaseTableSchemaName()
Annotations
@DatabaseChangeProperty
mustEqualExisting:column.relation.schema
description:Name of the database schema of the base table
getConfirmationMessageback to summary
public String getConfirmationMessage()

Implements liquibase.change.Change.getConfirmationMessage.

Doc from liquibase.change.Change.getConfirmationMessage.

Confirmation message to be displayed after the change is executed. Should include relevant configuration settings to make it as helpful as possible. This method may be called outside the changelog execution process, such as in documentation generation.

Annotations
@Override
getConstraintNameback to summary
public String getConstraintName()
Annotations
@DatabaseChangeProperty
description:Name of the new foreign key constraint
exampleValue:fk_address_person
getDeferrableback to summary
public Boolean getDeferrable()
Annotations
@DatabaseChangeProperty
description:Defines whether the foreign key is deferrable
getDeleteCascadeback to summary
public Boolean getDeleteCascade()

Deprecated

Use getOnDelete(). This always returns null so it doesn't impact checksums when settings onDelete vs. deleteCascade

Annotations
@DatabaseChangeProperty
description:Deprecated. This is true to set onDelete to Cascade, priority given to onDelete tag if one exists
getInitiallyDeferredback to summary
public Boolean getInitiallyDeferred()
Annotations
@DatabaseChangeProperty
description:Defines whether the foreign key is initially deferred
getOnDeleteback to summary
public String getOnDelete()
Annotations
@DatabaseChangeProperty
description:ON DELETE functionality. Possible values: \'CASCADE\', \'SET NULL\', \'SET DEFAULT\', \'RESTRICT\', \'NO ACTION\'
exampleValue:CASCADE
getOnUpdateback to summary
public String getOnUpdate()
Annotations
@DatabaseChangeProperty
description:ON UPDATE functionality. Possible values: \'CASCADE\', \'SET NULL\', \'SET DEFAULT\', \'RESTRICT\', \'NO ACTION\'
exampleValue:RESTRICT
getReferencedColumnNamesback to summary
public String getReferencedColumnNames()
Annotations
@DatabaseChangeProperty
description:Name of the column(s) the foreign key points to. Comma-separate if multiple
exampleValue:id
getReferencedTableCatalogNameback to summary
public String getReferencedTableCatalogName()
Annotations
@DatabaseChangeProperty
since:3.0
mustEqualExisting:column
description:Name of the database catalog of the referenced table
getReferencedTableNameback to summary
public String getReferencedTableName()
Annotations
@DatabaseChangeProperty
description:Name of the table the foreign key points to
exampleValue:person
getReferencedTableSchemaNameback to summary
public String getReferencedTableSchemaName()
Annotations
@DatabaseChangeProperty
description:Name of the database schema of the referenced table
getReferencesUniqueColumnback to summary
public Boolean getReferencesUniqueColumn()

Deprecated

No longer supported in 3.0

Annotations
@Deprecated
@DatabaseChangeProperty
description:Deprecated
getSerializedObjectNamespaceback to summary
public String getSerializedObjectNamespace()

Overrides liquibase.change.AbstractChange.getSerializedObjectNamespace.

Implements liquibase.serializer.LiquibaseSerializable.getSerializedObjectNamespace.

Annotations
@Override
getValidateback to summary
public Boolean getValidate()

the VALIDATE keyword defines whether to check if a foreign key constraint on a column in a table refers to a valid row or not.

Returns:Boolean

true if ENABLE VALIDATE (this is the default), or false if ENABLE NOVALIDATE.

Annotations
@DatabaseChangeProperty
description:Defines whether to check if the foreign key constraint refers to a valid row. This is true if the foreign key has \'ENABLE VALIDATE\' set, or false if the foreign key has \'ENABLE NOVALIDATE\' set.
setBaseColumnNamesback to summary
public void setBaseColumnNames(String baseColumnNames)
setBaseTableCatalogNameback to summary
public void setBaseTableCatalogName(String baseTableCatalogName)
setBaseTableNameback to summary
public void setBaseTableName(String baseTableName)
setBaseTableSchemaNameback to summary
public void setBaseTableSchemaName(String baseTableSchemaName)
setConstraintNameback to summary
public void setConstraintName(String constraintName)
setDeferrableback to summary
public void setDeferrable(Boolean deferrable)
setDeleteCascadeback to summary
public void setDeleteCascade(Boolean deleteCascade)
setInitiallyDeferredback to summary
public void setInitiallyDeferred(Boolean initiallyDeferred)
setOnDeleteback to summary
public void setOnDelete(String onDelete)
setOnDeleteback to summary
public void setOnDelete(ForeignKeyConstraintType rule)
setOnUpdateback to summary
public void setOnUpdate(String rule)
setOnUpdateback to summary
public void setOnUpdate(ForeignKeyConstraintType rule)
setReferencedColumnNamesback to summary
public void setReferencedColumnNames(String referencedColumnNames)
setReferencedTableCatalogNameback to summary
public void setReferencedTableCatalogName(String referencedTableCatalogName)
setReferencedTableNameback to summary
public void setReferencedTableName(String referencedTableName)
setReferencedTableSchemaNameback to summary
public void setReferencedTableSchemaName(String referencedTableSchemaName)
setReferencesUniqueColumnback to summary
public void setReferencesUniqueColumn(Boolean referencesUniqueColumn)
setValidateback to summary
public void setValidate(Boolean shouldValidate)
Parameters
shouldValidate:Boolean

- if shouldValidate is set to FALSE then the constraint will be created with the 'ENABLE NOVALIDATE' mode. This means the constraint would be created, but that no check will be done to ensure old data has valid foreign keys - only new data would be checked to see if it complies with the constraint logic. The default state for foreign keys is to have 'ENABLE VALIDATE' set.