details: /erp/devel/dbsm-main/rev/20121bbd21c7
changeset: 285:20121bbd21c7
user: Antonio Moreno <antonio.moreno <at> openbravo.com>
date: Thu Mar 11 11:16:06 2010 +0100
summary: Fixed issue 12603. NOT NULL constraints will not be active when
copying data from the temporary table to the final one, when a table is
recreated. This will ensure that even if the column definition is incorrect
(ex. if it's mandatory, but doesn't have a default or onCreateDefault value),
the data is not lost.
details: /erp/devel/dbsm-main/rev/96cc585d5696
changeset: 286:96cc585d5696
user: Antonio Moreno <antonio.moreno <at> openbravo.com>
date: Fri Mar 12 17:16:15 2010 +0100
summary: Related to issue 12603. Activate the NOT NULLs in correct order
details: /erp/devel/dbsm-main/rev/cd149dc55cad
changeset: 287:cd149dc55cad
user: Antonio Moreno <antonio.moreno <at> openbravo.com>
date: Fri Mar 12 17:19:12 2010 +0100
summary: Fixed issue 12671. Temporary tables will be dropped before being
created again.
diffstat:
src/org/apache/ddlutils/platform/SqlBuilder.java | 9 +--
src/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java | 26
+---------
src/org/openbravo/ddlutils/task/AlterDatabaseDataMod.java | 2 +-
3 files changed, 5 insertions(+), 32 deletions(-)
diffs (109 lines):
diff -r f0ffeb5bb917 -r cd149dc55cad
src/org/apache/ddlutils/platform/SqlBuilder.java
--- a/src/org/apache/ddlutils/platform/SqlBuilder.java Thu Mar 11 09:40:50
2010 +0100
+++ b/src/org/apache/ddlutils/platform/SqlBuilder.java Fri Mar 12 17:19:12
2010 +0100
@@ -725,8 +725,6 @@
if (recreated) {
recreatedTables.add(desiredModel.getTable(i).getName());
if (newColumn) {
- Table tempTable = getTemporaryTableFor(desiredModel,
desiredModel.getTable(i));
- dropTemporaryTable(desiredModel, tempTable);
if (fullModel != null) {
// We have the full model. We will activate foreign keys pointing
to recreated tables
@@ -1640,8 +1638,7 @@
createTable(desiredModel, realTargetTable, parameters);
disableAllNOTNULLColumns(realTargetTable);
writeCopyDataStatement(tempTable, targetTable);
- if (!newColumn)
- dropTemporaryTable(desiredModel, tempTable);
+ dropTemporaryTable(desiredModel, tempTable);
recreatedTables.add(sourceTable.getName());
} else {
dropTable(sourceTable);
@@ -1752,7 +1749,7 @@
protected void disableAllNOTNULLColumns(Table table) throws IOException {
for (int i = 0; i < table.getColumnCount(); i++) {
Column column = table.getColumn(i);
- if (column.isRequired() && column.getOnCreateDefault() != null &&
!column.isPrimaryKey()
+ if (column.isRequired() && !column.isPrimaryKey()
&& !recreatedTables.contains(table.getName())) {
println("ALTER TABLE " + table.getName() + " MODIFY " +
getColumnName(column) + " "
+ getSqlType(column) + " NULL");
@@ -1777,7 +1774,7 @@
protected void enableAllNOTNULLColumns(Table table) throws IOException {
for (int i = 0; i < table.getColumnCount(); i++) {
Column column = table.getColumn(i);
- if (column.isRequired() && column.getOnCreateDefault() != null &&
!column.isPrimaryKey()) {
+ if (column.isRequired() && !column.isPrimaryKey()) {
println("ALTER TABLE " + table.getName() + " MODIFY " +
getColumnName(column) + " "
+ getSqlType(column) + " NOT NULL");
printEndOfStatement();
diff -r f0ffeb5bb917 -r cd149dc55cad
src/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java
--- a/src/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java
Thu Mar 11 09:40:50 2010 +0100
+++ b/src/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java
Fri Mar 12 17:19:12 2010 +0100
@@ -199,7 +199,7 @@
protected void disableAllNOTNULLColumns(Table table) throws IOException {
for (int i = 0; i < table.getColumnCount(); i++) {
Column column = table.getColumn(i);
- if (column.isRequired() && column.getOnCreateDefault() != null &&
!column.isPrimaryKey()
+ if (column.isRequired() && !column.isPrimaryKey()
&& !recreatedTables.contains(table.getName())) {
println("ALTER TABLE " + table.getName() + " ALTER " +
getColumnName(column)
+ " DROP NOT NULL");
@@ -209,18 +209,6 @@
}
}
- protected void disableNOTNULLColumns(Vector<AddColumnChange> newColumns)
throws IOException {
- for (int i = 0; i < newColumns.size(); i++) {
- Column column = newColumns.get(i).getNewColumn();
- if (column.isRequired()) {
- println("ALTER TABLE " + newColumns.get(i).getChangedTable().getName()
+ " ALTER "
- + getColumnName(column) + " DROP NOT NULL");
- printEndOfStatement();
- }
-
- }
- }
-
@Override
protected void disableTempNOTNULLColumns(Vector<AddColumnChange> newColumns)
throws IOException {
for (int i = 0; i < newColumns.size(); i++) {
@@ -246,18 +234,6 @@
}
}
- protected void enableNOTNULLColumns(Vector<AddColumnChange> newColumns)
throws IOException {
- for (int i = 0; i < newColumns.size(); i++) {
- Column column = newColumns.get(i).getNewColumn();
- if (column.isRequired() && column.getOnCreateDefault() != null &&
!column.isPrimaryKey()) {
- println("ALTER TABLE " + newColumns.get(i).getChangedTable().getName()
+ " ALTER "
- + getColumnName(column) + " SET NOT NULL");
- printEndOfStatement();
- }
-
- }
- }
-
/**
* Creates the auto-increment sequence that is then used in the column.
*
diff -r f0ffeb5bb917 -r cd149dc55cad
src/org/openbravo/ddlutils/task/AlterDatabaseDataMod.java
--- a/src/org/openbravo/ddlutils/task/AlterDatabaseDataMod.java Thu Mar 11
09:40:50 2010 +0100
+++ b/src/org/openbravo/ddlutils/task/AlterDatabaseDataMod.java Fri Mar 12
17:19:12 2010 +0100
@@ -306,7 +306,6 @@
}
getLog().info("Removing invalid rows.");
platform.deleteInvalidConstraintRows(completedb, !isFailonerror());
- platform.enableNOTNULLColumns(dbXML);
for (int i = 0; i < dataChanges.size(); i++) {
getLog().info("Executing update final script (NOT NULLs and dropping
temporary tables)");
platform.alterTablesPostScript(moduleOldModels.get(i),
moduleModels.get(i), !isFailonerror(),
@@ -314,6 +313,7 @@
}
platform.executeOnCreateDefaultForMandatoryColumns(dbXML);
getLog().info("Enabling Foreign Keys and Triggers");
+ platform.enableNOTNULLColumns(dbXML);
platform.enableAllFK(connection, dbAD, !isFailonerror());
platform.enableAllTriggers(connection, dbAD, !isFailonerror());
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits