1 // Copyright 2011 Leo Przybylski. All rights reserved. 2 // 3 // Redistribution and use in source and binary forms, with or without modification, are 4 // permitted provided that the following conditions are met: 5 // 6 // 1. Redistributions of source code must retain the above copyright notice, this list of 7 // conditions and the following disclaimer. 8 // 9 // 2. Redistributions in binary form must reproduce the above copyright notice, this list 10 // of conditions and the following disclaimer in the documentation and/or other materials 11 // provided with the distribution. 12 // 13 // THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED 14 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 15 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR 16 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 18 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 19 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 20 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 21 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 // 23 // The views and conclusions contained in the software and documentation are those of the 24 // authors and should not be interpreted as representing official policies, either expressed 25 // or implied, of Leo Przybylski. 26 package liquibase.change.ext; 27 28 import liquibase.change.AbstractChange; 29 import liquibase.change.Change; 30 import liquibase.change.ChangeMetaData; 31 import liquibase.change.ColumnConfig; 32 import liquibase.database.Database; 33 import liquibase.database.core.DB2Database; 34 import liquibase.database.core.SQLiteDatabase; 35 import liquibase.database.core.SQLiteDatabase.AlterTableVisitor; 36 import liquibase.database.structure.Index; 37 import liquibase.statement.SqlStatement; 38 import liquibase.statement.core.AddPrimaryKeyStatement; 39 import liquibase.statement.core.ReorganizeTableStatement; 40 import liquibase.util.StringUtils; 41 42 import java.util.ArrayList; 43 import java.util.List; 44 45 import static liquibase.ext.Constants.EXTENSION_PRIORITY; 46 47 48 /** 49 * Overridden to ignore schema information 50 * 51 * @author Leo Przybylski (leo [at] rsmart.com) 52 */ 53 public class AddPrimaryKeyChange extends liquibase.change.core.AddPrimaryKeyChange { 54 55 public AddPrimaryKeyChange() { 56 setPriority(EXTENSION_PRIORITY); 57 } 58 59 @Override 60 public SqlStatement[] generateStatements(Database database) { 61 String schemaName = null; 62 63 AddPrimaryKeyStatement statement = new AddPrimaryKeyStatement(schemaName, getTableName(), getColumnNames(), getConstraintName()); 64 statement.setTablespace(getTablespace()); 65 66 if (database instanceof DB2Database) { 67 return new SqlStatement[]{ 68 statement, 69 new ReorganizeTableStatement(schemaName, getTableName()) 70 }; 71 //todo } else if (database instanceof SQLiteDatabase) { 72 // // return special statements for SQLite databases 73 // return generateStatementsForSQLiteDatabase(database); 74 } 75 76 return new SqlStatement[]{ 77 statement 78 }; 79 } 80 }