Skip to content

core, relational: select by rules what is read from a database, written as DDL and compared - #91

Merged
stbischof merged 5 commits into
eclipse-daanse:mainfrom
stbischof:feature/selection
Nov 13, 2026
Merged

stbischof merged 5 commits into
eclipse-daanse:mainfrom
stbischof:feature/selection

Conversation

@stbischof

Copy link
Copy Markdown
Contributor

Reading a database into CWM, writing DDL from a model and comparing the two each chose their part of a model in their own way: schema and table filters and include switches when reading, a list of schemas and a set of features when writing. Now one notion does it, from the util packages of the models up to the relational tooling: a Selection of include and exclude rules on model elements, written in code or as text, one rule per line.

schema:sales                        # everything in the schema sales
!table:*_log                        # without the tables whose name ends in _log
!is:constraint                      # without unique constraints, checks and foreign keys
!tag:daanse.ddl.documentary=true    # without what is marked as documentary

Commits

  1. Selecting by rules (objectmodel.core, resource.relational, businessinformation, resource.relational.privilege). Selection with ElementRules (name, path, kind, tag, stereotype, owner) and the text form in the words of a RuleVocabulary that the models extend: is:constraint, is:documentary, is:materialized, is:comment, is:privilege, is:role, is:user. Selections lists what a selection selects or cuts a copy of a model down to it; consequence rules decide what a reference from what stays to what is left out brings along or removes, and the result names each element left out with its reason. QualifiedNames and Stereotypes read names and stereotypes; RelationalNames is the one rule for the names of unnamed keys, constraints, indexes and triggers.
  2. Loading models (emf/standalone, maven). Every goal of cwm-ecore, fennec-eorm and fennec-atlas loads its model through CwmPackages.loadModel and can be skipped; CwmPackages.save writes a copy and leaves the model where it was. maven/README.md describes the plugins and how they fit together.
  3. Reading, writing and comparing (load.jdbc, load.privilege, ddl, ddl.render, diff; liquibase.render, sql.resolve and the test kit follow).
    • The loader reads roles, users and privileges along with the tables, as the selection selects them, and skips the queries for a kind the selection leaves out.
    • The DDL generator writes what the model holds, in one order over all schemas, the drop script in the exact reverse. Whatever a dialect cannot write is either written plainer or left out with a warning, or, with DdlSettings.strict, the generation fails and names every case. Materialized views, partial indexes and descending index columns are written where the dialect has them.
    • CatalogDiffer compares catalogs in both directions. Named tolerances, collected per database in Tolerance.roundTrip(dialect), let pass what a database spells its own way. A migration is written by the same code as the create script.
    • Round trips on H2, PostgreSQL, MariaDB, MySQL, SQL Server, Oracle and DuckDB.
  4. Deferrable foreign keys and comments on views: written where the dialect has them, compared and migrated. The deferrability of unique constraints, checks and foreign keys defaults to notDeferrable, as in SQL.
  5. Functions and procedures: written in the languages a dialect writes routines in, dropped by their signature, compared by the parameters that pass values, created, dropped and replaced by a migration; a grant on one of several overloads names it by its parameter types.

Breaking

The old ways of choosing are gone:

  • JdbcToCwmConfig loses its schema and table filters and its include… switches.
  • The DDL generator loses its Feature set.
  • The privilege loader loses PrivilegeLoadResult.
  • ViewBodyChange becomes ViewChange.

None of this has been released.

Needs

The SQL dialect API of eclipse-daanse/org.eclipse.daanse.sql#92, published as a snapshot: deferrable foreign keys, comments on views, functions and procedures, roles.

Follows

These come separately: the module that reads a database into CWM and writes a model into it without OSGi, the Maven goals cwm-ddl:generate, cwm-jdbc:import and cwm-jdbc:export, and an example.

…and as text

Reading a database into CWM, writing DDL from a model and comparing the
two each choose their part of a model. The core now has one notion for
it: a Selection of include and exclude rules on model elements, written
in code as ElementRules or as text, one rule per line,
<selector>:<pattern> with a leading ! to exclude, in the words of a
RuleVocabulary. Selections lists the selected elements of a type or
cuts a copy down to a selection; ConsequenceRules decide what a
reference from what stays to what is left out brings along or removes,
and the result names what was left out and retained, each with its
reason. QualifiedNames and Stereotypes read names and brands; the ids of
an unnamed root are alike in every locale.

The relational, business information and privilege models bring their
words and consequences: RelationalRules with is:constraint,
is:documentary and is:materialized, BusinessInformationRules with
is:comment, PrivilegeRules with is:privilege, is:role and is:user.
RelationalNames is the one rule for the names of unnamed keys,
constraints, indexes and triggers, and keeps the specific name a
database gives an overload of a routine. Tables, ForeignKeys, SQLIndexes
and the other helpers gain what the readers and writers share.

The tests of the privilege loader ask a party whether it is a role or
a user, as the stereotype helpers now do, and read their parties from
one package.

Left out: the readers and writers that use the rules, which follow, and
the default of the deferrability of keys.

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
… and can be skipped

CwmPackages.loadModel loads a CWM model with the files it refers to,
for every plugin alike, and save writes a copy with ids built from the
name path and leaves the model where it was. The goals of cwm-ecore,
fennec-eorm and fennec-atlas load their models through it and can be
skipped; maven/README.md describes the plugins and how they fit
together.

Left out: the goals of the relational tooling, which come with their
own modules.

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
The relational tooling chooses its part of a catalog by the rules of the
model and keeps the names the model gives.

The loader reads a database into a catalog with roles, users and
privileges as a selection selects, skipping a kind the selection
excludes; it names what a database reports without a name by
RelationalNames, binds the parameters of an overload by its specific
name, leaves out the index a database makes for a foreign key and an
INSTEAD OF trigger, and reads the comments SQL Server and Oracle keep
apart from their drivers.

The DDL generator writes create and drop scripts per SQL dialect in one
order over all schemas, the drop script the exact reverse; a constraint
the dialect cannot add to an existing table goes into CREATE TABLE, and
each statement names its element. Users are created where the dialect
has users. What a dialect cannot write as the model has it is one rule:
written plainer or left out with a warning, or, with DdlSettings.strict,
a failure that names every case. Materialized views, indexes over part
of the rows and descending index columns are written where the dialect
has them. ddl.render writes the scripts of a cut model per dialect into
files.

The differ compares catalogs both ways with named tolerances for what a
database spells its own way, and the migration is written by the code
of the create script. The Liquibase writer, the SQL resolver and the
test kit follow. Round trips run on H2, PostgreSQL, MariaDB, MySQL, SQL
Server, Oracle and DuckDB.

Left out: the deferrability of foreign keys, the comments on views as
the dialect says it keeps them, and functions and procedures, which need
more of the SQL dialect API; the modules without OSGi and the Maven
goals, which come with their own modules.

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
A deferrable foreign key is written DEFERRABLE INITIALLY DEFERRED or
INITIALLY IMMEDIATE, in CREATE TABLE as in ALTER TABLE, where the
dialect has deferrable keys, and not deferrable elsewhere, a case the
dialect cannot write; the differ compares the deferrability with the
key. The deferrability of unique constraints, checks and foreign keys
defaults to notDeferrable, as in SQL, so INITIALLY DEFERRED is told
apart from nothing stated.

Whether a dialect writes a comment on a view and its columns is asked
of the dialect in one place, and one code path writes the comments of
tables, views and their columns. The differ compares the comments of
paired views; a changed one becomes SetViewComment, and a view a
migration creates brings its comments along. The loader reads the word
VIEW, which MySQL and MariaDB report for every view, as no comment.

Left out: functions and procedures.

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
…nd migrated

A function or procedure with a body in a language the dialect writes
routines in is written with CREATE FUNCTION or CREATE PROCEDURE, after
the views and before the triggers: its parameters with their direction
and their types by name, the type a function returns, the body as it
is; the drop script drops it by its signature, and a grant on one of
several overloads names it by the same types. The procedure a trigger
keeps its body in comes with the trigger only. Where the dialect writes
no routine in the language, cannot write a parameter, or the model does
not say the type a function returns, the routine is a case the dialect
cannot write, and so is a comment on a routine.

The loader reads the language of a body and takes the unnamed OUT
parameter Oracle and SQL Server report for the result of a function as
its RETURN parameter. The differ tells routines apart by the parameters
that pass values and compares the result where both state one. A
migration creates, drops and replaces routines, with OR REPLACE where
the dialect writes it; the Liquibase writer leaves them to the dialects.

Left out: the export without OSGi, the Maven goals and the example,
which come with their own modules.

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
@stbischof
stbischof merged commit 4c6ecce into eclipse-daanse:main Nov 13, 2026
2 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant