yamltodb - YAML to Database

yamltodb — generate SQL statements to update a PostgreSQL database to match the schema specified in YAML files

Synopsis

yamltodb [option...] dbname spec

Description

yamltodb is a utility for generating SQL statements to update a PostgreSQL database so that it will match the schema specified in YAML-formatted specification file(s).

For example, given the sample output shown under dbtoyaml - Database to YAML, yamltodb, when run against a newly-created database, outputs the following SQL statements:

CREATE TABLE public.film (id integer NOT NULL, title character varying(32))
ALTER TABLE public.film ADD CONSTRAINT film_pkey PRIMARY KEY (id)

Positional arguments

dbname

The name of the database whose schema is to be analyzed.

spec

Path to the YAML file(s)

Options

yamltodb accepts the following arguments (in addition to the Common Command Line Options):

-B, --single-transaction

Wrap the generated statements in a single transaction (BEGIN/COMMIT).

-o <file>, --output <file>

Send the generated SQL statements to the specified file name. By default, they are printed to standard output.

-u, --update

Execute the generated statements against the database mentioned in dbname. This implies the --single-transaction option.

Examples

To generate SQL statements without executing it:

yamltodb testdb testdb.yaml

To write the SQL to a file without executing:

yamltodb -o testdb.sql testdb testdb.yaml

To apply changes directly:

yamltodb testdb testdb.yaml --update

To wrap the output in a single transaction:

yamltodb testdb testdb.yaml --single-transaction

To connect to a specific host and port:

yamltodb -H somehost -p 5433 testdb testdb.yaml --update