dbdiff

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2018 License: MIT Imports: 14 Imported by: 0

README

[dbdiff] Tool to detect data difference in the database

How to setup

Install
go get github.com/jparound30/dbdiff/cmd/dbdiff
or Update
go get -u github.com/jparound30/dbdiff/cmd/dbdiff
Configuration

Put configuration.yaml file in the current directory.
Or specify a configuration file path by -conf option.

A sample of configuration.yamlis as follows.

db:
  type: postgresql (or mysql)
  host: localhost
  port: 5432
  user: username
  password: password
  name: sampledatabase
  schema: hoge.
Run
  1. Execute dbdiff on the command line.
dbdiff

Usage:

  -conf string
        Specify path of configuration file. (default "configuration.yaml")
  -o string
        Filename of result file(.xlsx). (default "dbdiff_yyyymmdd_hhmmss.xlsx")
  1. Please operate accoding to the messages.

  2. Output result to console, and generate Excel file(.xlsx) in the current directory.

LIMITATIONS

  • Tested only on macOS High Sierra / Go 1.11

Documentation

Index

Constants

View Source
const (
	DiffStatusInit        int8 = 0 //: 比較前,
	DiffStatusAdd         int8 = 1 //: Add,
	DiffStatusDel         int8 = 2 //: Delete,
	DiffStatusMod         int8 = 3 //: Mod,
	DiffStatusNotModified int8 = 4 //: NotModified
)
View Source
const DefaultConfigFilePath = "configuration.yaml"

Variables

This section is empty.

Functions

func GetAllColumnsOnTable

func GetAllColumnsOnTable(db DbHolder, tableName string, schema string) ([]string, error)

func GetAllTables

func GetAllTables(db DbHolder, config *Configuration) ([]string, error)

Get all table name from db

func GetPksOfTables

func GetPksOfTables(db DbHolder, config *Configuration, tableNames []string) (map[string][]string, error)

Get Primary key information

Types

type AllTableStore

type AllTableStore struct {
	AllData        map[string]map[string]*RowObject
	AllColumn      map[string][]string
	TotalDataCount uint64
	// contains filtered or unexported fields
}

func (*AllTableStore) CollectAllTableData

func (ats *AllTableStore) CollectAllTableData(db DbHolder, config *Configuration, tablePks map[string][]string) error

func (*AllTableStore) ExtractChangedData

func (ats *AllTableStore) ExtractChangedData(beforeData *AllTableStore) map[string][]*RowObject

テーブルごとに、追加、変更(変更前後)、削除のデータだけをまとめたものを戻り値で返す 呼ぶときは必ず変更前データを引数にし、メッソドレシーバは変更後データとすること

type ColumnScan

type ColumnScan struct {
	Value sql.Scanner
}

func (*ColumnScan) GetValueString

func (rs *ColumnScan) GetValueString() string

func (*ColumnScan) Scan

func (rs *ColumnScan) Scan(value interface{}) error

func (*ColumnScan) String

func (rs *ColumnScan) String() string

type Configuration

type Configuration struct {
	Db Db `yaml:"db"`
}

func GetConfiguration

func GetConfiguration() (*Configuration, error)

func LoadConfiguration

func LoadConfiguration(configFilePath string) (*Configuration, error)

type DBManager

type DBManager struct {
	// contains filtered or unexported fields
}

func GetDBInstance

func GetDBInstance(dbConfig *Db) (*DBManager, error)

func (*DBManager) Begin

func (holder *DBManager) Begin() (*sql.Tx, error)

Wrapper for sql.DB#Begin()

func (*DBManager) BeginTx

func (holder *DBManager) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)

Wrapper for sql.DB#BeginTx()

func (*DBManager) Close

func (holder *DBManager) Close() error

func (*DBManager) Conn

func (holder *DBManager) Conn(ctx context.Context) (*sql.Conn, error)

Wrapper for sql.DB#Conn()

func (*DBManager) Driver

func (holder *DBManager) Driver() driver.Driver

Wrapper for sql.DB#Driver()

func (*DBManager) Exec

func (holder *DBManager) Exec(query string, args ...interface{}) (sql.Result, error)

Wrapper for sql.DB#Exec()

func (*DBManager) ExecContext

func (holder *DBManager) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

Wrapper for sql.DB#ExecContext()

func (*DBManager) Finalize

func (holder *DBManager) Finalize() error

func (*DBManager) Ping

func (holder *DBManager) Ping() error

Wrapper for sql.DB#Ping()

func (*DBManager) PingContext

func (holder *DBManager) PingContext(ctx context.Context) error

Wrapper for sql.DB#PingContext()

func (*DBManager) Prepare

func (holder *DBManager) Prepare(query string) (*sql.Stmt, error)

Wrapper for sql.DB#Prepare()

func (*DBManager) PrepareContext

func (holder *DBManager) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)

Wrapper for sql.DB#PrepareContext()

func (*DBManager) Query

func (holder *DBManager) Query(query string, args ...interface{}) (*sql.Rows, error)

Wrapper for sql.DB#Query()

func (*DBManager) QueryContext

func (holder *DBManager) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

Wrapper for sql.DB#QueryContext()

func (*DBManager) QueryRow

func (holder *DBManager) QueryRow(query string, args ...interface{}) *sql.Row

Wrapper for sql.DB#QueryRow()

func (*DBManager) QueryRowContext

func (holder *DBManager) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

Wrapper for sql.DB#QueryRowContext()

func (*DBManager) SetConnMaxLifetime

func (holder *DBManager) SetConnMaxLifetime(d time.Duration)

Wrapper for sql.DB#SetConnMaxLifetime()

func (*DBManager) SetMaxIdleConns

func (holder *DBManager) SetMaxIdleConns(n int)

Wrapper for sql.DB#SetMaxIdleConns()

func (*DBManager) SetMaxOpenConns

func (holder *DBManager) SetMaxOpenConns(n int)

Wrapper for sql.DB#SetMaxOpenConns()

func (*DBManager) Stats

func (holder *DBManager) Stats() sql.DBStats

Wrapper for sql.DB#Stats()

type Db

type Db struct {
	DbType   string `yaml:"type"`
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	User     string `yaml:"user"`
	Password string `yaml:"password"`
	Name     string `yaml:"name"`
	Schema   string `yaml:"schema"`
}

type DbHolder

type DbHolder interface {
	Finalize() error

	Close() error

	// Wrapper for sql.DB#PingContext()
	PingContext(ctx context.Context) error

	// Wrapper for sql.DB#Ping()
	Ping() error

	// Wrapper for sql.DB#SetMaxIdleConns()
	SetMaxIdleConns(n int)

	// Wrapper for sql.DB#SetMaxOpenConns()
	SetMaxOpenConns(n int)

	// Wrapper for sql.DB#SetConnMaxLifetime()
	SetConnMaxLifetime(d time.Duration)

	// Wrapper for sql.DB#Stats()
	Stats() sql.DBStats

	// Wrapper for sql.DB#PrepareContext()
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)

	// Wrapper for sql.DB#Prepare()
	Prepare(query string) (*sql.Stmt, error)

	// Wrapper for sql.DB#ExecContext()
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

	// Wrapper for sql.DB#Exec()
	Exec(query string, args ...interface{}) (sql.Result, error)

	// Wrapper for sql.DB#QueryContext()
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

	// Wrapper for sql.DB#Query()
	Query(query string, args ...interface{}) (*sql.Rows, error)

	// Wrapper for sql.DB#QueryRowContext()
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

	// Wrapper for sql.DB#QueryRow()
	QueryRow(query string, args ...interface{}) *sql.Row

	// Wrapper for sql.DB#BeginTx()
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)

	// Wrapper for sql.DB#Begin()
	Begin() (*sql.Tx, error)

	// Wrapper for sql.DB#Driver()
	Driver() driver.Driver

	// Wrapper for sql.DB#Conn()
	Conn(ctx context.Context) (*sql.Conn, error)
}

type RowObject

type RowObject struct {
	DiffStatus          int8
	ModifiedColumnIndex []uint8
	ColumnNames         []string
	ColScans            []*ColumnScan
	IsBeforeData        bool
}

func (*RowObject) EqualColumns

func (ro *RowObject) EqualColumns(that *RowObject) bool

func (*RowObject) GetKey

func (ro *RowObject) GetKey(pkColumns []string) string

func (*RowObject) String

func (ro *RowObject) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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