Schemas

The schema module defines two classes, Schema and SchemaDict, derived from DbObject and DbObjectDict, respectively.

Schema

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.

class pyrseas.dbobject.schema.Schema(**attrs)

A database schema definition, i.e., a named collection of tables, views, triggers and other schema objects.

Schema.extern_dir(root='.')

Return the path to a directory to hold the schema objects.

Returns:directory path
Schema.to_map(dbschemas, opts)

Convert tables, etc., dictionaries to a YAML-suitable format

Parameters:
  • dbschemas – dictionary of schemas
  • opts – options to include/exclude schemas/tables, etc.
Returns:

dictionary

Schema.create(obj, *args, **kwargs)

Return SQL statements to CREATE the schema

Returns:SQL statements
Schema.data_import(opts)

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

Schema Dictionary

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.

class pyrseas.dbobject.schema.SchemaDict(dbconn=None)

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.

SchemaDict.from_map(inmap, newdb)

Initialize the dictionary of schemas by converting the input map

Parameters:
  • inmap – the input YAML map defining the schemas
  • newdb – collection of dictionaries defining the database

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:
  • db – dictionary of dictionaries of all objects
  • datacopy – dictionary of data copying info
SchemaDict.to_map(opts)

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.

SchemaDict.diff_map(inschemas)

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.

SchemaDict.data_import(opts)

Iterate over schemas with tables to be imported

Parameters:opts – options to include/exclude schemas/tables, etc.
Returns:list of SQL statements

Table Of Contents

Previous topic

Procedural Languages

Next topic

Collations

This Page