Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

In yamltodb, exit with status 2 if statements were output.

 * docs/yamltodb.rst: Document exit statuses.  Add paragraph about use
   of status 0 for verifying no changes were made.  Reformat some
   options for clarity.
 * pyrseas/yamltodb.py: If statements were output, exit with status 2.
  • Loading branch information...
commit 38772f212d1ba49e1a1c6a5f20ab2158c922385d 1 parent 2c2d024
@jmafc jmafc authored
Showing with 26 additions and 10 deletions.
  1. +22 −7 docs/yamltodb.rst
  2. +4 −3 pyrseas/yamltodb.py
View
29 docs/yamltodb.rst
@@ -38,38 +38,53 @@ For example, given the input file shown under :doc:`dbtoyaml`,
ALTER TABLE t1 ADD CONSTRAINT t1_pkey PRIMARY KEY (c1);
ALTER TABLE t1 ADD CONSTRAINT t1_c2_fkey FOREIGN KEY (c2) REFERENCES s1.t2 (c21);
+:program:`yamltodb` can also be used to verify that a database has not
+changed, i.e., that it matches the input YAML specification (see `Exit
+status`_ 0 below).
+
Options
-------
:program:`yamltodb` accepts the following command-line arguments (in
addition to the :doc:`cmdargs`):
-dbname
+**dbname**
Specifies the name of the database whose schema is to analyzed.
-spec
+**spec**
Specifies the location of the YAML specification. If this is
omitted or specified as a single or double dash, the specification
is read from the program's standard input.
--n `schema`, ---schema= `schema`
+-n **schema**, ``--schema=`` **schema**
- Compare only a schema matching `schema`. By default, all schemas
+ Compare only a schema matching **schema**. By default, all schemas
are compared. Multiple schemas can be compared by using multiple
``-n`` switches.
--1\, --single-transaction
+-1\, ``--single-transaction``
Wrap the generated statements in BEGIN/COMMIT. This ensures that
either all the statements complete successfully, or no changes are
applied.
--u\, --update
+-u\, ``--update``
Execute the generated statements against the database mentioned in
- ``dbname``. This implies the --single-transaction option.
+ **dbname**. This implies the ``--single-transaction`` option.
+
+Exit status
+~~~~~~~~~~~
+
+0    if OK (no differences found)
+
+1    if there was an error in processing, particularly applicable if
+``--update`` was used
+
+2    if differences were found: SQL statements were generated, and
+applied if ``--update`` was used
Examples
--------
View
7 pyrseas/yamltodb.py
@@ -42,8 +42,8 @@ def main(host='localhost', port=5432):
if sch not in kschlist and sch.startswith('schema '):
del inmap[sch]
stmts = db.diff_map(inmap, args.schlist)
- fd = args.output or sys.stdout
if stmts:
+ fd = args.output or sys.stdout
if args.onetrans or args.update:
print("BEGIN;", file=fd)
print(";\n".join(stmts) + ';', file=fd)
@@ -59,8 +59,9 @@ def main(host='localhost', port=5432):
else:
db.dbconn.commit()
print("Changes applied", file=sys.stderr)
- if args.output:
- args.output.close()
+ if args.output:
+ args.output.close()
+ sys.exit(2)
if __name__ == '__main__':
main()
Please sign in to comment.
Something went wrong with that request. Please try again.