com.atlassian.confluence.upgrade.upgradetask
Class AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask

java.lang.Object
  extended by com.atlassian.confluence.upgrade.AbstractUpgradeTask
      extended by com.atlassian.confluence.upgrade.upgradetask.AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask
All Implemented Interfaces:
DatabaseUpgradeTask, UpgradeTask

public class AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask
extends AbstractUpgradeTask
implements DatabaseUpgradeTask

This task adds a unique constraint to the AttachmentId column on the AttachmentData table. Having multiple records for the one attachment id is an invalid state that causes errors (CONF-7882). In order to create the constraint this task does the following:

  1. Deletes any attachmentdata records with no attachmentid.
  2. Whenever there are multiple attachmentdata records for the same attachmentid, deletes all but the one with the lowest attachmentid.
  3. For SQL Server only, removes all the indexes on the attachmentid column in the attachmentdata table.
  4. Adds a not-null constraint on the attachmentid table, since unique constraints must be not-null on some DBs.
  5. Adds the unique constraint on the attachmentid table.

This task does not need to run in an import or on setup of a new system because the constraints are included in the hibernate schema. It MUST run pre-upgrade because it relies on the SchemaHelper.updateSchemaIfNeeded() to re-create the indices in Sql Server. See dropIndicesFromSqlServer(ConfluenceHibernateConfig).


Constructor Summary
AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask(net.sf.hibernate.SessionFactory sessionFactory, AlterTableExecutor alterTableExecutor, DdlExecutor ddlExecutor, org.springframework.transaction.PlatformTransactionManager transactionManager)
           
 
Method Summary
 void doUpgrade()
          Perform the upgrade.
 String getBuildNumber()
           
 String getShortDescription()
          A short (<50 chars) description of the upgrade action
 
Methods inherited from class com.atlassian.confluence.upgrade.AbstractUpgradeTask
addAllErrors, addError, addError, getConstraint, getErrors, setBuildNumber, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.atlassian.confluence.upgrade.UpgradeTask
getConstraint, getErrors, validate
 

Constructor Detail

AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask

public AddUniqueAttachmentIdConstraintToAttachmentDataUpgradeTask(net.sf.hibernate.SessionFactory sessionFactory,
                                                                  AlterTableExecutor alterTableExecutor,
                                                                  DdlExecutor ddlExecutor,
                                                                  org.springframework.transaction.PlatformTransactionManager transactionManager)
Method Detail

getBuildNumber

public String getBuildNumber()
Specified by:
getBuildNumber in interface UpgradeTask
Overrides:
getBuildNumber in class AbstractUpgradeTask
Returns:
The build number that this upgrade is applicable to

getShortDescription

public String getShortDescription()
Description copied from interface: UpgradeTask
A short (<50 chars) description of the upgrade action

Specified by:
getShortDescription in interface UpgradeTask
Overrides:
getShortDescription in class AbstractUpgradeTask

doUpgrade

public void doUpgrade()
               throws Exception
Description copied from interface: UpgradeTask
Perform the upgrade.

Specified by:
doUpgrade in interface UpgradeTask
Throws:
Exception


Copyright © 2003-2013 Atlassian. All Rights Reserved.