IDEMPIERE-3655 Improve installer to include migration scripts and syncApplied

This commit is contained in:
Carlos Ruiz 2018-03-14 18:13:08 -03:00
parent 14536e9848
commit b8f0aa4bd8
18 changed files with 329 additions and 286 deletions

View File

@ -0,0 +1,11 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- IDEMPIERE-3655
-- Mar 14, 2018 2:27:47 PM BRT
UPDATE AD_SysConfig SET Value=CASE WHEN Value NOT LIKE 'migration;%' THEN 'migration;'||TRIM(Value) ELSE Value END,Updated=TO_DATE('2018-03-14 14:27:47','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_SysConfig_ID=200102
;
SELECT register_migration_script('201803141439_IDEMPIERE-3655.sql') FROM dual
;

View File

@ -0,0 +1,8 @@
-- IDEMPIERE-3655
-- Mar 14, 2018 2:27:47 PM BRT
UPDATE AD_SysConfig SET Value=CASE WHEN Value NOT LIKE 'migration;%' THEN 'migration;'||TRIM(Value) ELSE Value END,Updated=TO_DATE('2018-03-14 14:27:47','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_SysConfig_ID=200102
;
SELECT register_migration_script('201803141439_IDEMPIERE-3655.sql') FROM dual
;

View File

@ -0,0 +1,20 @@
You can add here custom scripts for your installation to be applied when running the RUN_SyncDB utility.
Custom scripts must follow the same convention as core scripts, this is:
postgresql/yyyymmddHHMM_InformationalDescription.sql
oracle/yyyymmddHHMM_InformationalDescription.sql
This is, the scripts must be within a folder with name postgresql or oracle depending on the database to apply, and must follow the convention yyyymmddHHMM_InformationalDescription.sql
* yyyymmddHHMM : the timestamp of the SQL script, this is relevant as the files will be applied ordering by this timestamp - independently of the folder where they are located
* InformationalDescription : optional additional information
folders are applied in alphabetical order, for example:
i4.1
i4.1z
i5.1
... and so on until the current version ... and then
local_sql
Note it process ANY FOLDER that contains a subfolder postgresql or oracle, and at the end it process the scripts in processes_post_migration

View File

@ -0,0 +1,8 @@
2Pack files are processed anywhere within the migration folder, however, it is recommended to add here your custom 2Pack zip files for your installation, these 2Pack files will be applied after starting the server by the org.adempiere.plugin.utils.PackInApplicationActivator plugin.
Name of 2pack files must follow the convention:
yyyymmddHHMM_ClientValue_InformationalDescription.zip
* yyyymmddHHMM : the timestamp of the 2pack file, this is relevant as the files will be applied ordering by this timestamp - independently of the folder where they are located
* ClientValue : refers to the AD_Client.Value - this is case sensitive and it describes in which client (tenant) the 2pack is applied
* InformationalDescription : optional additional information

View File

@ -137,7 +137,7 @@ public class PackInApplicationActivator extends AbstractActivator {
File[] fileArray = getFilesToProcess(folders); File[] fileArray = getFilesToProcess(folders);
if (fileArray.length <= 0) { if (fileArray.length <= 0) {
System.out.println("No zip files to process"); logger.info("No zip files to process");
return; return;
} }
@ -162,9 +162,9 @@ public class PackInApplicationActivator extends AbstractActivator {
} }
if (filesToProcess.size() > 0) { if (filesToProcess.size() > 0) {
System.out.println("The following packages were not applied: "); logger.warning("The following packages were not applied: ");
for (File file : filesToProcess) { for (File file : filesToProcess) {
System.out.println(file.getName()); logger.warning(file.getName());
} }
} }
} }
@ -172,7 +172,7 @@ public class PackInApplicationActivator extends AbstractActivator {
private boolean packIn(File packinFile) { private boolean packIn(File packinFile) {
if (packinFile != null && service != null) { if (packinFile != null && service != null) {
String fileName = packinFile.getName(); String fileName = packinFile.getName();
System.out.println("Installing " + fileName + " ..."); logger.warning("Installing " + fileName + " ...");
// The convention for package names is: yyyymmddHHMM_ClientValue_InformationalDescription.zip // The convention for package names is: yyyymmddHHMM_ClientValue_InformationalDescription.zip
String [] parts = fileName.split("_"); String [] parts = fileName.split("_");
@ -194,7 +194,7 @@ public class PackInApplicationActivator extends AbstractActivator {
logger.log(Level.SEVERE, "Pack in failed.", e); logger.log(Level.SEVERE, "Pack in failed.", e);
return false; return false;
} }
System.out.println(packinFile.getPath() + " installed"); logger.warning(packinFile.getPath() + " installed");
} }
return true; return true;
@ -254,7 +254,7 @@ public class PackInApplicationActivator extends AbstractActivator {
boolean found = false; boolean found = false;
for (File fileToProcess : toProcess.listFiles(filter)) { for (File fileToProcess : toProcess.listFiles(filter)) {
if (!found) { if (!found) {
System.out.println("*** Creating list from folder " + toProcess.toString()); logger.info("*** Creating list from folder " + toProcess.toString());
found = true; found = true;
} }
if (fileToProcess.isDirectory()) if (fileToProcess.isDirectory())
@ -263,7 +263,7 @@ public class PackInApplicationActivator extends AbstractActivator {
filesToProcess.add(fileToProcess); filesToProcess.add(fileToProcess);
} }
if (!found) { if (!found) {
logger.log(Level.SEVERE, toProcess.getName() + " does not have .zip files or subfolders"); logger.log(Level.FINE, toProcess.getName() + " does not have .zip files or subfolders");
return; return;
} }
} else { } else {
@ -283,7 +283,7 @@ public class PackInApplicationActivator extends AbstractActivator {
} }
private MClient getClient(String clientValue) { private MClient getClient(String clientValue) {
String where = "upper(Value) = upper(?)"; String where = "Value = ?";
Query q = new Query(Env.getCtx(), MClient.Table_Name, Query q = new Query(Env.getCtx(), MClient.Table_Name,
where, null) where, null)
.setParameters(new Object[] {clientValue}) .setParameters(new Object[] {clientValue})

View File

@ -3,6 +3,7 @@ root=file:build.xml,file:setup.ini,file:extensions-priorty.properties,file:hazel
root.folder.data=data root.folder.data=data
root.folder.setup=setup root.folder.setup=setup
root.folder.jettyhome=jettyhome root.folder.jettyhome=jettyhome
root.folder.migration=../migration
#linux 64 bits #linux 64 bits
root.linux.gtk.x86_64=file:setup.sh,file:console-setup.sh,file:idempiere-server.sh,file:setup-alt.sh,file:console-setup-alt.sh,file:sign-database-build.sh,file:sign-database-build-alt.sh,file:idempiereEnvTemplate.properties root.linux.gtk.x86_64=file:setup.sh,file:console-setup.sh,file:idempiere-server.sh,file:setup-alt.sh,file:console-setup-alt.sh,file:sign-database-build.sh,file:sign-database-build-alt.sh,file:idempiereEnvTemplate.properties

View File

@ -0,0 +1,10 @@
#!/bin/sh
# Author Carlos Ruiz
if [ $IDEMPIERE_HOME ]; then
cd $IDEMPIERE_HOME/utils
fi
. ./myEnvironment.sh Server
echo Synchronize iDempiere Database - $IDEMPIERE_HOME \($ADEMPIERE_DB_NAME\)
sh $ADEMPIERE_DB_PATH/SyncDB.sh "$ADEMPIERE_DB_USER" "$ADEMPIERE_DB_PASSWORD" "$ADEMPIERE_DB_PATH"

View File

@ -1,69 +0,0 @@
DECLARE
ins VARCHAR2 (2000);
sel VARCHAR2 (2000);
inssel VARCHAR2 (4001);
table_id NUMBER;
BEGIN
ins := RPAD (' ', 2000, ' ');
sel := RPAD (' ', 2000, ' ');
inssel := RPAD (' ', 4001, ' ');
DBMS_OUTPUT.PUT_LINE ('Start');
FOR t IN (SELECT ad_table_id,
SUBSTR (tablename, 1, LENGTH (tablename) - 4) tablename
FROM AD_TABLE
WHERE tablename LIKE '%_Trl' AND isactive = 'Y'
AND isview = 'N')
LOOP
ins :=
'INSERT INTO '
|| t.tablename
|| '_TRL ('
|| 'ad_language,ad_client_id,ad_org_id,created,createdby,updated,updatedby,isactive,istranslated,'
|| t.tablename
|| '_id';
sel :=
'SELECT l.ad_language,t.ad_client_id,t.ad_org_id,t.created,t.createdby,t.updated,t.updatedby,t.isactive,''N'' as istranslated,'
|| t.tablename
|| '_id';
SELECT ad_table_id
INTO table_id
FROM AD_TABLE
WHERE tablename = t.tablename;
FOR c IN (SELECT col.columnname
FROM AD_COLUMN col INNER JOIN AD_TABLE tab
ON (col.ad_table_id = tab.ad_table_id)
WHERE col.ad_table_id = table_id
AND col.istranslated = 'Y'
AND col.isactive = 'Y'
ORDER BY 1)
LOOP
ins := TRIM (ins) || ',' || TRIM (c.columnname);
sel := TRIM (sel) || ',t.' || TRIM (c.columnname);
END LOOP;
ins := TRIM (ins) || ')';
sel :=
TRIM (sel)
|| ' from '
|| t.tablename
|| ' t, ad_language l WHERE l.issystemlanguage=''Y'' AND NOT EXISTS (SELECT 1 FROM '
|| t.tablename
|| '_TRL b WHERE b.'
|| t.tablename
|| '_id=t.'
|| t.tablename
|| '_id AND b.AD_LANGUAGE=l.AD_LANGUAGE)';
inssel := TRIM (ins) || ' ' || TRIM (sel);
DBMS_OUTPUT.PUT_LINE (inssel);
EXECUTE IMMEDIATE inssel;
END LOOP;
DBMS_OUTPUT.PUT_LINE ('End');
COMMIT;
END;
/

View File

@ -20,4 +20,4 @@ fi
echo ------------------------------------- echo -------------------------------------
echo Add missing translations echo Add missing translations
echo ------------------------------------- echo -------------------------------------
echo sqlplus $2/$3@$ADEMPIERE_DB_SERVER:$ADEMPIERE_DB_PORT/$ADEMPIERE_DB_NAME @$IDEMPIERE_HOME/utils/$ADEMPIERE_DB_PATH/01_add_missing_Translations.sql echo sqlplus $2/$3@$ADEMPIERE_DB_SERVER:$ADEMPIERE_DB_PORT/$ADEMPIERE_DB_NAME @$IDEMPIERE_HOME/migration/processes_post_migration/$ADEMPIERE_DB_PATH/01_add_missing_Translations.sql

View File

@ -0,0 +1,100 @@
#!/bin/sh
#
# Author: Carlos Ruiz - globalqss
# Script to synchronize the database for with latest migration scripts
echo Synchronize iDempiere Database
echo Upgrading database $1@$ADEMPIERE_DB_NAME
if [ $# -eq 0 ]
then
echo "Usage: $0 <userAccount>"
echo "Example: $0 adempiere adempiere"
exit 1
fi
if [ "$IDEMPIERE_HOME" = "" -o "$ADEMPIERE_DB_NAME" = "" -o "$ADEMPIERE_DB_SERVER" = "" -o "$ADEMPIERE_DB_PORT" = "" ]
then
echo "Please make sure that the environment variables are set correctly:"
echo " IDEMPIERE_HOME e.g. /idempiere"
echo " ADEMPIERE_DB_NAME e.g. adempiere or xe"
echo " ADEMPIERE_DB_SERVER e.g. dbserver.adempiere.org"
echo " ADEMPIERE_DB_PORT e.g. 5432 or 1521"
exit 1
fi
TMPFOLDER=/tmp
ADEMPIERE_DB_USER=$1
ADEMPIERE_DB_PASSWORD=$2
ADEMPIERE_DB_PATH=$3
CMD="sqlplus $ADEMPIERE_DB_USER/$ADEMPIERE_DB_PASSWORD@$ADEMPIERE_DB_SERVER:$ADEMPIERE_DB_PORT/$ADEMPIERE_DB_NAME"
SILENTCMD="$CMD -S"
ERROR_STRINGS="^(ORA-[0-9]+:|TNS-|PLS-)"
cd $IDEMPIERE_HOME/migration
# Create list of files already applied - registered in AD_MigrationScript table
echo "set heading off
set feedback off
set pagesize 0
set term off
set echo off
select name from ad_migrationscript;" | $SILENTCMD | sed -e 's:^ ::' | grep -v '^$' | sort > $TMPFOLDER/lisDB_$$.txt
# Create list of files in the migration folder
> $TMPFOLDER/lisFS_$$.txt
find -type d -name $ADEMPIERE_DB_PATH | grep -v "./processes_post_migration/$ADEMPIERE_DB_PATH" | while read FOLDER
do
cd "${FOLDER}"
ls *.sql >> $TMPFOLDER/lisFS_$$.txt
cd $IDEMPIERE_HOME/migration
done
sort -o $TMPFOLDER/lisFS_$$.txt $TMPFOLDER/lisFS_$$.txt
sort -o $TMPFOLDER/lisDB_$$.txt $TMPFOLDER/lisDB_$$.txt
MSGERROR=""
APPLIED=N
# extract and process the list of pending files
comm -13 $TMPFOLDER/lisDB_$$.txt $TMPFOLDER/lisFS_$$.txt > $TMPFOLDER/lisPENDING_$$.txt
if [ -s $TMPFOLDER/lisPENDING_$$.txt ]
then
mkdir $TMPFOLDER/SyncDB_out_$$
for FILE in `cat $TMPFOLDER/lisPENDING_$$.txt`
do
SCRIPT=`find -name "$FILE" | grep "/$ADEMPIERE_DB_PATH/"`
OUTFILE=$TMPFOLDER/SyncDB_out_$$/`basename "$FILE" .sql`.out
echo "Applying $SCRIPT"
cat "$SCRIPT" | $CMD 2>&1 | tee "$OUTFILE"
APPLIED=Y
if egrep "$ERROR_STRINGS" "$OUTFILE" > /dev/null 2>&1
then
MSGERROR="$MSGERROR\n**** ERROR ON FILE $OUTFILE - Please verify ****"
# Stop processing to allow user to fix the problem before processing additional files
break
fi
done
else
if [ -s $TMPFOLDER/lisFS_$$.txt ]
then
echo "Database is already in sync - no scripts pending to apply"
else
echo "No scripts were found to apply"
fi
fi
if [ x$APPLIED = xY ]
then
cd $IDEMPIERE_HOME/migration
for FILE in processes_post_migration/$ADEMPIERE_DB_PATH/*.sql
do
OUTFILE=$TMPFOLDER/SyncDB_out_$$/`basename "$FILE" .sql`.out
cat "$FILE" | $CMD 2>&1 | tee "$OUTFILE"
if egrep "$ERROR_STRINGS" "$OUTFILE" > /dev/null 2>&1
then
MSGERROR="$MSGERROR\n**** ERROR ON FILE $OUTFILE - Please verify ****"
fi
done
fi
if [ -n "$MSGERROR" ]
then
echo "$MSGERROR"
echo "\n Errors were found during the process (see message above) - please review and fix the error running manually the script - and then restart this process again"
fi

View File

@ -1,69 +0,0 @@
CREATE OR REPLACE FUNCTION add_missing_translations() RETURNS void as $func$
DECLARE
ins VARCHAR (2000);
sel VARCHAR (2000);
inssel VARCHAR (4001);
table_id NUMERIC;
t RECORD;
c RECORD;
BEGIN
FOR t IN (SELECT ad_table_id,
SUBSTR (tablename, 1, LENGTH (tablename) - 4) as tablename
FROM AD_TABLE
WHERE tablename LIKE '%_Trl' AND isactive = 'Y'
AND isview = 'N')
LOOP
ins :=
'INSERT INTO '
|| t.tablename
|| '_TRL ('
|| 'ad_language,ad_client_id,ad_org_id,created,createdby,updated,updatedby,isactive,istranslated,'
|| t.tablename
|| '_id';
sel :=
'SELECT l.ad_language,t.ad_client_id,t.ad_org_id,t.created,t.createdby,t.updated,t.updatedby,t.isactive,''N'' as istranslated,'
|| t.tablename
|| '_id';
SELECT ad_table_id
INTO table_id
FROM AD_TABLE
WHERE tablename = t.tablename;
FOR c IN (SELECT col.columnname
FROM AD_COLUMN col INNER JOIN AD_TABLE tab
ON (col.ad_table_id = tab.ad_table_id)
WHERE col.ad_table_id = table_id
AND col.istranslated = 'Y'
AND col.isactive = 'Y'
ORDER BY 1)
LOOP
ins := TRIM (ins) || ',' || TRIM (c.columnname);
sel := TRIM (sel) || ',t.' || TRIM (c.columnname);
END LOOP;
ins := TRIM (ins) || ')';
sel :=
TRIM (sel)
|| ' from '
|| t.tablename
|| ' t, ad_language l WHERE l.issystemlanguage=''Y'' AND NOT EXISTS (SELECT 1 FROM '
|| t.tablename
|| '_TRL b WHERE b.'
|| t.tablename
|| '_id=t.'
|| t.tablename
|| '_id AND b.AD_LANGUAGE=l.AD_LANGUAGE)';
inssel := TRIM (ins) || ' ' || TRIM (sel);
EXECUTE inssel;
END LOOP;
END;
$func$ LANGUAGE plpgsql;
select add_missing_translations();
commit;

View File

@ -24,6 +24,6 @@ export PGPASSWORD
echo ------------------------------------- echo -------------------------------------
echo Add missing translations echo Add missing translations
echo ------------------------------------- echo -------------------------------------
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -d $ADEMPIERE_DB_NAME -U $2 -f $IDEMPIERE_HOME/utils/$ADEMPIERE_DB_PATH/01_add_missing_translations.sql psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -d $ADEMPIERE_DB_NAME -U $2 -f $IDEMPIERE_HOME/migration/processes_post_migration/$ADEMPIERE_DB_PATH/01_add_missing_translations.sql
PGPASSWORD= PGPASSWORD=
export PGPASSWORD export PGPASSWORD

View File

@ -0,0 +1,100 @@
#!/bin/sh
#
# Author: Carlos Ruiz - globalqss
# Script to synchronize the database for with latest migration scripts
echo Synchronize iDempiere Database
echo Upgrading database $1@$ADEMPIERE_DB_NAME
if [ $# -eq 0 ]
then
echo "Usage: $0 <userAccount>"
echo "Example: $0 adempiere adempiere"
exit 1
fi
if [ "$IDEMPIERE_HOME" = "" -o "$ADEMPIERE_DB_NAME" = "" -o "$ADEMPIERE_DB_SERVER" = "" -o "$ADEMPIERE_DB_PORT" = "" ]
then
echo "Please make sure that the environment variables are set correctly:"
echo " IDEMPIERE_HOME e.g. /idempiere"
echo " ADEMPIERE_DB_NAME e.g. adempiere or xe"
echo " ADEMPIERE_DB_SERVER e.g. dbserver.adempiere.org"
echo " ADEMPIERE_DB_PORT e.g. 5432 or 1521"
exit 1
fi
PGPASSWORD=$2
export PGPASSWORD
TMPFOLDER=/tmp
ADEMPIERE_DB_USER=$1
ADEMPIERE_DB_PATH=$3
CMD="psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -d $ADEMPIERE_DB_NAME -U $ADEMPIERE_DB_USER"
SILENTCMD="$CMD -q -t"
ERROR_STRINGS="^(ERROR:|FEHLER:|FATAL:|ERRO:)"
cd $IDEMPIERE_HOME/migration
# Create list of files already applied - registered in AD_MigrationScript table
echo "select name from ad_migrationscript" | $SILENTCMD | sed -e 's:^ ::' | grep -v '^$' | sort > $TMPFOLDER/lisDB_$$.txt
# Create list of files in the migration folder
> $TMPFOLDER/lisFS_$$.txt
find -type d -name $ADEMPIERE_DB_PATH | grep -v "./processes_post_migration/$ADEMPIERE_DB_PATH" | while read FOLDER
do
cd "${FOLDER}"
ls *.sql >> $TMPFOLDER/lisFS_$$.txt
cd $IDEMPIERE_HOME/migration
done
sort -o $TMPFOLDER/lisFS_$$.txt $TMPFOLDER/lisFS_$$.txt
sort -o $TMPFOLDER/lisDB_$$.txt $TMPFOLDER/lisDB_$$.txt
MSGERROR=""
APPLIED=N
# extract and process the list of pending files
comm -13 $TMPFOLDER/lisDB_$$.txt $TMPFOLDER/lisFS_$$.txt > $TMPFOLDER/lisPENDING_$$.txt
if [ -s $TMPFOLDER/lisPENDING_$$.txt ]
then
mkdir $TMPFOLDER/SyncDB_out_$$
for FILE in `cat $TMPFOLDER/lisPENDING_$$.txt`
do
SCRIPT=`find -name "$FILE" | grep "/$ADEMPIERE_DB_PATH/"`
OUTFILE=$TMPFOLDER/SyncDB_out_$$/`basename "$FILE" .sql`.out
echo "Applying $SCRIPT"
cat "$SCRIPT" | $CMD 2>&1 | tee "$OUTFILE"
APPLIED=Y
if egrep "$ERROR_STRINGS" "$OUTFILE" > /dev/null 2>&1
then
MSGERROR="$MSGERROR\n**** ERROR ON FILE $OUTFILE - Please verify ****"
# Stop processing to allow user to fix the problem before processing additional files
break
fi
done
else
if [ -s $TMPFOLDER/lisFS_$$.txt ]
then
echo "Database is already in sync - no scripts pending to apply"
else
echo "No scripts were found to apply"
fi
fi
if [ x$APPLIED = xY ]
then
cd $IDEMPIERE_HOME/migration
for FILE in processes_post_migration/$ADEMPIERE_DB_PATH/*.sql
do
OUTFILE=$TMPFOLDER/SyncDB_out_$$/`basename "$FILE" .sql`.out
cat "$FILE" | $CMD 2>&1 | tee "$OUTFILE"
if egrep "$ERROR_STRINGS" "$OUTFILE" > /dev/null 2>&1
then
MSGERROR="$MSGERROR\n**** ERROR ON FILE $OUTFILE - Please verify ****"
fi
done
fi
if [ -n "$MSGERROR" ]
then
echo "$MSGERROR"
echo "\n Errors were found during the process (see message above) - please review and fix the error running manually the script - and then restart this process again"
fi
PGPASSWORD=
export PGPASSWORD

View File

@ -0,0 +1,4 @@
@if (%IDEMPIERE_HOME%) == () (CALL myEnvironment.bat Server) else (CALL %IDEMPIERE_HOME%\utils\myEnvironment.bat Server)
@Title Synchronize iDempiere Database - %IDEMPIERE_HOME% (%ADEMPIERE_DB_NAME%)
@call %ADEMPIERE_DB_PATH%\SyncDB %ADEMPIERE_DB_USER% %ADEMPIERE_DB_PASSWORD% %ADEMPIERE_DB_PATH%

View File

@ -1,69 +0,0 @@
DECLARE
ins VARCHAR2 (2000);
sel VARCHAR2 (2000);
inssel VARCHAR2 (4001);
table_id NUMBER;
BEGIN
ins := RPAD (' ', 2000, ' ');
sel := RPAD (' ', 2000, ' ');
inssel := RPAD (' ', 4001, ' ');
DBMS_OUTPUT.PUT_LINE ('Start');
FOR t IN (SELECT ad_table_id,
SUBSTR (tablename, 1, LENGTH (tablename) - 4) tablename
FROM AD_TABLE
WHERE tablename LIKE '%_Trl' AND isactive = 'Y'
AND isview = 'N')
LOOP
ins :=
'INSERT INTO '
|| t.tablename
|| '_TRL ('
|| 'ad_language,ad_client_id,ad_org_id,created,createdby,updated,updatedby,isactive,istranslated,'
|| t.tablename
|| '_id';
sel :=
'SELECT l.ad_language,t.ad_client_id,t.ad_org_id,t.created,t.createdby,t.updated,t.updatedby,t.isactive,''N'' as istranslated,'
|| t.tablename
|| '_id';
SELECT ad_table_id
INTO table_id
FROM AD_TABLE
WHERE tablename = t.tablename;
FOR c IN (SELECT col.columnname
FROM AD_COLUMN col INNER JOIN AD_TABLE tab
ON (col.ad_table_id = tab.ad_table_id)
WHERE col.ad_table_id = table_id
AND col.istranslated = 'Y'
AND col.isactive = 'Y'
ORDER BY 1)
LOOP
ins := TRIM (ins) || ',' || TRIM (c.columnname);
sel := TRIM (sel) || ',t.' || TRIM (c.columnname);
END LOOP;
ins := TRIM (ins) || ')';
sel :=
TRIM (sel)
|| ' from '
|| t.tablename
|| ' t, ad_language l WHERE l.issystemlanguage=''Y'' AND NOT EXISTS (SELECT 1 FROM '
|| t.tablename
|| '_TRL b WHERE b.'
|| t.tablename
|| '_id=t.'
|| t.tablename
|| '_id AND b.AD_LANGUAGE=l.AD_LANGUAGE)';
inssel := TRIM (ins) || ' ' || TRIM (sel);
DBMS_OUTPUT.PUT_LINE (inssel);
EXECUTE IMMEDIATE inssel;
END LOOP;
DBMS_OUTPUT.PUT_LINE ('End');
COMMIT;
END;
/

View File

@ -0,0 +1,28 @@
@Echo Synchronize iDempiere Database
@Rem
@Echo Upgrading database %1@%ADEMPIERE_DB_NAME%
@if (%IDEMPIERE_HOME%) == () goto environment
@if (%ADEMPIERE_DB_NAME%) == () goto environment
@if (%ADEMPIERE_DB_SERVER%) == () goto environment
@if (%ADEMPIERE_DB_PORT%) == () goto environment
@Rem Must have parameter: userAccount
@if (%1) == () goto usage
@Echo WARNING: THIS PROGRAM IS NOT DEVELOPED FOR WINDOWS YET - YOU NEED TO APPLY MANUALLY THE PENDING MIGRATION SCRIPTS
@Rem TODO: port oracle/SyncDB.sh to windows syntax
@goto end
:environment
@Echo Please make sure that the enviroment variables are set correctly:
@Echo IDEMPIERE_HOME e.g. D:\Adempiere
@Echo ADEMPIERE_DB_NAME e.g. adempiere.adempiere.org
:usage
@echo Usage: %0 <userAccount>
@echo Examples: %0 adempiere adempiere
:end

View File

@ -1,69 +0,0 @@
CREATE OR REPLACE FUNCTION add_missing_translations() RETURNS void as $func$
DECLARE
ins VARCHAR (2000);
sel VARCHAR (2000);
inssel VARCHAR (4001);
table_id NUMERIC;
t RECORD;
c RECORD;
BEGIN
FOR t IN (SELECT ad_table_id,
SUBSTR (tablename, 1, LENGTH (tablename) - 4) as tablename
FROM AD_TABLE
WHERE tablename LIKE '%_Trl' AND isactive = 'Y'
AND isview = 'N')
LOOP
ins :=
'INSERT INTO '
|| t.tablename
|| '_TRL ('
|| 'ad_language,ad_client_id,ad_org_id,created,createdby,updated,updatedby,isactive,istranslated,'
|| t.tablename
|| '_id';
sel :=
'SELECT l.ad_language,t.ad_client_id,t.ad_org_id,t.created,t.createdby,t.updated,t.updatedby,t.isactive,''N'' as istranslated,'
|| t.tablename
|| '_id';
SELECT ad_table_id
INTO table_id
FROM AD_TABLE
WHERE tablename = t.tablename;
FOR c IN (SELECT col.columnname
FROM AD_COLUMN col INNER JOIN AD_TABLE tab
ON (col.ad_table_id = tab.ad_table_id)
WHERE col.ad_table_id = table_id
AND col.istranslated = 'Y'
AND col.isactive = 'Y'
ORDER BY 1)
LOOP
ins := TRIM (ins) || ',' || TRIM (c.columnname);
sel := TRIM (sel) || ',t.' || TRIM (c.columnname);
END LOOP;
ins := TRIM (ins) || ')';
sel :=
TRIM (sel)
|| ' from '
|| t.tablename
|| ' t, ad_language l WHERE l.issystemlanguage=''Y'' AND NOT EXISTS (SELECT 1 FROM '
|| t.tablename
|| '_TRL b WHERE b.'
|| t.tablename
|| '_id=t.'
|| t.tablename
|| '_id AND b.AD_LANGUAGE=l.AD_LANGUAGE)';
inssel := TRIM (ins) || ' ' || TRIM (sel);
EXECUTE inssel;
END LOOP;
END;
$func$ LANGUAGE plpgsql;
select add_missing_translations();
commit;

View File

@ -0,0 +1,29 @@
@Echo Synchronize iDempiere Database
@Echo Upgrading database %1@%ADEMPIERE_DB_NAME%
@if (%IDEMPIERE_HOME%) == () goto environment
@if (%ADEMPIERE_DB_NAME%) == () goto environment
@if (%ADEMPIERE_DB_SERVER%) == () goto environment
@if (%ADEMPIERE_DB_PORT%) == () goto environment
@Rem Must have parameter: userAccount
@if (%1) == () goto usage
@Echo WARNING: THIS PROGRAM IS NOT DEVELOPED FOR WINDOWS YET - YOU NEED TO APPLY MANUALLY THE PENDING MIGRATION SCRIPTS
@Rem TODO: port postgresql/SyncDB.sh to windows syntax
@goto end
:environment
@Echo Please make sure that the enviroment variables are set correctly:
@Echo IDEMPIERE_HOME e.g. D:\ADEMPIERE2
@Echo ADEMPIERE_DB_NAME e.g. adempiere or xe
@Echo ADEMPIERE_DB_SERVER e.g. dbserver.adempiere.org
@Echo ADEMPIERE_DB_PORT e.g. 5432 or 1521
:usage
@echo Usage: %0 <userAccount>
@echo Examples: %0 ADEMPIERE/ADEMPIERE
:end