Skip to content

Add Oracle import - #1440

Merged
andredlng merged 1 commit into
mainfrom
import-oracle
Jul 28, 2026
Merged

Add Oracle import#1440
andredlng merged 1 commit into
mainfrom
import-oracle

Conversation

@andredlng

Copy link
Copy Markdown
Collaborator

Summary

Adds datacontract import oracle, which creates a data contract from a live Oracle database:

datacontract import oracle --source localhost --service-name XEPDB1 --schema ADMIN --output datacontract.yaml

The guide previously told users to pull the DDL out of DBMS_METADATA.GET_DDL, import the file with import sql --dialect oracle, and then fill in a servers block of placeholder values.

The length rule is shared, not duplicated. Oracle reports a DATA_LENGTH for every column, but it is only part of the declared type for character and raw types — otherwise a DATE (length 7) would become DATE(7) and a CLOB (length 4000) CLOB(4000), neither of which matches what the test path reads back. That rule already existed inside native_type._map_reconstructed; it is now a named function both paths call.

--schema is upper-cased, since Oracle stores identifiers that way and a lower-case owner matches nothing.

Verified against a real Oracle

Import followed by datacontract test on the unedited file: 16/16 checks passed. The catalog for the seeded table shows why the length rule matters:

ORDER_ID    VARCHAR2      len 36    -> VARCHAR2(36)
ORDER_TOTAL NUMBER        len 22, precision 10, scale 2 -> NUMBER(10,2)
ORDERED_AT  TIMESTAMP(6)  len 11    -> TIMESTAMP(6)
NOTES       CLOB          len 4000  -> CLOB
CREATED_ON  DATE          len 7     -> DATE

A bug only the real run could find: Oracle returns catalog numbers as Decimal, and the first contract came out with

maxLength: !!python/object/apply:decimal.Decimal
- '36'

— a Python-specific YAML tag that no other tool can read and yaml.safe_load rejects. They are coerced to int, and a test asserts no !!python tag appears in the output.

Testing

tests/test_import_oracle.py — 10 tests. The seven that need a database are marked slow, matching test_test_oracle_xe.py, so they run in the dedicated CI job rather than on every invocation; the three argument-validation tests need no container. All ten pass locally against gvenzl/oracle-xe:21-slim-faststart, and the existing Oracle suite still passes.

Docs

New imports/oracle.md; testing/oracle.md gets the one-command step 3 with the DBMS_METADATA recipe reduced to a fallback, and step 2 renamed to "Authenticate" for consistency.

Create a data contract from a live Oracle database with `datacontract import
oracle`, replacing a recipe that told users to pull the DDL out of
DBMS_METADATA, import the file, and then fill in a placeholder servers block by
hand.

Oracle reports a DATA_LENGTH for every column, but it only belongs to the
declared type for character and raw types, so a DATE would otherwise become
DATE(7). The rule that the test path already applied when reading this catalog
back is now shared with the import rather than duplicated.

Catalog numbers arrive as Decimal, which YAML writes as a Python-specific tag;
they are coerced to int so the contract stays readable by other tools.
@andredlng andredlng self-assigned this Jul 28, 2026
@github-actions

Copy link
Copy Markdown

📖 Docs preview

Preview site: https://brave-water-0cee36e03-1440.westeurope.7.azurestaticapps.net

Changed pages (most-changed first):

@andredlng
andredlng merged commit 82a6e47 into main Jul 28, 2026
16 checks passed
@andredlng
andredlng deleted the import-oracle branch July 28, 2026 12:38
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