dbxml.py¶
dbxml.py – Maintain database tables and documentation using XML files
This script is used to synchronize the structure of database tables with XML files. The XML files contain additional information, including documentation.
The script is invoked with the following general syntax:
dbxml.py [math-options] command [command-arguments]
Here command
specifies the main task that dbxml.py
should
carry out. These commands are described below. The options before
command
are used to provide database parameters and are common for
all commands. The options and arguments following command
are
specific to the particular task.
To see the list of all commands and general options, type:
dbxml.py --help
To obtain information about the arguments required by a specific command, type:
dbxml.py command --help
Commands¶
The following commands are recognized by dbxml.py
.
list-tables
Print the list tables present in the database.
Example:
dbxml.py --dbconf live list-tables
create-xml
Generate an XML file representing a table in the database. The XML file will include empty tags where documentation can be added. The generated XML code is printed to standard output, so pipe it into a file if desired.
Example:
dbxml.py --dbconf live create-xml tbl1_Buildings > buildings.xml
create-table
Create a database table based on the SQL code embedded in an XML file. The name of the table is taken from the
name
attribute to the<table>
tag. More than one table can be created by specifying several XML files. If the--drop
option is used, then any existing tables with the same names will be deleted before new tables are created.Example:
dbxml.py --dbconf math2 --database math_test2 create-table Tables/*.xml
compare
Compare an XML file to the structure of a table in the database. If they agree then nothing is printed. Otherwise a brief summary of the main types of differences is printed. Use the
--verbose
option to get a full report of the differences.Example:
dbxml.py --dbconf live compare Tables/*.xml
update-xml
Update one or more XML files to match the structure of the database tables they represent. Columns that are not present in the tables are dropped in the XML files, and any new columns in the tables are added to the XML files with empty comment tags. This command can be used to update the XML files after columns have been added, deleted, reordered, or redefined in database tables, and when the table indexes have changed. Do not use
update-xml
if columns have been renamed since this will causedbxml.py
to delete the documentation for such columns. In stead, use therename-column
command to change column names.Example:
dbxml.py --dbconf live update-xml Tables/*.xml
update-table
This command is intended to update the structure of database tables to match the corresponding XML files. This command has not been implemented.
rename-table
Rename a table in both an XML file and the database. The XML file itself will not be renamed, but it may be beneficial to use GIT to do so afterwards.
Example:
dbxml.py --dbconf live rename-table Tables/tbl1_Buildings.xml buildings git mv Tables/tbl1_Buildings.xml Tables/buildings.xml
rename-column
Rename a column in both an XML file and in the corresponding database table. If the XML file is under GIT control, then the updated file should be committed afterwards.
Example:
dbxml.py --dbconf live rename-column Tables/tbl1_Buildings.xml Bldg_Name new_name