migrations

package
v0.396.8-next.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChangeTypeAdded    = "ADDED"
	ChangeTypeRemoved  = "REMOVED"
	ChangeTypeModified = "MODIFIED"
)

Variables

View Source
var ErrMultipleStoredSchemas = errors.New("more than one schema found in keel_schema table")
View Source
var ErrNoStoredSchema = errors.New("no schema stored in keel_schema table")
View Source
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",
}

Functions

func GetCurrentSchema

func GetCurrentSchema(ctx context.Context, database db.Database) (*proto.Schema, error)

func Identifier

func Identifier(v string) string

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 PrimaryKeyConstraintName

func PrimaryKeyConstraintName(modelName string, fieldName string) string

func UniqueConstraintName

func UniqueConstraintName(modelName string, fieldNames []string) string

Types

type ColumnRow

type ColumnRow struct {
	TableName    string `json:"table_name"`
	ColumnName   string `json:"column_name"`
	ColumnNum    int    `json:"column_num"`
	NotNull      bool   `json:"not_null"`
	HasDefault   bool   `json:"has_default"`
	DefaultValue string `json:"default_value"`
	DataType     string `json:"data_type"`
}

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 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

func New(ctx context.Context, schema *proto.Schema, database db.Database) (*Migrations, error)

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"`
}

Jump to

Keyboard shortcuts

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