Documentation
¶
Index ¶
- Constants
- func EscapeIdentifier(name string) string
- func FQEscapedColumnName(table SchemaQualifiedName, columnName string) string
- type CheckConstraint
- type Column
- type ColumnIdentity
- type ColumnIdentityType
- type Enum
- type Extension
- type ForeignKeyConstraint
- type Function
- type GetIndexDefStatement
- type GetSchemaOpt
- type GetTriggerDefStatement
- type Index
- type IndexConstraint
- type IndexConstraintType
- type NamedSchema
- type Object
- type Policy
- type PolicyCmd
- type ReplicaIdentity
- type Schema
- type SchemaQualifiedName
- type Sequence
- type SequenceOwner
- type Table
- type Trigger
Constants ¶
const ( ColumnIdentityTypeAlways = "a" ColumnIdentityTypeByDefault = "d" )
Variables ¶
This section is empty.
Functions ¶
func EscapeIdentifier ¶
func FQEscapedColumnName ¶ added in v0.2.0
func FQEscapedColumnName(table SchemaQualifiedName, columnName string) string
FQEscapedColumnName builds a fully-qualified escape column name
Types ¶
type CheckConstraint ¶
type CheckConstraint struct { Name string // KeyColumns are the columns that the constraint applies to KeyColumns []string Expression string IsValid bool IsInheritable bool DependsOnFunctions []SchemaQualifiedName }
func (CheckConstraint) GetName ¶
func (c CheckConstraint) GetName() string
type Column ¶
type Column struct { Name string Type string Collation SchemaQualifiedName // If the column has a default value, this will be a SQL string representing that value. // Examples: // ”::text // CURRENT_TIMESTAMP // If empty, indicates that there is no default value. Default string IsNullable bool // Size is the number of bytes required to store the value. // It is used for data-packing purposes Size int Identity *ColumnIdentity }
func (Column) IsCollated ¶
type ColumnIdentity ¶ added in v0.8.0
type ColumnIdentityType ¶ added in v0.8.0
type ColumnIdentityType string
type Enum ¶ added in v0.7.0
type Enum struct { SchemaQualifiedName Labels []string }
type Extension ¶ added in v0.3.0
type Extension struct { SchemaQualifiedName Version string }
type ForeignKeyConstraint ¶ added in v0.3.0
type ForeignKeyConstraint struct { EscapedName string OwningTable SchemaQualifiedName ForeignTable SchemaQualifiedName ConstraintDef string IsValid bool }
func (ForeignKeyConstraint) GetName ¶ added in v0.3.0
func (f ForeignKeyConstraint) GetName() string
type Function ¶
type Function struct { SchemaQualifiedName // FunctionDef is the statement required to completely (re)create // the function, as returned by `pg_get_functiondef`. It is a CREATE OR REPLACE // statement FunctionDef string // Language is the language of the function. This is relevant in determining if we // can track the dependencies of the function (or not) Language string DependsOnFunctions []SchemaQualifiedName }
type GetIndexDefStatement ¶
type GetIndexDefStatement string
GetIndexDefStatement is the output of pg_getindexdef. It is a `CREATE INDEX` statement that will re-create the index. This statement does not contain `CONCURRENTLY`. For unique indexes, it does contain `UNIQUE` For partitioned tables, it does contain `ONLY`
func (GetIndexDefStatement) ToCreateIndexConcurrently ¶
func (i GetIndexDefStatement) ToCreateIndexConcurrently() (string, error)
type GetSchemaOpt ¶ added in v0.6.0
type GetSchemaOpt func(*getSchemaOptions)
func WithExcludeSchemas ¶ added in v0.6.0
func WithExcludeSchemas(schemas ...string) GetSchemaOpt
WithExcludeSchemas filters the schema to exclude the given schemas. This unions with any schemas that are already excluded via WithExcludeSchemas. If empty, then no schemas are excluded.
func WithIncludeSchemas ¶ added in v0.6.0
func WithIncludeSchemas(schemas ...string) GetSchemaOpt
WithIncludeSchemas filters the schema to only include the given schemas. This unions with any schemas that are already included via WithIncludeSchemas. If empty, then all schemas are included.
type GetTriggerDefStatement ¶
type GetTriggerDefStatement string
GetTriggerDefStatement is the output of pg_get_triggerdef. It is a `CREATE TRIGGER` statement that will create the trigger. This statement does not contain `OR REPLACE`
func (GetTriggerDefStatement) ToCreateOrReplace ¶
func (g GetTriggerDefStatement) ToCreateOrReplace() (string, error)
type Index ¶
type Index struct { // Name is the name of the index. We don't store the schema because the schema is just the schema of the table. // Referencing the name is an anti-pattern because it is not qualified. Use should use GetSchemaQualifiedName instead. Name string OwningTable SchemaQualifiedName Columns []string IsInvalid bool IsUnique bool Constraint *IndexConstraint // GetIndexDefStmt is the output of pg_getindexdef GetIndexDefStmt GetIndexDefStatement ParentIdx *SchemaQualifiedName }
func (Index) GetSchemaQualifiedName ¶ added in v0.6.0
func (i Index) GetSchemaQualifiedName() SchemaQualifiedName
type IndexConstraint ¶ added in v0.4.0
type IndexConstraint struct { Type IndexConstraintType EscapedConstraintName string ConstraintDef string IsLocal bool }
IndexConstraint informally represents a constraint that is always 1:1 with an index, i.e., primary and unique constraints. It's easiest to just treat these like a property of the index rather than a separate entity
type IndexConstraintType ¶ added in v0.4.0
type IndexConstraintType string
const (
PkIndexConstraintType IndexConstraintType = "p"
)
type NamedSchema ¶ added in v0.6.0
type NamedSchema struct {
Name string
}
NamedSchema represents a schema in the database. We call it NamedSchema to distinguish it from the Postgres Database schema
func (NamedSchema) GetName ¶ added in v0.6.0
func (n NamedSchema) GetName() string
type Object ¶
type Object interface { // GetName is used to identify the old and new versions of a schema object between the old and new schemas // If the name is not present in the old schema objects list, then it is added // If the name is not present in the new schemas objects list, then it is removed // Otherwise, it has persisted across two schemas and is possibly altered // // GetName should be qualified with the schema name. GetName() string }
Object represents a resource in a schema (table, column, index...)
type Policy ¶ added in v0.7.0
type PolicyCmd ¶ added in v0.7.0
type PolicyCmd string
PolicyCmd represents the polcmd value in the pg_policy system catalog. See docs for possible values: https://www.postgresql.org/docs/current/catalog-pg-policy.html#CATALOG-PG-POLICY
type ReplicaIdentity ¶ added in v0.4.0
type ReplicaIdentity string
const ( ReplicaIdentityDefault ReplicaIdentity = "d" ReplicaIdentityNothing ReplicaIdentity = "n" ReplicaIdentityFull ReplicaIdentity = "f" ReplicaIdentityIndex ReplicaIdentity = "i" )
type Schema ¶
type Schema struct { NamedSchemas []NamedSchema Extensions []Extension Enums []Enum Tables []Table Indexes []Index ForeignKeyConstraints []ForeignKeyConstraint Sequences []Sequence Functions []Function Triggers []Trigger }
Schema is the schema of the database, not just a single Postgres schema.
type SchemaQualifiedName ¶
type SchemaQualifiedName struct { SchemaName string // EscapedName is the name of the object. It should already be escaped // We take an escaped name because there are weird exceptions, like functions, where we can't just // surround the name in quotes EscapedName string }
SchemaQualifiedName represents a schema object name scoped within a schema
func (SchemaQualifiedName) GetFQEscapedName ¶
func (o SchemaQualifiedName) GetFQEscapedName() string
GetFQEscapedName gets the fully-qualified, escaped name of the schema object, including the schema name
func (SchemaQualifiedName) GetName ¶
func (o SchemaQualifiedName) GetName() string
func (SchemaQualifiedName) IsEmpty ¶
func (o SchemaQualifiedName) IsEmpty() bool
type Sequence ¶ added in v0.2.0
type Sequence struct { SchemaQualifiedName Owner *SequenceOwner Type string StartValue int64 Increment int64 MaxValue int64 MinValue int64 CacheSize int64 Cycle bool }
type SequenceOwner ¶ added in v0.2.0
type SequenceOwner struct { TableName SchemaQualifiedName ColumnName string }
SequenceOwner represents the owner of a sequence.
type Table ¶
type Table struct { SchemaQualifiedName Columns []Column CheckConstraints []CheckConstraint Policies []Policy ReplicaIdentity ReplicaIdentity RLSEnabled bool RLSForced bool // PartitionKeyDef is the output of Pg function pg_get_partkeydef: // PARTITION BY $PartitionKeyDef // If empty, then the table is not partitioned PartitionKeyDef string ParentTable *SchemaQualifiedName ForValues string }
func (Table) IsPartition ¶
IsPartition returns whether the table is a partition. It represents a mismatch in modeling because the ForValues and ParentTable are stored separately. Instead, the fields should be stored under the same struct as a nilable pointer, and this function should be deleted.
func (Table) IsPartitioned ¶
type Trigger ¶
type Trigger struct { EscapedName string OwningTable SchemaQualifiedName Function SchemaQualifiedName // GetTriggerDefStmt is the statement required to completely (re)create the trigger, as returned // by pg_get_triggerdef GetTriggerDefStmt GetTriggerDefStatement }