YAML Format Reference

This page describes the YAML format used by dbtoyaml and yamltodb.

Top-level structure

schema <name>:
  owner: <username>
  description: <text>
  table <name>:
    ...

Schema properties

Property

Type

Description

owner

string

Schema owner

description

string

Schema comment

Table properties

Property

Type

Description

owner

string

Table owner

description

string

Table comment

columns

list

Column definitions (list of single-key maps)

primary_key

map

Primary key constraint

foreign_keys

map

Foreign key constraints

check_constraints

map

Check constraints

unique_constraints

map

Unique constraints

Column properties

Property

Type

Description

type

string

PostgreSQL data type

not_null

boolean

NOT NULL constraint

default

string

Default value expression

description

string

Column comment

Example

schema public:
  table film:
    owner: postgres
    columns:
      - id:
          type: integer
          not_null: true
      - title:
          type: character varying(32)
          not_null: true
      - release_year:
          type: integer
          not_null: true
      - length:
          type: smallint
      - rating:
          type: character(5)
    primary_key:
      film_pkey:
        columns:
          - id
    check_constraints:
      film_length_check:
        columns:
          - length
        expression: ((length > 0) AND (length < 10000))
      film_release_year_check:
        columns:
          - release_year
        expression: (release_year >= 1888)
  owner: pg_database_owner
  description: standard public schema

The columns value is a list of single-key maps (one entry per column), which matches the format produced by Pyrseas and is accepted by both yamltodb implementations. yamltodb also accepts the equivalent map form (columns: {id: {...}, ...}) for backward compatibility.