The dbtype module defines six classes, DbType derived from DbSchemaObject, BaseType, Composite, Enum and Domain derived from DbType, and TypeDict derived from and DbObjectDict.
Class DbType is derived from DbSchemaObject and represents a SQL type or domain as defined in the PostgreSQL pg_type catalog. Note: Only enumerated types are implemented currently.
A composite, domain or enum type
BaseType is derived from DbType and represents a PostgreSQL user-defined base type.
The map returned by to_map() and expected as argument by diff_map() has the following structure (not all fields need be present):
{'type t1':
{'alignment': 'double',
'analyze': 'analyze_func',
'input': 'input_func',
'internallength': 'variable',
'output': 'output_func',
'receive': 'receive_func',
'send': 'send_func',
'storage': 'plain'
'typmod_in': 'typmod_in_func',
'typmod_out': 'typmod_out_func'
}
}
A composite type
Convert a type to a YAML-suitable format
Parameters: | no_owner – exclude type owner information |
---|---|
Returns: | dictionary |
Return SQL statements to CREATE the base type
Returns: | SQL statements |
---|
Return SQL statement to DROP the base type
Returns: | SQL statement |
---|
We have to override the super method and add CASCADE to drop dependent functions.
Composite is derived from DbType and represents a standalone composite type.
A composite type
Convert a type to a YAML-suitable format
Parameters: | no_owner – exclude type owner information |
---|---|
Returns: | dictionary |
Return SQL statements to CREATE the composite type
Returns: | SQL statements |
---|
Generate SQL to transform an existing composite type
Parameters: | intype – the new composite type |
---|---|
Returns: | list of SQL statements |
Compares the type to an input type and generates SQL statements to transform it into the one represented by the input.
Enum is derived from DbType and represents an enumerated type.
An enumerated type definition
Return SQL statements to CREATE the enum
Returns: | SQL statements |
---|
Domain is derived from DbType and represents a domain.
A domain definition
Convert a domain to a YAML-suitable format
Parameters: | no_owner – exclude domain owner information |
---|---|
Returns: | dictionary |
Return SQL statements to CREATE the domain
Returns: | SQL statements |
---|
TypeDict is derived from DbObjectDict. It is a dictionary that represents the collection of domains and enums in a database.
The collection of domains and enums in a database
Initalize the dictionary of types by converting the input map
Parameters: |
|
---|
Connect various objects to their corresponding types or domains
Parameters: |
|
---|
Fills the check_constraints dictionaries for each domain by traversing the dbconstrs dictionary. Fills the attributes list for composite types. Fills the dependent functions dictionary for base types.
Generate SQL to transform existing domains and types
Parameters: | intypes – a YAML map defining the new domains/types |
---|---|
Returns: | list of SQL statements |
Compares the existing domain/type definitions, as fetched from the catalogs, to the input map and generates SQL statements to transform the domains/types accordingly.