Skip to content

Commit

Permalink
refs #3114 improved schema output when aliging schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnich committed Nov 15, 2018
1 parent d148d69 commit 4d8893c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
3 changes: 3 additions & 0 deletions doxygen/lang/900_release_notes.dox.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@
- <a href="../../modules/RestSchemaValidator/html/index.html">RestSchemaValidator</a> module changes:
- Updated the default validator to try all serialization methods if multiple methods are available and one fails
(<a href="https://github.com/qorelanguage/qore/issues/2831">issue 2831</a>)
- <a href="../../modules/Schema/html/index.html">Schema</a> module changes:
- improved logging output when aligning schemas
(<a href="https://github.com/qorelanguage/qore/issues/3114">issue 3114</a>)
- <a href="../../modules/SqlUtil/html/index.html">SqlUtil</a> module changes:
- Deprecated \c AbstractTable::getRowIterator() for \c AbstractTable::getStatement()
(<a href="https://github.com/qorelanguage/qore/issues/2326">issue 2326</a>)
Expand Down
58 changes: 40 additions & 18 deletions qlib/Schema.qm
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
DEALINGS IN THE SOFTWARE.
*/

# this module requires Qore 0.8.13 or better
%requires qore >= 0.8.13
# minimum Qore version
%requires qore >= 0.9

# requires the SqlUtil module
%requires SqlUtil >= 1.2
%requires SqlUtil >= 1.5

# requires the Util module
%requires Util >= 1.1
Expand All @@ -44,7 +44,7 @@
%strict-args

module Schema {
version = "1.2";
version = "1.3";
desc = "user module for working with SQL schemas";
author = "David Nichols <david@qore.org>";
url = "http://qore.org";
Expand All @@ -71,6 +71,10 @@ module Schema {

@section schema_relnotes Schema Module Release History

@subsection schema_v1_3 Schema Module v1.3
- improved logging output when performing schema alignments
(<a href="https://github.com/qorelanguage/qore/issues/3114">issue 3114</a>)

@subsection schema_v1_2 Schema Module v1.2
- added the following public functions: (<a href="https://github.com/qorelanguage/qore/issues/1851">issue 1851</a>)
- Schema::c_blob()
Expand Down Expand Up @@ -529,15 +533,15 @@ public namespace Schema {

all_options = AbstractSchema::combineOptions(creation_options, column_options);

schema = (
schema = {
"tables": getTables(),
"sequences": getSequences(),
"types": getTypes(),
"functions": getFunctions(),
"procedures": getProcedures(),
"packages": getPackages(),
"materialized_views": getMaterializedViews(),
);
};
}

#! returns the name of the schema
Expand Down Expand Up @@ -648,14 +652,17 @@ public namespace Schema {
}
%endif

if (sch.dot_count)
if (sch.dot_count) {
logProgress("\n");
if (sch.change_count)
sch.dot_count = 0;
}
if (sch.change_count) {
log("%d change%s made; schema is now at version %s", sch.change_count, sch.change_count == 1 ? "" : "s", version);
else
} else {
log("no changes made to schema version %s", version);
}

doPostAlignment(table_cache, first_time_install, initial_schema_info);
doPostAlignment(table_cache, first_time_install, initial_schema_info, verbose);

*hash strict_data = getStrictReferenceDataHash();
*hash ref_data = getReferenceDataHash();
Expand All @@ -666,35 +673,45 @@ public namespace Schema {
hash sh;

if (strict_data || ref_data || co_data || insert_only_data) {
log("verifying reference data");
if (verbose != 1) {
log("verifying reference data");
} else {
logProgress("verifying reference data: ");
}

int upsert_strategy = getUpsertStrategy(first_time_install);

# install "strict reference data", where there can be no other rows in the table
if (strict_data)
if (strict_data) {
map AbstractSchema::doTable(table_cache{$1.key}, $1.value, upsert_strategy, True, verbose, \sh), strict_data.pairIterator();
}

# ensure that "normal" reference data is in place
if (ref_data)
if (ref_data) {
map AbstractSchema::doTable(table_cache{$1.key}, $1.value, upsert_strategy, False, verbose, \sh), ref_data.pairIterator();
}

# do "insert-only" data
if (insert_only_data)
if (insert_only_data) {
map AbstractSchema::doTable(table_cache{$1.key}, $1.value, AbstractTable::UpsertInsertOnly, False, verbose, \sh), insert_only_data.pairIterator();
}

# do "create only" data
if (co_data && first_time_install)
if (co_data && first_time_install) {
map AbstractSchema::doTable(table_cache{$1.key}, $1.value, upsert_strategy, False, verbose, \sh), co_data.pairIterator();
}

postDataActions(first_time_install);

if (!verbose)
if (!verbose) {
logProgress("\n");
}

if (!sh)
if (!sh) {
log("reference data: OK (no changes)");
else
} else {
log("reference data: %s", (foldl $1 + ", " + $2, (map sprintf("%s: %d", $1.key, $1.value), sh.pairIterator())));
}
}

return sch.change_count + sh.size();
Expand Down Expand Up @@ -992,6 +1009,11 @@ public namespace Schema {
return True;
}

#! this method is called after schema structural alignment has been executed but before schema reference data management
private doPostAlignment(Tables table_cache, bool first_time_install, *hash initial_schema_info, int verbose) {
doPostAlignment(table_cache, first_time_install, initial_schema_info);
}

#! this method is called after schema structural alignment has been executed but before schema reference data management
private doPostAlignment(Tables table_cache, bool first_time_install, *hash initial_schema_info) {
}
Expand Down

0 comments on commit 4d8893c

Please sign in to comment.