Import: SQL

Creates a data contract from a SQL DDL file. Pass the SQL dialect with --dialect.

{/* AUTOGENERATED EXAMPLE: do not edit by hand; regenerate with the update script. */}

Given this orders.sql:

CREATE TABLE orders (
    order_id TEXT PRIMARY KEY,
    order_timestamp TIMESTAMPTZ NOT NULL,
    customer_id TEXT NOT NULL,
    order_total NUMERIC NOT NULL,
    status TEXT NOT NULL
);

Run:

datacontract import sql --source orders.sql --dialect postgres

to produce the data contract:

version: 1.0.0
kind: DataContract
apiVersion: v3.1.0
id: my-data-contract
name: My Data Contract
status: draft
servers:
- server: postgres
  type: postgres
  database: my_database
  host: my_host
  port: 5432
  schema: public
schema:
- name: orders
  physicalType: table
  logicalType: object
  physicalName: orders
  properties:
  - name: order_id
    physicalType: TEXT
    primaryKey: true
    primaryKeyPosition: 1
    logicalType: string
  - name: order_timestamp
    physicalType: TIMESTAMPTZ
    logicalType: timestamp
    required: true
  - name: customer_id
    physicalType: TEXT
    logicalType: string
    required: true
  - name: order_total
    physicalType: DECIMAL
# …

{/* END AUTOGENERATED EXAMPLE */}