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 or Postgres namespace, i.e., a
collection of tables and other objects. The ‘public’ schema is
currently treated specially 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.” The ‘pyrseas’ schema, if present, is excluded as it
is only intended for use by dbaugment or other Pyrseas
internal purposes.
-
class
pyrseas.dbobject.schema.
Schema
(name, description=None, owner=None, privileges=[], oldname=None, oid=None)¶ 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
(db, 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
(dbversion=None)¶ Return SQL statements to CREATE the schema
Returns: SQL statements
-
Schema.
drop
()¶ Generate SQL to drop the current object
Returns: list of 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.
-
SchemaDict.
to_map
(db, 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.
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