From 48f9e1991345856ae7dbb81430b97683640ebd10 Mon Sep 17 00:00:00 2001 From: "j.goderbauer" <j.goderbauer@adito.de> Date: Wed, 25 Nov 2020 10:32:47 +0100 Subject: [PATCH] Liquibase: Prepare lib for generating liquiscritps for upgrade --- process/Liquibase_lib/process.js | 39 +++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/process/Liquibase_lib/process.js b/process/Liquibase_lib/process.js index 65cfed3485..b3e976bbae 100644 --- a/process/Liquibase_lib/process.js +++ b/process/Liquibase_lib/process.js @@ -77,7 +77,7 @@ LiquiUtils.exportAllTablesAsLiquibaseFiles = function(pOutFolderPath, pAuthor, p */ LiquiUtils.exportTableAsLiquibaseFiles = function(pPath, pTableName, pColumns, pCondition, pAuthor, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments, pBlobCallbackFn, pFileName) { - var resXml = LiquiUtils._getDataXml(pAuthor, pPath, pTableName, pColumns, pCondition, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments, pBlobCallbackFn); + var resXml = LiquiUtils.getDataXmlFromDB(pAuthor, pPath, pTableName, pColumns, pCondition, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments, pBlobCallbackFn); if (resXml == "") return {exported: false}; var fileName = pFileName || pTableName; @@ -108,17 +108,44 @@ LiquiUtils.exportTableAsLiquibaseFiles = function(pPath, pTableName, pColumns, p * * @return {String} the liquibase-changest in xml-form */ -LiquiUtils._getDataXml = function(pAuthor, pLobPath, pTableName, pColumns, pCondition, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments, pBlobCallbackFn) +LiquiUtils.getDataXmlFromDB = function(pAuthor, pLobPath, pTableName, pColumns, pCondition, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments, pBlobCallbackFn) { + var alias = pAlias || db.getCurrentAlias(); + var dbData = db.table("select " + columns.join(", ") + " from " + pTableName + " " + (pCondition ? "where " + pCondition : ""), alias); + return LiquiUtils.getDataXml(pAuthor, pLobPath, pTableName, pColumns, dbData, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments, pBlobCallbackFn); +} + +/** +* generates from a table a xml-changeset for liquibase; determines the correct liquibase-xml-attribute by db-column-type; +* if a value is empty it will not be added to the xml; will load the data at once (no paging); +* if the data contains a long CLOB-value that value has to and will be stored on the server-filesystem; +* if the data contains any BLOB-value that value has to and will be stored on the server-filesystem; +* +* @param {String} [pAuthor="autogenerated"] author that will be written into the changeset +* @param {String} [pLobPath=not set] file-path where lob files and folders will be created; the folder must be on the server; +* if you've no lob-fields you don't have to specify somehing here +* @param {String} pTableName name of the DB-table that will be exported; this is also the name of the file that is stored +* @param {Array} [pColumns=all columns within the table] db-columns within the table that will be exported +* @param {String} [pData=undefined] 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 +* @param {function} [pBlobCallbackFn=undefined] function that returns the filename for a stored file (only for BLOB-databasetypes). <br/> +* if nothing is specified, the filename is generated automatically with a hash of the content <br/> +* The callback function retrieves all the arguments of the LiquiXTable.prototype.addBlobCol-function +* +* @return {String} the liquibase-changest in xml-form +*/ +LiquiUtils.getDataXml = function(pAuthor, pLobPath, pTableName, pColumns, pData, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments, pBlobCallbackFn) +{ + if (!pData) + return ""; 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 = LiquiXmlUtils.xmlHeaderLineStr(); var columns = pColumns || db.getColumns(pTableName, alias); - var dbData = db.table("select " + columns.join(", ") + " from " + pTableName + " " + (pCondition ? "where " + pCondition : ""), alias); - if (dbData.length == 0) - return ""; var colTypes = db.getColumnTypes(pTableName, columns, alias);//needed to determine the correct liquibase function //every type has its function that accepts a columnName- and a value-parameter //so let's dertermine once the corresponding funtion to its type for faster access @@ -157,7 +184,7 @@ LiquiUtils._getDataXml = function(pAuthor, pLobPath, pTableName, pColumns, pCond var changeLogXml = LiquiXmlUtils.databaseChangeLogWithChangeSet(author, changesetId); if (pIncludeClearTableDirective) changeLogXml.changeSet.appendChild(<delete tableName={pTableName}/>); - dbData.forEach(function(row) + pData.forEach(function(row) { var rowObj = {}; for (let i = 0; i < columnLen; i++) -- GitLab