schema

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EscapeIdentifier

func EscapeIdentifier(name string) string

Types

type CheckConstraint

type CheckConstraint struct {
	Name               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 //
}

func (Column) GetName

func (c Column) GetName() string

func (Column) IsCollated

func (c Column) IsCollated() bool

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 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 {
	TableName string
	Name      string
	Columns   []string
	IsInvalid bool
	IsPk      bool
	IsUnique  bool
	// ConstraintName is the name of the constraint associated with an index. Empty string if no associated constraint.
	// Once we need support for constraints not associated with indexes, we'll add a
	// Constraint schema object and starting fetching constraints directly
	ConstraintName string

	// GetIndexDefStmt is the output of pg_getindexdef
	GetIndexDefStmt GetIndexDefStatement

	// ParentIdxName is the name of the parent index if the index is a partition of an index
	ParentIdxName string
}

func (Index) GetName

func (i Index) GetName() string

func (Index) IsPartitionOfIndex

func (i Index) IsPartitionOfIndex() bool

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() string
}

Object represents a resource in a schema (table, column, index...)

type Schema

type Schema struct {
	// Name refers to the name of the schema. Ultimately, schema objects can cut across
	// schemas, e.g., a partition of a table can exist in a different table. Thus, we're probably
	// going to delete this Name attribute soon, once multi-schema is supported
	Name    string
	Tables  []Table
	Indexes []Index

	Functions []Function
	Triggers  []Trigger
}

func GetPublicSchema

func GetPublicSchema(ctx context.Context, db queries.DBTX) (Schema, error)

GetPublicSchema fetches the "public" schema. It is a non-atomic operation

func (Schema) GetName

func (s Schema) GetName() string

func (Schema) Hash

func (s Schema) Hash() (string, error)

func (Schema) Normalize

func (s Schema) Normalize() Schema

Normalize normalizes the schema (alphabetically sorts tables and columns in tables) Useful for hashing and testing

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 Table

type Table struct {
	Name             string
	Columns          []Column
	CheckConstraints []CheckConstraint

	// PartitionKeyDef is the output of Pg function pg_get_partkeydef:
	// PARTITION BY $PartitionKeyDef
	// If empty, then the table is not partitioned
	PartitionKeyDef string

	ParentTableName string
	ForValues       string
}

func (Table) GetName

func (t Table) GetName() string

func (Table) IsPartition

func (t Table) IsPartition() bool

func (Table) IsPartitioned

func (t Table) IsPartitioned() bool

type Trigger

type Trigger struct {
	EscapedName string
	OwningTable SchemaQualifiedName
	// OwningTableUnescapedName lets us be backwards compatible with the TableSQLVertexGenerator, which
	// currently uses the unescaped name as the vertex id. This will be removed once the TableSQLVertexGenerator
	// is migrated to use SchemaQualifiedName
	OwningTableUnescapedName string
	Function                 SchemaQualifiedName
	// GetTriggerDefStmt is the statement required to completely (re)create the trigger, as returned
	// by pg_get_triggerdef
	GetTriggerDefStmt GetTriggerDefStatement
}

func (Trigger) GetName

func (t Trigger) GetName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL