Documentation ¶
Overview ¶
Package schema provides a generic representation of database schemas. Note that our goal is not to faithfully represent all aspects of the schema, but just the relevant components for conversion to Spanner and reporting on the quality of the conversion (this motivates us to keep partial information about some features we will report on but not use in the conversion e.g. default values, check constraints).
The current version supports PostgreSQL. Expect it to grow as we support other databases. We might eventually support the Spanner schema, and potentially get rid of the ddl package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ForeignKey ¶
type ForeignKey struct { Name string ColIds []string ColumnNames []string `json:"-"` ReferTableId string ReferTableName string `json:"-"` ReferColumnIds []string // len(ReferColumnIds) must be same as len(ColIds) ReferColumnNames []string `json:"-"` OnDelete string OnUpdate string Id string }
ForeignKey represents a foreign key. Note that the fields onDelete and onUpdate describe actions for when keys are deleted or updated. Different source databases support different actions. For example, mysql supports RESTRICT, CASCADE, SET NULL, NO ACTION, and SET DEFAULT (see https://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html).
type Ignored ¶
type Ignored struct { Check bool Identity bool Default bool Exclusion bool ForeignKey bool AutoIncrement bool }
Ignored represents column properties/constraints that are not represented. We drop the details, but retain presence/absence for reporting purposes.
type Index ¶
Index represents a database index. Index represents a database index. The only way we represent unique constraints is via indexes. All source database unique constraints will be transformed into this representation, including: i) A column level constraint (as part of a CREATE TABLE statement) ii) A table level constraint (as part of a CREATE TABLE statement) iii) An index (as part of a CREATE TABLE statement) iv) Added via an ALTER TABLE constraint (changing column constraints, table constraints or index definitions) v) Added via a CREATE UNIQUE INDEX statement (which internally maps to an alter table statement). We use this single representation of unique constraints to simplify their processing and avoid having to handle lots of cases for the same concept. Our choice of an index representation for unique is largely motivated by the fact that databases typically implement UNIQUE via an index.
type Key ¶
type Key struct { ColId string Desc bool // By default, order is ASC. Set to true to specifiy DESC. Order int }
Key respresents a primary key or index key.
type Table ¶
type Table struct { Name string Schema string ColIds []string // List of column Ids (for predictable iteration order e.g. printing). ColDefs map[string]Column // Details of columns. ColNameIdMap map[string]string `json:"-"` // Computed every time just after conv is generated or after any column renaming PrimaryKeys []Key ForeignKeys []ForeignKey Indexes []Index Id string }
Table represents a database table.