Skip to content
Snippets Groups Projects
Commit d99aeb3a authored by Johannes Goderbauer's avatar Johannes Goderbauer
Browse files

liquibase-lib: extensions for results

parent 10b0b74d
No related branches found
No related tags found
No related merge requests found
import("system.text");
import("system.translate");
import("Util_lib");
import("system.fileIO");
......@@ -27,25 +28,31 @@ function LiquiUtils(){}
* note that the liquibase tables "DATABASECHANGELOG" and "DATABASECHANGELOGLOCK" will never be exported
* (regardless of what you specify here)
* @param {Boolean} [pIncludeClearTableDirective=false] if true, a delete element is added at the beginning of the changeset for the table
* @param {Boolean} [pGenerateChangeSetIdFromArguments=false] if true the id of the changeset will be generated by the passed arguments to this function
*
* @return void
* @return {Object} returns an object that has currently only one property<br/>- exportedTables:Array of tableNames that have been exported
*
*
*/
LiquiUtils.exportAllTablesAsLiquibaseFiles = function(pOutFolderPath, pAuthor, pAlias, pExcludedTables, pIncludeClearTableDirective)
LiquiUtils.exportAllTablesAsLiquibaseFiles = function(pOutFolderPath, pAuthor, pAlias, pExcludedTables, pIncludeClearTableDirective, pGenerateChangeSetIdFromArguments)
{
var excludedTables = ["DATABASECHANGELOG", "DATABASECHANGELOGLOCK"];//liquibase-tables - therefor they shall never be included
if (pExcludedTables)
excludedTables = excludedTables.concat(pExcludedTables);
var alias = pAlias || db.getCurrentAlias();
var tables = db.getTables(alias);
var exportedTables = [];
for (var i = 0, l = tables.length; i < l; i++)
{
if (ArrayUtils.hasElement(excludedTables, tables[i], true))
continue;
var cond = null;
LiquiUtils.exportTableAsLiquibaseFiles(pOutFolderPath, tables[i], null, cond, pAuthor, pIncludeClearTableDirective, alias);
var res = LiquiUtils.exportTableAsLiquibaseFiles(pOutFolderPath, tables[i], null, cond, pAuthor, pIncludeClearTableDirective, alias, pGenerateChangeSetIdFromArguments);
if (res.exported)
exportedTables.push(tables[i]);
}
return {exportedTables: exportedTables}
};
/**
......@@ -59,19 +66,20 @@ LiquiUtils.exportAllTablesAsLiquibaseFiles = function(pOutFolderPath, pAuthor, p
* @param {String} [pAuthor="autogenerated"] author that will be written into the liquibase-changeset
* @param {Boolean} [pIncludeClearTableDirective=false] if true, a delete element is added at the beginning of the changeset for the table
* @param {String} [pAlias=current db-alias] alias where the data will be loaded from
* @param {Boolean} [pGenerateChangeSetIdFromArguments=false] if true the id of the changeset will be generated by the passed arguments to this function
*
* @return {null} returns currently always null
* @return {Object} returns an object that has currently only one property<br/>- exported:boolean if the table has been exported or not
*/
LiquiUtils.exportTableAsLiquibaseFiles = function(pPath, pTableName, pColumns, pCondition, pAuthor, pIncludeClearTableDirective, pAlias)
LiquiUtils.exportTableAsLiquibaseFiles = function(pPath, pTableName, pColumns, pCondition, pAuthor, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments)
{
var resXml = LiquiUtils._getDataXml(pAuthor, pPath, pTableName, pColumns, pCondition, pIncludeClearTableDirective, pAlias);
var resXml = LiquiUtils._getDataXml(pAuthor, pPath, pTableName, pColumns, pCondition, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments);
if (resXml == "")
return null;
return {exported: false};
fileIO.mkdir(pPath, true);
var fullFileName = pPath += "/" + pTableName + ".xml";
fileIO.storeData(fullFileName, resXml, util.DATA_TEXT, false, "UTF8");
return null;
return {exported: true};
};
/**
......@@ -88,15 +96,16 @@ LiquiUtils.exportTableAsLiquibaseFiles = function(pPath, pTableName, pColumns, p
* @param {String} [pCondition=none] db-condition to limit the data that will be exported; if nothing given the whole content will be exported
* @param {Boolean} [pIncludeClearTableDirective=false] if true, a delete element is added at the beginning of the changeset for the table
* @param {String} [pAlias=current db-alias] alias where the data will be loaded from
* @param {Boolean} [pGenerateChangeSetIdFromArguments=false] if true the id of the changeset will be generated by the passed arguments to this function
*
* @return {String} the liquibase-changest in xml-form
*/
LiquiUtils._getDataXml = function(pAuthor, pLobPath, pTableName, pColumns, pCondition, pIncludeClearTableDirective, pAlias)
LiquiUtils._getDataXml = function(pAuthor, pLobPath, pTableName, pColumns, pCondition, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments)
{
var author = pAuthor || "autogenerated";
var alias = pAlias || db.getCurrentAlias();
//cannot be added within jdito code to the XML-object, so instead add it as string
var XML_HEADER_LINE= '<?xml version="1.1" encoding="UTF-8" standalone="no"?>';
var XML_HEADER_LINE = LiquiXmlUtils.xmlHeaderLineStr();
var columns = pColumns || db.getColumns(pTableName, alias);
var dbData = db.table("select " + columns.join(", ") + " from " + pTableName + " " + (pCondition ? "where " + pCondition : ""), alias);
......@@ -128,7 +137,16 @@ LiquiUtils._getDataXml = function(pAuthor, pLobPath, pTableName, pColumns, pCond
});
var columnLen = columns.length;
var changeLogXml = LiquiXmlUtils.databaseChangeLog(author);
var changesetId;
if (pGenerateChangeSetIdFromArguments)
{
changesetId = Array.prototype.slice.call(arguments);//todo: use Array.from instead when supported (>= rhino 1.7.11)
changesetId = changesetId.reduce(function (accumulator, currentValue){
return (currentValue !== null && currentValue !== undefined ? accumulator + JSON.stringify(currentValue) : accumulator);
}, "");
changesetId = text.hash(changesetId, text.HASH_MD5);
}//or otherwise is the changesetId automatically generated within the databaseChangeLogWithChangeSet function
var changeLogXml = LiquiXmlUtils.databaseChangeLogWithChangeSet(author, changesetId);
if (pIncludeClearTableDirective)
changeLogXml.changeSet.appendChild(<delete tableName={pTableName}/>);
dbData.forEach(function(row)
......@@ -158,16 +176,23 @@ LiquiUtils._getDataXml = function(pAuthor, pLobPath, pTableName, pColumns, pCond
*/
function LiquiXmlUtils(){}
//TODO: comments
LiquiXmlUtils.databaseChangeLog = function (pAuthor, pChangeSetId)
LiquiXmlUtils.xmlHeaderLineStr = function()
{
return '<?xml version="1.1" encoding="UTF-8" standalone="no"?>';
};
LiquiXmlUtils.databaseChangeLog = function ()
{
return <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"/>;
};
LiquiXmlUtils.databaseChangeLogWithChangeSet = function (pAuthor, pChangeSetId)
{
if (pChangeSetId == undefined)
pChangeSetId = util.getNewUUID();
var dbcl = <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"/>
;
var dbcl = LiquiXmlUtils.databaseChangeLog();
dbcl.changeSet = <changeSet author={pAuthor} id={pChangeSetId} />;
return dbcl;
};
......@@ -274,7 +299,7 @@ LiquiXTable.prototype.addClobCol = function (pColName, pValue)
throw new Error(translate.withArguments("[%0]it was necessary to create a text-file from a clob-field but no lob-file-path was specified."
+ "The lob-file-path is required when adding long clob-values. value length was %1.", ["LiquiXTable addClobCol", pValue.length]));
var relativeFolderPath = this._name + "/" + pColName + "/clobFiles/";
var fileName = util.getNewUUID() + ".txt";
var fileName = text.hash(pValue, text.HASH_MD5) + ".txt";
fileIO.mkdir(lobBasePath + relativeFolderPath, true);
fileIO.storeData(lobBasePath + relativeFolderPath + fileName, pValue, util.DATA_TEXT, false, "UTF8");
return this.appendIfNotNull(LiquiXmlUtils.colValue(pColName, relativeFolderPath + fileName, "valueClobFile"));
......@@ -290,7 +315,7 @@ LiquiXTable.prototype.addBlobCol = function (pColName, pValue)
throw new Error(translate.withArguments("[%0]it was necessary to create a file from a blob-field but no lob-file-path was specified."
+ "The lob-file-path is required when adding blob-values.", ["LiquiXTable addClobCol"]));
var relativeFolderPath = this._name + "/" + pColName + "/blobFiles/";
var fileName = util.getNewUUID();
var fileName = text.hash(pValue, text.HASH_MD5);
fileIO.mkdir(lobBasePath + relativeFolderPath, true);
fileIO.storeData(lobBasePath + relativeFolderPath + fileName, pValue, util.DATA_BINARY, false);
return this.appendIfNotNull(LiquiXmlUtils.colValue(pColName, relativeFolderPath + fileName, "valueBlobFile"));
......
import("Sql_lib");
import("system.datetime");
import("system.util");
import("system.logging");
import("Liquibase_lib");
import("system.db");
import("system.fileIO");
var alias = SqlUtils.getSystemAlias();
//var alias = "betterDataSys";
//var alias = "betterData";
//var alias = db.getCurrentAlias();
var outFolderPath = "C:\\temp\\generatedData\\" + alias + "\\";
var excludedTables = ["AB_COUNTRYINFO", "AB_LANGUAGE"];
//LiquiUtils.exportAllTablesAsLiquibaseFiles(outFolderPath, null, alias, excludedTables, true);
alias = SqlUtils.getSystemAlias();
outFolderPath = "C:\\temp\\generatedData\\" + alias + "\\";
LiquiUtils.exportTableAsLiquibaseFiles(outFolderPath, "ASYS_USERS", null, "PROPKEY in ('mailserverAlias', 'userserverEnabled') ", null, false, alias);
logging.log("finish");
\ No newline at end of file
throw new Error("proccess not defined")
\ No newline at end of file
<?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>exportLiquibaseContent_serverProcess</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<process>%aditoprj%/process/exportLiquibaseContent_serverProcess/process.js</process>
<alias>Data_alias</alias>
<variants>
<element>EXECUTABLE</element>
</variants>
</process>
import("system.vars");
import("Sql_lib");
import("system.datetime");
import("system.util");
import("system.logging");
import("Liquibase_lib");
import("system.db");
import("system.fileIO");
var alias = "diffAlias";
var outFolderBase = vars.get("$sys.servertemp") + "/" + alias + "/";
var outFolderPath = outFolderBase + "generatedData/";
var excludedTables = ["AB_COUNTRYINFO", "AB_LANGUAGE"];
excludedTables.push("AB_KEYWORD_ATTRIBUTE", "AB_KEYWORD_ATTRIBUTERELATION", "AB_KEYWORD_ENTRY");//TODO: only export parts
var exportRes = LiquiUtils.exportAllTablesAsLiquibaseFiles(outFolderPath, null, alias, excludedTables, true);
var exportedTables = exportRes.exportedTables;
var changeLogData = LiquiXmlUtils.databaseChangeLog("autogenerated");
exportedTables.forEach(function (tableName){
var fileValue = "generatedData/" + tableName + ".xml";
changeLogData.appendChild(<include relativeToChangelogFile="true" file={
fileValue
}/>);
});
changeLogData = LiquiXmlUtils.xmlHeaderLineStr() + "\n" + changeLogData.toString();
fileIO.storeData(outFolderBase + "changelog.xml", changeLogData, util.DATA_TEXT, false, "UTF8");
logging.log("liquibase data (" + exportedTables.length + " tables) exported into folder:" + outFolderPath);
//remember to change the alias db to the data_system when running binaries exporter:
//LiquiUtils.exportTableAsLiquibaseFiles(outFolderPath, "ASYS_BINARIES", null, null, null, false, alias);
//alias = SqlUtils.getSystemAlias();
//outFolderPath = "C:\\temp\\generatedData\\" + alias + "\\";
//LiquiUtils.exportTableAsLiquibaseFiles(outFolderPath, "ASYS_USERS", null, "PROPKEY in ('mailserverAlias', 'userserverEnabled') ", null, false, alias);
//logging.log("finish");
\ No newline at end of file
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