FR [ 1829798 ] Easy generation of migration scripts
This commit is contained in:
parent
04ee2be595
commit
4feb03df69
|
@ -346,6 +346,7 @@ public class DB_Oracle implements AdempiereDatabase
|
|||
*/
|
||||
public String convertStatement (String oraStatement)
|
||||
{
|
||||
Convert.logMigrationScript(oraStatement, null);
|
||||
return oraStatement;
|
||||
} // convertStatement
|
||||
|
||||
|
|
|
@ -318,6 +318,7 @@ public class DB_PostgreSQL implements AdempiereDatabase
|
|||
log.log(Level.FINER, "PostgreSQL =>" + retValue[0] + "<= <" + oraStatement + ">");
|
||||
//end vpj-cd 24/06/2005 e-evolution
|
||||
//
|
||||
Convert.logMigrationScript(oraStatement, retValue[0]);
|
||||
return retValue[0];
|
||||
} // convertStatement
|
||||
|
||||
|
|
|
@ -16,10 +16,15 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.dbPort;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLWarning;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
@ -27,7 +32,10 @@ import java.util.Vector;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.compiere.model.MSysConfig;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Ini;
|
||||
|
||||
/**
|
||||
* Convert SQL to Target DB
|
||||
|
@ -54,7 +62,12 @@ public abstract class Convert
|
|||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger (Convert.class);
|
||||
|
||||
/**
|
||||
private static FileOutputStream tempFileOr = null;
|
||||
private static DataOutputStream osOr;
|
||||
private static FileOutputStream tempFilePg = null;
|
||||
private static DataOutputStream osPg;
|
||||
|
||||
/**
|
||||
* Set Verbose
|
||||
* @param verbose
|
||||
*/
|
||||
|
@ -397,5 +410,124 @@ public abstract class Convert
|
|||
* @return boolean
|
||||
*/
|
||||
public abstract boolean isOracle();
|
||||
|
||||
} // Convert
|
||||
|
||||
public static void logMigrationScript(String oraStatement, String pgStatement) {
|
||||
// Check AdempiereSys
|
||||
// check property Log migration script
|
||||
boolean logMigrationScript = Ini.isPropertyBool(Ini.P_LOGMIGRATIONSCRIPT);
|
||||
if (logMigrationScript) {
|
||||
if (dontLog(oraStatement))
|
||||
return;
|
||||
// Log oracle and postgres migration scripts in temp directory
|
||||
// migration_script_oracle.sql and migration_script_postgresql.sql
|
||||
try {
|
||||
if (tempFileOr == null) {
|
||||
String fileNameOr = System.getProperty("java.io.tmpdir")
|
||||
+ System.getProperty("file.separator")
|
||||
+ "migration_script_oracle.sql";
|
||||
tempFileOr = new FileOutputStream(fileNameOr, true);
|
||||
osOr = new DataOutputStream(tempFileOr);
|
||||
}
|
||||
writeLogMigrationScript(osOr, oraStatement);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
if (pgStatement == null) {
|
||||
// if oracle call convert for postgres before logging
|
||||
Convert_PostgreSQL convert = new Convert_PostgreSQL();
|
||||
String[] r = convert.convert(oraStatement);
|
||||
pgStatement = r[0];
|
||||
}
|
||||
if (tempFilePg == null) {
|
||||
String fileNamePg = System.getProperty("java.io.tmpdir")
|
||||
+ System.getProperty("file.separator")
|
||||
+ "migration_script_postgresql.sql";
|
||||
tempFilePg = new FileOutputStream(fileNamePg, true);
|
||||
osPg = new DataOutputStream(tempFilePg);
|
||||
}
|
||||
writeLogMigrationScript(osPg, pgStatement);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean dontLog(String statement) {
|
||||
String [] exceptionTables = new String[] {
|
||||
"AD_ACCESSLOG",
|
||||
"AD_ALERTPROCESSORLOG",
|
||||
"AD_CHANGELOG",
|
||||
"AD_ISSUE",
|
||||
"AD_LDAPPROCESSORLOG",
|
||||
"AD_PACKAGE_IMP",
|
||||
"AD_PACKAGE_IMP_BACKUP",
|
||||
"AD_PACKAGE_IMP_DETAIL",
|
||||
"AD_PACKAGE_IMP_INST",
|
||||
"AD_PACKAGE_IMP_PROC",
|
||||
"AD_PINSTANCE",
|
||||
"AD_PINSTANCE_LOG",
|
||||
"AD_PINSTANCE_PARA",
|
||||
"AD_REPLICATION_LOG",
|
||||
"AD_SCHEDULERLOG",
|
||||
"AD_SESSION",
|
||||
"AD_WORKFLOWPROCESSORLOG",
|
||||
"CM_WEBACCESSLOG",
|
||||
"C_ACCTPROCESSORLOG",
|
||||
"K_INDEXLOG",
|
||||
"R_REQUESTPROCESSORLOG",
|
||||
"T_AGING",
|
||||
"T_ALTER_COLUMN",
|
||||
"T_DISTRIBUTIONRUNDETAIL",
|
||||
"T_INVENTORYVALUE",
|
||||
"T_INVOICEGL",
|
||||
"T_REPLENISH",
|
||||
"T_REPORT",
|
||||
"T_REPORTSTATEMENT",
|
||||
"T_SELECTION",
|
||||
"T_SELECTION2",
|
||||
"T_SPOOL",
|
||||
"T_TRANSACTION",
|
||||
"T_TRIALBALANCE"
|
||||
};
|
||||
String uppStmt = statement.toUpperCase();
|
||||
// don't log selects
|
||||
if (uppStmt.startsWith("SELECT "))
|
||||
return true;
|
||||
// don't log update to statistic process
|
||||
if (uppStmt.startsWith("UPDATE AD_PROCESS SET STATISTIC_COUNT="))
|
||||
return true;
|
||||
for (int i = 0; i < exceptionTables.length; i++) {
|
||||
if (uppStmt.startsWith("INSERT INTO " + exceptionTables[i] + " "))
|
||||
return true;
|
||||
if (uppStmt.startsWith("DELETE FROM " + exceptionTables[i] + " "))
|
||||
return true;
|
||||
if (uppStmt.startsWith("DELETE " + exceptionTables[i] + " "))
|
||||
return true;
|
||||
if (uppStmt.startsWith("UPDATE " + exceptionTables[i] + " "))
|
||||
return true;
|
||||
}
|
||||
|
||||
// don't log selects or insert/update for exception tables (i.e. AD_Issue, AD_ChangeLog)
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void writeLogMigrationScript(DataOutputStream os, String statement) throws IOException {
|
||||
String prm_COMMENT = MSysConfig.getValue("DICTIONARY_ID_COMMENTS");
|
||||
// log time and date
|
||||
SimpleDateFormat format = DisplayType.getDateFormat(DisplayType.DateTime);
|
||||
String dateTimeText = format.format(new Timestamp(System.currentTimeMillis()));
|
||||
os.writeBytes("-- ");
|
||||
os.writeBytes(dateTimeText);
|
||||
os.writeBytes("\n");
|
||||
// log sysconfig comment
|
||||
os.writeBytes("-- ");
|
||||
os.writeBytes(prm_COMMENT);
|
||||
os.writeBytes("\n");
|
||||
// log statement
|
||||
os.writeBytes(statement);
|
||||
// close statement
|
||||
os.writeBytes("\n/\n\n");
|
||||
}
|
||||
|
||||
} // Convert
|
|
@ -602,6 +602,9 @@ public final class ALogin extends CDialog
|
|||
// Reference check
|
||||
Ini.setProperty(Ini.P_ADEMPIERESYS, "Reference".equalsIgnoreCase(CConnection.get().getDbUid()));
|
||||
|
||||
// Reference check
|
||||
Ini.setProperty(Ini.P_LOGMIGRATIONSCRIPT, "Reference".equalsIgnoreCase(CConnection.get().getDbUid()));
|
||||
|
||||
// Get Roles
|
||||
m_login = new Login(m_ctx);
|
||||
KeyNamePair[] roles = null;
|
||||
|
|
|
@ -115,6 +115,7 @@ public final class Preference extends CDialog
|
|||
private CCheckBox traceFile = new CCheckBox();
|
||||
private CCheckBox autoLogin = new CCheckBox();
|
||||
private CCheckBox adempiereSys = new CCheckBox();
|
||||
private CCheckBox logMigrationScript = new CCheckBox();
|
||||
private CCheckBox storePassword = new CCheckBox();
|
||||
private CCheckBox showTrl = new CCheckBox();
|
||||
private CCheckBox showAcct = new CCheckBox();
|
||||
|
@ -178,6 +179,8 @@ public final class Preference extends CDialog
|
|||
autoNew.setToolTipText(Msg.getMsg(Env.getCtx(), "AutoNew", false));
|
||||
adempiereSys.setText(Msg.getMsg(Env.getCtx(), "AdempiereSys", true));
|
||||
adempiereSys.setToolTipText(Msg.getMsg(Env.getCtx(), "AdempiereSys", false));
|
||||
logMigrationScript.setText(Msg.getMsg(Env.getCtx(), "LogMigrationScript", true));
|
||||
logMigrationScript.setToolTipText(Msg.getMsg(Env.getCtx(), "LogMigrationScript", false));
|
||||
printPreview.setText(Msg.getMsg(Env.getCtx(), "AlwaysPrintPreview", true));
|
||||
printPreview.setToolTipText(Msg.getMsg(Env.getCtx(), "AlwaysPrintPreview", false));
|
||||
validateConnectionOnStartup.setText(Msg.getMsg(Env.getCtx(), "ValidateConnectionOnStartup", true));
|
||||
|
@ -285,6 +288,7 @@ public final class Preference extends CDialog
|
|||
datePanel.add(fDate);
|
||||
otherPanel.add(datePanel);datePanel.setBorder(insetBorder);
|
||||
otherPanel.add(adempiereSys);adempiereSys.setBorder(insetBorder);
|
||||
otherPanel.add(logMigrationScript);logMigrationScript.setBorder(insetBorder);
|
||||
customizePane.add(otherPanel, new GridBagConstraints(0, 5, 1, 1, 1.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 0, 2, 0), 0, 0));
|
||||
|
||||
|
@ -425,10 +429,14 @@ public final class Preference extends CDialog
|
|||
autoNew.setSelected(Env.isAutoNew(Env.getCtx()));
|
||||
// AdempiereSys
|
||||
adempiereSys.setSelected(Ini.isPropertyBool(Ini.P_ADEMPIERESYS));
|
||||
// LogMigrationScript
|
||||
logMigrationScript.setSelected(Ini.isPropertyBool(Ini.P_LOGMIGRATIONSCRIPT));
|
||||
if (Env.getAD_Client_ID(Env.getCtx()) > 20)
|
||||
{
|
||||
adempiereSys.setSelected(false);
|
||||
adempiereSys.setEnabled(false);
|
||||
logMigrationScript.setSelected(false);
|
||||
logMigrationScript.setEnabled(false);
|
||||
}
|
||||
// AutoLogin
|
||||
autoLogin.setSelected(Ini.isPropertyBool(Ini.P_A_LOGIN));
|
||||
|
@ -514,6 +522,8 @@ public final class Preference extends CDialog
|
|||
Env.setAutoNew(Env.getCtx(), autoNew.isSelected());
|
||||
// AdempiereSys
|
||||
Ini.setProperty(Ini.P_ADEMPIERESYS, adempiereSys.isSelected());
|
||||
// LogMigrationScript
|
||||
Ini.setProperty(Ini.P_LOGMIGRATIONSCRIPT, logMigrationScript.isSelected());
|
||||
// AutoLogin
|
||||
Ini.setProperty(Ini.P_A_LOGIN, (autoLogin.isSelected()));
|
||||
// Save Password
|
||||
|
|
|
@ -95,9 +95,12 @@ public final class Ini implements Serializable
|
|||
/** Auto New Record */
|
||||
public static final String P_A_NEW = "AutoNew";
|
||||
private static final boolean DEFAULT_A_NEW = false;
|
||||
/** Dictonary Maintennace */
|
||||
/** Dictionary Maintenance */
|
||||
public static final String P_ADEMPIERESYS = "AdempiereSys"; // Save system records
|
||||
private static final boolean DEFAULT_ADEMPIERESYS = false;
|
||||
/** Log Migration Script */
|
||||
public static final String P_LOGMIGRATIONSCRIPT = "LogMigrationScript"; // Log migration script
|
||||
private static final boolean DEFAULT_LOGMIGRATIONSCRIPT = false;
|
||||
/** Show Acct Tabs */
|
||||
public static final String P_SHOW_ACCT = "ShowAcct";
|
||||
private static final boolean DEFAULT_SHOW_ACCT = true;
|
||||
|
@ -173,7 +176,7 @@ public final class Ini implements Serializable
|
|||
P_CONNECTION, P_STORE_PWD,
|
||||
P_UI_LOOK, P_UI_THEME, /* P_UI_FLAT,*/
|
||||
P_A_COMMIT, P_A_LOGIN, P_A_NEW,
|
||||
P_ADEMPIERESYS, P_SHOW_ACCT, P_SHOW_TRL,
|
||||
P_ADEMPIERESYS, P_LOGMIGRATIONSCRIPT, P_SHOW_ACCT, P_SHOW_TRL,
|
||||
P_SHOW_ADVANCED, P_CACHE_WINDOW,
|
||||
P_CONTEXT, P_TEMP_DIR,
|
||||
P_ROLE, P_CLIENT, P_ORG, P_PRINTER, P_WAREHOUSE, P_TODAY,
|
||||
|
@ -192,7 +195,7 @@ public final class Ini implements Serializable
|
|||
DEFAULT_CONNECTION, DEFAULT_STORE_PWD?"Y":"N",
|
||||
DEFAULT_UI_LOOK, DEFAULT_UI_THEME, /* DEFAULT_UI_FLAT?"Y":"N", */
|
||||
DEFAULT_A_COMMIT?"Y":"N", DEFAULT_A_LOGIN?"Y":"N", DEFAULT_A_NEW?"Y":"N",
|
||||
DEFAULT_ADEMPIERESYS?"Y":"N", DEFAULT_SHOW_ACCT?"Y":"N", DEFAULT_SHOW_TRL?"Y":"N",
|
||||
DEFAULT_ADEMPIERESYS?"Y":"N", DEFAULT_LOGMIGRATIONSCRIPT?"Y":"N", DEFAULT_SHOW_ACCT?"Y":"N", DEFAULT_SHOW_TRL?"Y":"N",
|
||||
DEFAULT_SHOW_ADVANCED?"Y":"N", DEFAULT_CACHE_WINDOW?"Y":"N",
|
||||
DEFAULT_CONTEXT, DEFAULT_TEMP_DIR,
|
||||
DEFAULT_ROLE, DEFAULT_CLIENT, DEFAULT_ORG, DEFAULT_PRINTER, DEFAULT_WAREHOUSE, DEFAULT_TODAY.toString(),
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
-- Nov 11, 2007 1:54:50 AM COT
|
||||
-- FR 1829798 - Easy generation of migration scripts
|
||||
INSERT INTO AD_MESSAGE
|
||||
(ad_client_id, ad_message_id, ad_org_id,
|
||||
created, createdby,
|
||||
entitytype, isactive, msgtext,
|
||||
msgtip,
|
||||
msgtype, updated,
|
||||
updatedby, VALUE
|
||||
)
|
||||
VALUES (0, 53007, 0,
|
||||
TO_DATE ('2007-11-11 01:54:49', 'YYYY-MM-DD HH24:MI:SS'), 100,
|
||||
'D', 'Y', 'Log Migration Script',
|
||||
'Log Migration Script - Save migration scripts file in %TEMP%/migration_script_*.sql',
|
||||
'I', TO_DATE ('2007-11-11 01:54:49', 'YYYY-MM-DD HH24:MI:SS'),
|
||||
100, 'LogMigrationScript'
|
||||
)
|
||||
/
|
||||
-- Nov 11, 2007 1:54:50 AM COT
|
||||
-- FR 1829798 - Easy generation of migration scripts
|
||||
INSERT INTO AD_MESSAGE_TRL
|
||||
(AD_LANGUAGE, ad_message_id, msgtext, msgtip, istranslated,
|
||||
ad_client_id, ad_org_id, created, createdby, updated, updatedby)
|
||||
SELECT l.AD_LANGUAGE, t.ad_message_id, t.msgtext, t.msgtip, 'N',
|
||||
t.ad_client_id, t.ad_org_id, t.created, t.createdby, t.updated,
|
||||
t.updatedby
|
||||
FROM AD_LANGUAGE l, AD_MESSAGE t
|
||||
WHERE l.isactive = 'Y'
|
||||
AND l.issystemlanguage = 'Y'
|
||||
AND l.isbaselanguage = 'N'
|
||||
AND t.ad_message_id = 53007
|
||||
AND EXISTS (
|
||||
SELECT *
|
||||
FROM AD_MESSAGE_TRL tt
|
||||
WHERE tt.AD_LANGUAGE != l.AD_LANGUAGE
|
||||
OR tt.ad_message_id != t.ad_message_id)
|
||||
/
|
|
@ -0,0 +1,9 @@
|
|||
-- Nov 11, 2007 1:54:50 AM COT
|
||||
-- FR 1829798 - Easy generation of migration scripts
|
||||
INSERT INTO AD_MESSAGE (AD_Client_ID,AD_Message_ID,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgTip,MsgType,Updated,UpdatedBy,VALUE) VALUES (0,53007,0,TO_TIMESTAMP('2007-11-11 01:54:49','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','Log Migration Script','Log Migration Script - Save migration scripts file in %TEMP%/migration_script_*.sql','I',TO_TIMESTAMP('2007-11-11 01:54:49','YYYY-MM-DD HH24:MI:SS'),100,'LogMigrationScript')
|
||||
/
|
||||
|
||||
-- Nov 11, 2007 1:54:50 AM COT
|
||||
-- FR 1829798 - Easy generation of migration scripts
|
||||
INSERT INTO AD_MESSAGE_TRL (AD_LANGUAGE,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_LANGUAGE,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_LANGUAGE l, AD_MESSAGE t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=53007 AND EXISTS (SELECT * FROM AD_MESSAGE_TRL tt WHERE tt.AD_LANGUAGE!=l.AD_LANGUAGE OR tt.AD_Message_ID!=t.AD_Message_ID)
|
||||
/
|
Loading…
Reference in New Issue