Skip to content
Snippets Groups Projects
Commit 2d584da1 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

add DB to Liquibase-function

parent 8132ae19
No related branches found
No related tags found
No related merge requests found
import("system.logging");
import("system.translate"); import("system.translate");
import("system.vars"); import("system.vars");
import("system.util");
import("system.db"); import("system.db");
import("system.datetime"); import("system.datetime");
import("system.tools"); import("system.tools");
...@@ -1369,3 +1371,54 @@ SqlUtils.getResolvingCaseWhen = function(pKeyValueArray, pDbFieldName, pLocale) ...@@ -1369,3 +1371,54 @@ SqlUtils.getResolvingCaseWhen = function(pKeyValueArray, pDbFieldName, pLocale)
resSql = [resSql, preparedValues]; resSql = [resSql, preparedValues];
return resSql; 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()
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment