diff --git a/process/Sql_lib/process.js b/process/Sql_lib/process.js index 082ba83b99f8234b2a0606420fd87a859ce21922..161f32c580fca1ec9b6741557140f4bf14cc7c2b 100644 --- a/process/Sql_lib/process.js +++ b/process/Sql_lib/process.js @@ -1,5 +1,7 @@ +import("system.logging"); import("system.translate"); import("system.vars"); +import("system.util"); import("system.db"); import("system.datetime"); import("system.tools"); @@ -1369,3 +1371,54 @@ SqlUtils.getResolvingCaseWhen = function(pKeyValueArray, pDbFieldName, pLocale) resSql = [resSql, preparedValues]; return resSql; }; + +SqlUtils.exportToLiquibase = function(pAuthor, pTableName, pColumns, pNewUUIDForIndexes) +{ + 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); + 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]; + + if (SQLTYPES.isNumberType(types[i])) + col.@valueNumeric = value; + else + col.@value = value; + + node.appendChild(col); + } + this.appendChild(node); + }, xmlData.changeSet); + + //xmlData.changeSet.push(<insert>6</insert>); + + return xmlData.toXMLString() +};