Commit b555b76
committed
feat: Add IBM Db2 engine adapter with CI/CD integration
Adds a complete IBM Db2 LUW engine adapter for SQLMesh, including
connection configuration, Docker-based CI, integration tests, and
engine-specific documentation.
## What is included
### Core adapter (sqlmesh/core/engine_adapter/db2.py)
- Db2EngineAdapter implementing all standard SQLMesh engine operations
- SYSCAT-based metadata queries (columns, tables, schemas, indexes, views)
- CTAS with mandatory WITH DATA clause
- MERGE INTO with TARGET/SOURCE alias substitution
- CREATE INDEX with SYSCAT.INDEXES existence check
- CREATE/DROP SCHEMA using SYSCAT.SCHEMATA
- DROP VIEW using SYSCAT.VIEWS existence check
- GRANT/REVOKE using SYSCAT.TABAUTH (not INFORMATION_SCHEMA)
- Truncate implemented as DELETE FROM (Db2 has no TRUNCATE)
- TIMESTAMPTZ stripped to TIMESTAMP (SQL0180N fix)
- normalize_identifiers before quoting (SQL0204N fix)
- catalog_support = SINGLE_CATALOG_ONLY (Db2 databases are isolated)
- SUPPORTED_DROP_CASCADE_OBJECT_KINDS = [] (SQL0104N fix)
- MAX_IDENTIFIER_LENGTH = 128
- set_current_catalog via CONNECT TO
### Connection config (sqlmesh/core/config/connection.py)
- Db2ConnectionConfig with host/port/database/username/password/db2_schema
- SSL options (ssl, ssl_cert, ssl_key, ssl_ca)
- get_catalog() returns .upper() to match Db2 UPPERCASE normalisation
- Excluded from FORBIDDEN_STATE_SYNC_ENGINES with explanation comment
(Db2 rejects table names starting with underscore)
### Framework integration
- sqlmesh/core/engine_adapter/__init__.py: conditional import guarded
by Python >= 3.10 AND find_spec('db2_sqlglot') — prevents import
crash in environments without the db2 extra installed
- sqlmesh/utils/migration.py: db2 added to MAX_TEXT_INDEX_LENGTH
(255) and blob_text_type() returns VARCHAR(32000)
## CI / infrastructure
- .github/workflows/pr.yaml: db2 added to engine-tests-docker matrix
- .github/scripts/install-prerequisites.sh: db2 installs libxml2-dev
- .github/scripts/wait-for-db.sh: db2_ready() readiness probe
- tests/.../docker/compose.db2.yaml: IBM Db2 Community Edition image
- Makefile: db2-test target with junitxml; db2 added to install-dev
- pyproject.toml: db2 optional extra + pytest marker
## Tests
- tests/core/engine_adapter/test_db2.py: 22 unit tests (all passing)
- tests/core/engine_adapter/integration/test_integration_db2.py:
18 Db2-specific integration tests
- tests/core/engine_adapter/integration/__init__.py: SYSCAT comment
queries, role-based grant infrastructure for Db2
- tests/core/engine_adapter/integration/config.yaml: inttest_db2
gateway with DuckDB state_connection
- tests/core/engine_adapter/integration/test_integration.py:
skip blocks with documented reasons for 20 tests; adaptations
for uppercase identifiers, TIMESTAMPTZ, grants
## CI results (stable baseline on Docker Db2 Community Edition)
- 81 passed · 46 skipped · 0 failed
## Known limitations and skipped tests
### SCD Type 2 (4 tests skipped)
Db2 SQL preprocessor treats identifiers starting with '_' as
conditional compilation directives (SQL20521N reason 7). SQLMesh
generates _exists, _key0, _row_number, _t as aliases. Additionally
SCD staging uses CTAS which Db2 does not support natively.
Fix: override _scd_type_2() in Db2EngineAdapter to rename aliases.
### View comments (3 tests skipped)
Db2 has no COMMENT ON VIEW statement (SQL0104N).
### test_sushi (1 test skipped)
CREATE SCHEMA IF NOT EXISTS is not valid Db2 SQL (SQL0104N).
Fix: add create_sql() override to db2-sqlglot-dialect to strip
IF NOT EXISTS from CREATE SCHEMA.
### ctx.create_context() tests (6 tests skipped)
shared.py:346 uses a case-sensitive == comparison between
catalog_name (TESTDB, Db2 uppercase) and _default_catalog
(testdb, duckdb-dialect lowercase). This is a one-line upstream
fix in shared.py that cannot be made in this PR:
catalog_name.upper() != (engine_adapter._default_catalog or '').upper()
## Documentation
- docs/integrations/engines/db2.md: connection options, state
connection guidance, limitations, example config
- docs/integrations/overview.md: Db2 entry added
- docs/guides/connections.md: Db2 link added
- mkdocs.yml: db2.md nav entry added
Signed-off-by: IBM Db2 Eco System <Hdm-dev-persona-db2-eco-system@ibm.com>1 parent b1e36b9 commit b555b76
20 files changed
Lines changed: 2243 additions & 16 deletions
File tree
- .github
- scripts
- workflows
- docs
- guides
- integrations
- engines
- sqlmesh
- core
- config
- engine_adapter
- utils
- tests/core
- engine_adapter
- integration
- docker
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
93 | 107 | | |
94 | 108 | | |
95 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
255 | | - | |
| 255 | + | |
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
225 | 228 | | |
226 | 229 | | |
227 | 230 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
115 | 119 | | |
116 | 120 | | |
117 | 121 | | |
| |||
270 | 274 | | |
271 | 275 | | |
272 | 276 | | |
| 277 | + | |
273 | 278 | | |
274 | 279 | | |
275 | 280 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
| |||
2602 | 2605 | | |
2603 | 2606 | | |
2604 | 2607 | | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
| 2628 | + | |
| 2629 | + | |
| 2630 | + | |
| 2631 | + | |
| 2632 | + | |
| 2633 | + | |
| 2634 | + | |
| 2635 | + | |
| 2636 | + | |
| 2637 | + | |
| 2638 | + | |
| 2639 | + | |
| 2640 | + | |
| 2641 | + | |
| 2642 | + | |
| 2643 | + | |
| 2644 | + | |
| 2645 | + | |
| 2646 | + | |
| 2647 | + | |
| 2648 | + | |
| 2649 | + | |
| 2650 | + | |
| 2651 | + | |
| 2652 | + | |
| 2653 | + | |
| 2654 | + | |
| 2655 | + | |
| 2656 | + | |
| 2657 | + | |
| 2658 | + | |
| 2659 | + | |
| 2660 | + | |
| 2661 | + | |
| 2662 | + | |
| 2663 | + | |
| 2664 | + | |
| 2665 | + | |
| 2666 | + | |
| 2667 | + | |
| 2668 | + | |
| 2669 | + | |
| 2670 | + | |
| 2671 | + | |
| 2672 | + | |
| 2673 | + | |
| 2674 | + | |
| 2675 | + | |
| 2676 | + | |
| 2677 | + | |
| 2678 | + | |
| 2679 | + | |
| 2680 | + | |
| 2681 | + | |
| 2682 | + | |
| 2683 | + | |
| 2684 | + | |
| 2685 | + | |
| 2686 | + | |
| 2687 | + | |
| 2688 | + | |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
| 2692 | + | |
2605 | 2693 | | |
2606 | 2694 | | |
2607 | 2695 | | |
| |||
0 commit comments