database

package
v0.0.0-...-0bdae87 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseTargetExpression

func ParseTargetExpression(targetExpression string) (string, string)

Types

type Attribute

type Attribute struct {
	Name       string `json:"attr_name"`
	Num        int    `json:"attr_num"`
	TypeName   string `json:"type_name"`
	TypeSchema string `json:"type_schema"`
	TypeOid    string `json:"type_oid"`
	NotNull    bool   `json:"not_null"`
	Default    string `json:"default"`
	Type       *Type
}

Define a class column

func (*Attribute) Children

func (a *Attribute) Children() []ddldiff.Diffable

func (*Attribute) Diff

func (post *Attribute) Diff(other ddldiff.Diffable, context ddldiff.Context) []action.Action

Implements Diffable

func (*Attribute) Drop

func (a *Attribute) Drop(context ddldiff.Context) []action.Action

func (*Attribute) IsEqual

func (a *Attribute) IsEqual(other ddldiff.Diffable) bool

func (*Attribute) IsNativeType

func (a *Attribute) IsNativeType() bool

type Batch

type Batch struct {
	Id                    string  `db:"id" json:"id"`
	Status                string  `db:"status" json:"status"`
	DataStatus            string  `db:"data_status" json:"data_status"`
	Source                string  `db:"source" json:"source"`
	Target                string  `db:"target" json:"target"`
	Data                  *string `db:"data" json:"data"`
	StorageType           string  `db:"storage_type" json:"storage_type"`
	WaitingReexecution    bool    `db:"waiting_reexecution" json:"waiting_reexecution"`
	LastExecutedStatement int     `db:"last_executed_statement" json:"last_executed_statement"`
}

func NewBatch

func NewBatch(storageType string) *Batch

func (*Batch) ActionFromData

func (b *Batch) ActionFromData(data string) (action.Action, error)

func (*Batch) AppendActions

func (b *Batch) AppendActions(actions []action.Action) error

func (*Batch) AppendData

func (b *Batch) AppendData(data *string) error

func (*Batch) CreateFile

func (b *Batch) CreateFile() (*os.File, error)

func (*Batch) GetActions

func (b *Batch) GetActions() ([]action.Action, error)

func (*Batch) GetData

func (b *Batch) GetData() (*string, error)

func (*Batch) GetFile

func (b *Batch) GetFile() (*os.File, error)

func (*Batch) GetFileReader

func (b *Batch) GetFileReader() (*bufio.Reader, *os.File, error)

func (*Batch) InsertQuery

func (b *Batch) InsertQuery(tx *sqlx.Tx) error

func (*Batch) PurgeData

func (b *Batch) PurgeData() error

func (*Batch) ReadAction

func (b *Batch) ReadAction(reader *bufio.Reader) (action.Action, error)

func (*Batch) SetActions

func (b *Batch) SetActions(actions []action.Action) error

func (*Batch) SetData

func (b *Batch) SetData(data *string) error

func (*Batch) UpdateQuery

func (b *Batch) UpdateQuery(tx *sqlx.Tx) error

type Column

type Column struct {
	Name         string `json:"attr_name"`
	Num          int    `json:"attr_num"`
	TypeName     string `json:"type_name"`
	TypeSchema   string `json:"type_schema"`
	TypeOid      string `json:"type_oid"`
	IsPrimaryKey bool   `json:"is_primary_key"`
	NotNull      bool   `json:"not_null"`
	Default      string `json:"default"`
	Table        *Table
}

Define a class column

func (*Column) Children

func (a *Column) Children() []ddldiff.Diffable

func (*Column) Diff

func (post *Column) Diff(other ddldiff.Diffable, context ddldiff.Context) []action.Action

Implements Diffable

func (*Column) Drop

func (a *Column) Drop(context ddldiff.Context) []action.Action

func (*Column) IsEqual

func (a *Column) IsEqual(other ddldiff.Diffable) bool

func (*Column) IsNativeType

func (a *Column) IsNativeType() bool

type Database

type Database struct {
	Name    string
	Config  config.Database
	Schemas map[string]*Schema
	Db      *sqlx.DB
}

Database definition

func New

func New(dbconf config.Database) *Database

func (*Database) ConnectionString

func (db *Database) ConnectionString() string

func (Database) DBVersion

func (db Database) DBVersion() (string, error)

DBVersion Returns the current Postgres version

func (*Database) GetBatch

func (db *Database) GetBatch(id string) (*Batch, error)

func (*Database) GetBatches

func (db *Database) GetBatches(status, dataStatus string) ([]*Batch, error)

func (*Database) GetEvent

func (db *Database) GetEvent(id string) (*Event, error)

func (*Database) GetEvents

func (db *Database) GetEvents(status string, limit int) ([]*Event, error)

func (Database) InstallDDLTriggers

func (db Database) InstallDDLTriggers(useEventTriggers bool)

Install DDL triggers

func (*Database) InstallTriggers

func (db *Database) InstallTriggers(targetExpression string)

Install triggers on a source table

func (*Database) NewTransaction

func (db *Database) NewTransaction() *sqlx.Tx

func (*Database) RefreshSchema

func (db *Database) RefreshSchema() error

Fetches the schema from the database and update Schema

func (*Database) Start

func (db *Database) Start() error

Open connection with database and setup internal tables

type Ddl

type Ddl struct {
	PreSchemas   []*Schema `json:"pre"`
	PostSchemas  []*Schema `json:"post"`
	Db           *Database
	SourceSchema string
	TargetSchema string
}

func NewDdl

func NewDdl(db *Database, data []byte, sourceSchema, targetSchema string) *Ddl

func (*Ddl) Diff

func (d *Ddl) Diff() []action.Action

type Dml

type Dml struct {
	Pre          *map[string]interface{} `json:"pre"`
	Post         *map[string]interface{} `json:"post"`
	Event        *Event
	Db           *Database
	TargetSchema string
}

func NewDml

func NewDml(db *Database, e *Event, data []byte, targetSchema string) *Dml

func (*Dml) Diff

func (d *Dml) Diff() []action.Action

func (*Dml) GetSchemaName

func (d *Dml) GetSchemaName() string

func (*Dml) GetTable

func (d *Dml) GetTable() *Table

func (*Dml) GetTableName

func (d *Dml) GetTableName() string

type Enum

type Enum struct {
	Oid  string `json:"oid"`
	Name string `json:"name"`
	Type *Type
}

func (*Enum) Children

func (e *Enum) Children() []ddldiff.Diffable

func (*Enum) Diff

func (post *Enum) Diff(other ddldiff.Diffable, context ddldiff.Context) []action.Action

func (*Enum) Drop

func (e *Enum) Drop(context ddldiff.Context) []action.Action

func (*Enum) IsEqual

func (e *Enum) IsEqual(other ddldiff.Diffable) bool

type Event

type Event struct {
	Id            string  `db:"id"`
	Kind          string  `db:"kind"`
	Status        string  `db:"status"`
	TriggerTag    string  `db:"trigger_tag"`
	TriggerEvent  string  `db:"trigger_event"`
	TransactionId string  `db:"transaction_id"`
	Data          *string `db:"data"`
}

func NewEvent

func NewEvent(eventData string) *Event

func (*Event) InsertQuery

func (e *Event) InsertQuery(tx *sqlx.Tx) error

func (*Event) UpdateQuery

func (e *Event) UpdateQuery(tx *sqlx.Tx) error

type Events

type Events []*Event

func (Events) Len

func (slice Events) Len() int

Implement Interface

func (Events) Less

func (slice Events) Less(i, j int) bool

func (Events) Swap

func (slice Events) Swap(i, j int)

type Extension

type Extension struct {
	Oid    string `json:"oid"`
	Name   string `json:"extension_name"`
	Schema *Schema
}

func (*Extension) Children

func (e *Extension) Children() []ddldiff.Diffable

func (*Extension) Diff

func (post *Extension) Diff(other ddldiff.Diffable, context ddldiff.Context) []action.Action

func (*Extension) Drop

func (e *Extension) Drop(context ddldiff.Context) []action.Action

func (*Extension) IsEqual

func (e *Extension) IsEqual(other ddldiff.Diffable) bool

type Function

type Function struct {
	Oid       string `json:"oid"`
	Name      string `json:"function_name"`
	Def       string `json:"function_def"`
	Arguments string `json:"function_arguments"`
	Schema    *Schema
}

func (*Function) Children

func (f *Function) Children() []ddldiff.Diffable

func (*Function) Diff

func (post *Function) Diff(other ddldiff.Diffable, context ddldiff.Context) []action.Action

func (*Function) Drop

func (f *Function) Drop(context ddldiff.Context) []action.Action

func (*Function) IsEqual

func (f *Function) IsEqual(other ddldiff.Diffable) bool

type Index

type Index struct {
	Oid   string `json:"index_oid"`
	Name  string `json:"index_name"`
	Def   string `json:"index_def"`
	Table *Table
}

Define a class column

func (*Index) Children

func (i *Index) Children() []ddldiff.Diffable

func (*Index) Diff

func (post *Index) Diff(other ddldiff.Diffable, context ddldiff.Context) []action.Action

Implements Diffable

func (*Index) Drop

func (i *Index) Drop(context ddldiff.Context) []action.Action

func (*Index) IsEqual

func (i *Index) IsEqual(other ddldiff.Diffable) bool

type Schema

type Schema struct {
	Oid        string       `json:"oid"`
	Name       string       `json:"schema_name"`
	Tables     []*Table     `json:"classes"`
	Types      []*Type      `json:"types"`
	Functions  []*Function  `json:"functions"`
	Extensions []*Extension `json:"extensions"`
	Db         *Database
}

Define a database schema

func (*Schema) Children

func (s *Schema) Children() []ddldiff.Diffable

func (*Schema) Diff

func (post *Schema) Diff(other ddldiff.Diffable, context ddldiff.Context) []action.Action

Implements Diffable

func (*Schema) Drop

func (s *Schema) Drop(context ddldiff.Context) []action.Action

func (*Schema) IsEqual

func (s *Schema) IsEqual(other ddldiff.Diffable) bool

type Schemas

type Schemas []*Schema

func ParseSchema

func ParseSchema(schemaContent string) (Schemas, error)

type Table

type Table struct {
	Oid          string    `json:"oid"`
	RelationKind string    `json:"relation_kind"`
	RelationName string    `json:"relation_name"`
	Columns      []*Column `json:"columns"`
	Indexes      []*Index  `json:"indexes"`
	Schema       *Schema
}

Define a database table

func (*Table) Children

func (c *Table) Children() []ddldiff.Diffable

func (*Table) Diff

func (post *Table) Diff(other ddldiff.Diffable, context ddldiff.Context) []action.Action

Implements Diffable

func (*Table) Drop

func (c *Table) Drop(context ddldiff.Context) []action.Action

func (*Table) GetPrimaryKey

func (c *Table) GetPrimaryKey() *Column

func (*Table) InstallTriggers

func (c *Table) InstallTriggers() error

func (*Table) IsEqual

func (c *Table) IsEqual(other ddldiff.Diffable) bool

type Type

type Type struct {
	Oid        string       `json:"oid"`
	Name       string       `json:"type_name"`
	Type       string       `json:"type_type"`
	Enums      []*Enum      `json:"enums"`
	Attributes []*Attribute `json:"attributes"`
	Schema     *Schema
}

func (*Type) Children

func (t *Type) Children() []ddldiff.Diffable

func (*Type) Diff

func (post *Type) Diff(other ddldiff.Diffable, context ddldiff.Context) []action.Action

func (*Type) Drop

func (t *Type) Drop(context ddldiff.Context) []action.Action

func (*Type) IsEqual

func (t *Type) IsEqual(other ddldiff.Diffable) bool

Jump to

Keyboard shortcuts

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