types

package
v0.4.10 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionTypeCreate ActionType = "CREATE"
	ActionTypeDrop   ActionType = "DROP"

	EntityTypeSchema     EntityType = "SCHEMA"
	EntityTypeTable      EntityType = "TABLE"
	EntityTypeColumn     EntityType = "COLUMN"
	EntityTypeConstraint EntityType = "CONST"
	EntityTypeView       EntityType = "VIEW"
	EntityTypeSequence   EntityType = "SEQ"

	StateTagCS StateTag = "CS"
	StateTagPS StateTag = "PS"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionType

type ActionType string

type CobraCmdFn

type CobraCmdFn = func(cmd *cobra.Command, args []string)

type Column

type Column struct {
	TableSchema      string
	TableName        string
	Name             string
	Default          string
	Nullable         bool
	DataType         string
	CharMaxLen       int
	NumericPrecision int
	NumericScale     int
}

type DbConstraint

type DbConstraint struct {
	// on table
	TableSchema string
	TableName   string
	ColName     string

	ConName          string
	ConSchema        string
	Type             string // can be 'p', 'f', 'c' or 'u'
	UpdateActionType string
	DeleteActionType string

	// foreign table
	FTableSchema string
	FTableName   string
	FColName     string

	Syntax string
}

type DbDumpFilesMap

type DbDumpFilesMap = map[string][]string

type DbMigration

type DbMigration struct {
	// dir path will also contain the id (.../migrations/dbname/<timestamp>)
	DirPath  string
	IsActive bool
	Up       *DbMigration
	Down     *DbMigration
}

primitive DbMigration type, only containing helper function, use migrationsLib for complete use

a db migration directory will look like: /migrations/dbname/2024_01_01T00_00_00

this directory will contain files: "active" (present ONLY IF migration is currently active), "state.json" (a state snapshot of the CURRENT state) "up.sql" (sql file to go up to the next state) [COULD BE ABSENT IF LATEST STATE] "down.sql" (sql file to go down to the previous state) [ABSENT ON INIT MIGRATION] "info.md" (user maintained description of the current state changes relative to previous state)

func NewDbMigration

func NewDbMigration(migDirPath string, state *DbSchema, upSqlStr string, downSqlStr string, infoStr string) (*DbMigration, error)

ensures migration dir exists and writes state, up/down sql queries & info file to disk path string should look like this ".../migrations/dbname/2024-01-01T00_00_00"

func (*DbMigration) GetDownQuery

func (mig *DbMigration) GetDownQuery() (string, error)

func (*DbMigration) GetInfoFile

func (mig *DbMigration) GetInfoFile() (string, error)

func (*DbMigration) GetUpQuery

func (mig *DbMigration) GetUpQuery() (string, error)

func (*DbMigration) ReadState

func (mig *DbMigration) ReadState() (*DbSchema, error)

func (*DbMigration) SetActive

func (mig *DbMigration) SetActive() error

set "this" migration as active. removes the active signal file from all other migrations in the parent directory then creates the active signal file in the current migration

func (*DbMigration) WriteDownQuery

func (mig *DbMigration) WriteDownQuery(sql string) error

func (*DbMigration) WriteInfoFile

func (mig *DbMigration) WriteInfoFile(infoStr string) error

func (*DbMigration) WriteUpQuery

func (mig *DbMigration) WriteUpQuery(sql string) error

type DbRow

type DbRow struct {
	DataType string
	Value    interface{}
}

type DbRows

type DbRows = map[string][]DbRow

type DbSchema

type DbSchema struct {
	DbName    string
	Tables    map[string]*TableSchema
	Views     map[string]*TableSchema
	Types     []DbType
	Schemas   []Schema
	Sequences []DbSequence
}

the string key is of format "schema.table"

type DbSequence

type DbSequence struct {
	Schema      string
	Name        string
	DataType    string
	IncrementBy int
	MinValue    int
	MaxValue    int
	StartValue  int
	CacheSize   int
	Cycle       bool
}

type DbType

type DbType struct {
	Schema string
	Name   string
}

type DiffKey

type DiffKey struct {
	Entity   Entity
	StateTag StateTag
}

type Entity

type Entity struct {
	Type EntityType
	Id   []string

	// pointer to the real entity
	Ptr interface{}
}

func NewEntity

func NewEntity(entityType EntityType, entityPtr interface{}) Entity

func (*Entity) GetEntityId

func (e *Entity) GetEntityId() []string

type EntityType

type EntityType string

type MiddlewareFunc

type MiddlewareFunc = func(fn CobraCmdFn) CobraCmdFn

type MigAction

type MigAction struct {
	ActionType ActionType
	StateTag   StateTag
	Entity     Entity

	/*
		For table, dep id is "schema.table", for col it's "schema.table.colname", for constraint/type it's "schema.name"
	*/
	DepArr []string
}

type MigrationStatus

type MigrationStatus struct {
	Migrations      []DbMigration
	ActiveMigration *DbMigration
	IsInit          bool
}

type QueryResult

type QueryResult struct {
	RowCount uint
	Data     DbRows
	Columns  []string
}

type Response

type Response struct {
	Message string
	Data    any
}

type SafeVar

type SafeVar[T any] struct {
	// contains filtered or unexported fields
}

func NewSafeVar

func NewSafeVar[T any](val T) SafeVar[T]

func (*SafeVar[T]) Get

func (s *SafeVar[T]) Get() T

func (*SafeVar[T]) Set

func (s *SafeVar[T]) Set(newVal T)

type Schema

type Schema struct {
	Name string
}

type StateTag

type StateTag string

type Table

type Table struct {
	Schema string
	Name   string

	// IMP: possible values to be put in from constants 'TableType*'
	Type string
}

type TableSchema

type TableSchema struct {
	Schema      string
	Name        string
	DefSyntax   string // populated for only views
	Columns     []Column
	Constraints []*DbConstraint
}

Jump to

Keyboard shortcuts

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