diff --git a/process/Liquibase_lib/Liquibase_lib.aod b/process/Liquibase_lib/Liquibase_lib.aod new file mode 100644 index 0000000000000000000000000000000000000000..39c2f3f37859fe005008e54de8d6901202b752f3 --- /dev/null +++ b/process/Liquibase_lib/Liquibase_lib.aod @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.2.1"> + <name>Liquibase_lib</name> + <majorModelMode>DISTRIBUTED</majorModelMode> + <process>%aditoprj%/process/Liquibase_lib/process.js</process> +</process> diff --git a/process/Liquibase_lib/process.js b/process/Liquibase_lib/process.js new file mode 100644 index 0000000000000000000000000000000000000000..7384acc73faf4b75a7952110e5ed54cf7da39ee0 --- /dev/null +++ b/process/Liquibase_lib/process.js @@ -0,0 +1,57 @@ +import("system.SQLTYPES"); +import("system.db"); +import("system.util"); +function LiquiUtils(){} + +LiquiUtils.exportToLiquibase = function(pAuthor, pTableName, pColumns, pNewUUIDForIndexes, pCondition) +{ + if(!pNewUUIDForIndexes) + pNewUUIDForIndexes = [] + + var xmlData = <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd"/>; + xmlData.changeSet.@author = pAuthor + xmlData.changeSet.@id = util.getNewUUID() + + var dbData = db.table("select " + pColumns.join(", ") + " from " + pTableName + " " + (pCondition ? pCondition : "")); + var types = db.getColumnTypes(pTableName, pColumns); + + dbData.forEach(function(pRow) { + var node = <insert/>; + node.@tableName = pTableName; + + for (let i = 0; i < pColumns.length; i++) + { + var value = ""; + + for (j = 0; j < pNewUUIDForIndexes.length; j++) { + + if (i == pNewUUIDForIndexes[j]) + { + value = util.getNewUUID(); + break; + } + } + + if (!value) + value = pRow[i]; + + var col = <column/>; + col.@name = pColumns[i]; + + // do not add value if null + if (value) + { + if (SQLTYPES.isNumberType(types[i])) + col.@valueNumeric = value; + else + col.@value = value; + } + + node.appendChild(col); + } + this.appendChild(node); + }, xmlData.changeSet); + + return xmlData.toXMLString() +}; diff --git a/process/Sql_lib/process.js b/process/Sql_lib/process.js index 29b27316f3b33d9fadf8e53fc6d4c2e2a16a5892..ae7bfd7d0836060686f9c879220136c012bb307f 100644 --- a/process/Sql_lib/process.js +++ b/process/Sql_lib/process.js @@ -1495,56 +1495,3 @@ SqlUtils.getResolvingCaseWhen = function(pKeyValueArray, pDbFieldName, pLocale) resSql = [resSql, preparedValues]; return resSql; }; - -SqlUtils.exportToLiquibase = function(pAuthor, pTableName, pColumns, pNewUUIDForIndexes, pCondition) -{ - if(!pNewUUIDForIndexes) - pNewUUIDForIndexes = [] - - var xmlData = <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd"> - </databaseChangeLog>; - xmlData.changeSet.@author = pAuthor - xmlData.changeSet.@id = util.getNewUUID() - - var dbData = db.table("select " + pColumns.join(", ") + " from " + pTableName + " " + (pCondition ? pCondition : "")); - var types = db.getColumnTypes(pTableName, pColumns); - - dbData.forEach(function(pRow) { - var node = <insert></insert>; - node.@tableName = pTableName; - - for (let i = 0; i < pColumns.length; i++) - { - var value = ""; - - for (j = 0; j < pNewUUIDForIndexes.length; j++) { - - if (i == pNewUUIDForIndexes[j]) - { - value = util.getNewUUID(); - break; - } - } - - if (!value) - value = pRow[i]; - - var col = <column/>; - col.@name = pColumns[i]; - - // do not add value if null - if (value) - { - if (SQLTYPES.isNumberType(types[i])) - col.@valueNumeric = value; - else - col.@value = value; - } - - node.appendChild(col); - } - this.appendChild(node); - }, xmlData.changeSet); - - return xmlData.toXMLString() -};