The schema module defines two classes, Schema and SchemaDict, derived from DbObject and DbObjectDict, respectively.
Schema is derived from DbObject and represents a database schema, i.e., a collection of tables and other objects. The ‘public’ schema is special as in most contexts an unqualified object is assumed to be part of it, e.g., table “t” is usually shorthand for table “public.t.”
For now, the schema name is the only attribute and is of course the identifying attribute in the Schema keylist.
A database schema definition, i.e., a named collection of tables, views, triggers and other schema objects.
Return the path to a directory to hold the schema objects.
Returns: | directory path |
---|
Convert tables, etc., dictionaries to a YAML-suitable format
Parameters: |
|
---|---|
Returns: | dictionary |
Return SQL statements to CREATE the schema
Returns: | SQL statements |
---|
Generate SQL to import data from the tables in this schema
Parameters: | opts – options to include/exclude schemas/tables, etc. |
---|---|
Returns: | list of SQL statements |
SchemaDict is derived from DbObjectDict. It is a dictionary that represents the collection of schemas in a database. Certain internal schemas (information_schema, pg_catalog, etc.) owned by the ‘postgres’ user are excluded.
The collection of schemas in a database. Minimally, the ‘public’ schema.
Method from_map() is called from Database from_map() to start a recursive interpretation of the input map. The inmap argument is the same as input to the diff_map() method of Database. The newdb argument is the holder of DbObjectDict-derived dictionaries which is filled in as the recursive interpretation proceeds.
Initialize the dictionary of schemas by converting the input map
Parameters: |
|
---|
Starts the recursive analysis of the input map and construction of the internal collection of dictionaries describing the database objects.
Connect various schema objects to their respective schemas
Parameters: |
|
---|
Convert the schema dictionary to a regular dictionary
Parameters: | opts – options to include/exclude schemas/tables, etc. |
---|---|
Returns: | dictionary |
Invokes the to_map method of each schema to construct a dictionary of schemas.
Generate SQL to transform existing schemas
Parameters: | input_map – a YAML map defining the new schemas |
---|---|
Returns: | list of SQL statements |
Compares the existing schema definitions, as fetched from the catalogs, to the input map and generates SQL statements to transform the schemas accordingly.
Iterate over schemas with tables to be imported
Parameters: | opts – options to include/exclude schemas/tables, etc. |
---|---|
Returns: | list of SQL statements |