Documentation
¶
Index ¶
- Constants
- type ActionType
- type CobraCmdFn
- type Column
- type DbConstraint
- type DbDumpFilesMap
- type DbMigration
- func (mig *DbMigration) GetDownQuery() (string, error)
- func (mig *DbMigration) GetInfoFile() (string, error)
- func (mig *DbMigration) GetUpQuery() (string, error)
- func (mig *DbMigration) ReadState() (*DbSchema, error)
- func (mig *DbMigration) SetActive() error
- func (mig *DbMigration) WriteDownQuery(sql string) error
- func (mig *DbMigration) WriteInfoFile(infoStr string) error
- func (mig *DbMigration) WriteUpQuery(sql string) error
- type DbRow
- type DbRows
- type DbSchema
- type DbSequence
- type DbType
- type DiffKey
- type Entity
- type EntityType
- type MiddlewareFunc
- type MigAction
- type MigrationStatus
- type QueryResult
- type Response
- type SafeVar
- type Schema
- type StateTag
- type Table
- type TableSchema
Constants ¶
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 DbConstraint ¶
type DbDumpFilesMap ¶
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 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 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 ¶
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 SafeVar ¶
type SafeVar[T any] struct { // contains filtered or unexported fields }
func NewSafeVar ¶
type TableSchema ¶
type TableSchema struct {
Schema string
Name string
DefSyntax string // populated for only views
Columns []Column
Constraints []*DbConstraint
}