Documentation
¶
Index ¶
- Constants
- Variables
- func GetCurrentSchema(ctx context.Context, database db.Database) (*proto.Schema, error)
- func Identifier(v string) string
- func PrimaryKeyConstraintName(modelName string, fieldName string) string
- func UniqueConstraintName(modelName string, fieldNames []string) string
- type ColumnRow
- type ConstraintRow
- type DatabaseChange
- type FunctionRow
- type Migrations
- type TriggerRow
Constants ¶
const ( ChangeTypeAdded = "ADDED" ChangeTypeRemoved = "REMOVED" ChangeTypeModified = "MODIFIED" )
Variables ¶
var ErrMultipleStoredSchemas = errors.New("more than one schema found in keel_schema table")
var ErrNoStoredSchema = errors.New("no schema stored in keel_schema table")
var PostgresFieldTypes map[proto.Type]string = map[proto.Type]string{ proto.Type_TYPE_ID: "TEXT", proto.Type_TYPE_STRING: "TEXT", proto.Type_TYPE_INT: "INTEGER", proto.Type_TYPE_DECIMAL: "NUMERIC", proto.Type_TYPE_BOOL: "BOOL", proto.Type_TYPE_TIMESTAMP: "TIMESTAMPTZ", proto.Type_TYPE_DATETIME: "TIMESTAMPTZ", proto.Type_TYPE_DATE: "DATE", proto.Type_TYPE_ENUM: "TEXT", proto.Type_TYPE_SECRET: "TEXT", proto.Type_TYPE_PASSWORD: "TEXT", proto.Type_TYPE_MARKDOWN: "TEXT", proto.Type_TYPE_VECTOR: "VECTOR", proto.Type_TYPE_FILE: "JSONB", proto.Type_TYPE_DURATION: "INTERVAL", }
Functions ¶
func GetCurrentSchema ¶
func Identifier ¶
Identifier converts v into an identifier that can be used for table or column names in Postgres. The value is converted to snake case and then quoted. The former is done to create a more idiomatic postgres schema and the latter is so you can have a table name called "select" that would otherwise not be allowed as it clashes with the keyword.
func UniqueConstraintName ¶
Types ¶
type ConstraintRow ¶
type ConstraintRow struct {
TableName string
ConstraintName string
ConstrainedColumns pq.Int64Array `gorm:"type:smallint[]"`
// If a foreign key constraint the referenced table and columns
OnTable *string
ReferencesColumns pq.Int64Array `gorm:"type:smallint[]"`
// c = check constraint,
// f = foreign key constraint,
// p = primary key constraint,
// u = unique constraint,
// t = constraint trigger,
// x = exclusion constraint
ConstraintType string
// a = no action
// r = restrict
// c = cascade
// n = set null
// d = set default
OnDelete string
}
type DatabaseChange ¶
type DatabaseChange struct {
// The model this change applies to
Model string
// The field this change applies to (might be empty)
Field string
// The type of change
Type string
}
func (DatabaseChange) String ¶ added in v0.369.1
func (c DatabaseChange) String() string
type FunctionRow ¶ added in v0.400.0
type FunctionRow struct {
RoutineName string `json:"routine_name"`
}
type Migrations ¶
type Migrations struct {
Schema *proto.Schema
// Describes the changes that will be applied to the database
// if SQL is run
Changes []*DatabaseChange
// The SQL to run to execute the database schema changes
SQL string
// contains filtered or unexported fields
}
func New ¶
New creates a new Migrations instance for the given schema and database. Introspection is performed on the database to work out what schema changes need to be applied to result in the database schema matching the Keel schema
func (*Migrations) Apply ¶
func (m *Migrations) Apply(ctx context.Context, dryRun bool) error
Apply executes the migrations against the database If dryRun is true, then the changes are rolled back
func (*Migrations) HasModelFieldChanges ¶
func (m *Migrations) HasModelFieldChanges() bool
HasModelFieldChanges returns true if the migrations contain model field changes to be applied
type TriggerRow ¶ added in v0.369.1
type TriggerRow struct {
// company_employee_delete
TriggerName string `json:"trigger_name"`
// e.g. company_employee
TableName string `json:"table_name"`
// e.g. DELETE
StatementType string `json:"statement_type"`
// e.g. EXECUTE PROCEDURE process_audit()
ActionStatement string `json:"action_statement"`
// e.g. AFTER
ActionTiming string `json:"action_timing"`
}