Add support for PostgreSQL ENUM
s (and portable named types)
#171
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a fairly major change, and it breaks the output format for
dbcrossbar-schema
(so this is a semver bump). Highlists of thischange include:
CREATE TYPE name AS ENUM(...)
statements.ENUM
s in the database if they don't exist. Wrapping the existingdbcrossbar-schema
output format in{ "named_types": [], "tables": [old_table_format] }
.Internally, this requires:
Schema
around instead ofTable
in most places,so that we have access to
named_types
. - AddingDataType::Named
to refer to a named type. - Adding
DataType::OneOf
to refer to astring enumeration. - Lots of changes to the
postgres-sql
andpostgres
drivers.We designed
DataType::Named
andDataType::OneOf
the way we did inorder to later support the following planned features:
dbcrossbar-ts
should be able to converttype
andinterface
declarations into named types. - We want to support PostgreSQL
native structure types, as an alternative to encoding structures as
jsonb
options.Note that
one_of
andnamed
support is fairly limited. Some driverswill always recursively resolve all named types (like BigQuery), but
PostgreSQL only accepts
one_of
andnamed
if they correspond to aCREATE TYPE name AS ENUM(...)
statement. These restrictions will berelaxed over time as we figure out how to handle these cases
correctly, but we want to start by allowing only those cases we know
how to handle cleanly.
Other interesting PostgreSQL changes include:
TableName
is nowPgName
, because it's used by types and tables.Many thanks to Tom Caruso for pairing on a tricky set of tests and
test fixes, and to Forrest Wallace and Seamus Abshere for providing
feedback on the design.