diff --git a/lib/format/pgsql8/live/connection.go b/lib/format/pgsql8/live/connection.go deleted file mode 100644 index 1a6c0c5..0000000 --- a/lib/format/pgsql8/live/connection.go +++ /dev/null @@ -1,127 +0,0 @@ -package live - -import ( - "context" - "database/sql" - "fmt" - "strconv" - - "github.com/jackc/pgx/v4" - - "github.com/jackc/pgx/v4/pgxpool" - "github.com/pkg/errors" -) - -//go:generate $ROOTDIR/run _mockgen Connection - -type Connection interface { - Version() (VersionNum, error) - Disconnect() - Query(query string, params ...interface{}) (pgx.Rows, error) - QueryRow(query string, params ...interface{}) pgx.Row - QueryMap(query string, params ...interface{}) (StringMapList, error) - QueryVal(val interface{}, sql string, params ...interface{}) error -} - -type ConnectionFactory interface { - NewConnection(host string, port uint, name, user, pass string) (Connection, error) -} - -type LiveConnectionFactory struct{} - -func (*LiveConnectionFactory) NewConnection(host string, port uint, name, user, pass string) (Connection, error) { - // TODO(go,3) sslmode? - // TODO(go,3) just have the user pass the entire DSN - // TODO(feat) support envvar password - dsnNoPass := fmt.Sprintf("host=%s port=%d user=%s dbname=%s", host, port, user, name) - dsn := dsnNoPass + fmt.Sprintf(" password=%s", pass) - conn, err := pgxpool.Connect(context.Background(), dsn) - if err != nil { - return nil, errors.Wrap(err, "Could not connect to postgres database") - } - - return &LiveConnection{conn}, nil -} - -type ConstantConnectionFactory struct { - Connection Connection -} - -var _ ConnectionFactory = &ConstantConnectionFactory{} - -func (self *ConstantConnectionFactory) NewConnection(string, uint, string, string, string) (Connection, error) { - return self.Connection, nil -} - -type NullConnection struct { - Connection -} - -func (*NullConnection) Disconnect() {} - -type LiveConnection struct { - conn *pgxpool.Pool -} - -type StringMap map[string]string -type StringMapList []StringMap - -func (self *LiveConnection) Version() (VersionNum, error) { - var v string // for reasons unknown, this won't scan to int, only string - err := self.QueryVal(&v, "SHOW server_version_num;") - if err != nil { - return 0, err - } - i, err := strconv.Atoi(v) - return VersionNum(i), err -} - -func (self *LiveConnection) Disconnect() { - self.conn.Close() -} - -func (self *LiveConnection) Query(query string, params ...interface{}) (pgx.Rows, error) { - return self.conn.Query(context.TODO(), query, params...) -} -func (self *LiveConnection) QueryRow(query string, params ...interface{}) pgx.Row { - return self.conn.QueryRow(context.TODO(), query, params...) -} - -func (self *LiveConnection) QueryMap(query string, params ...interface{}) (StringMapList, error) { - out := StringMapList{} - rows, err := self.conn.Query(context.TODO(), query, params...) - if err != nil { - return nil, err - } - - fields := rows.FieldDescriptions() - cols := make([]string, len(fields)) - vals := make([]sql.NullString, len(fields)) - dests := make([]interface{}, len(fields)) - for i, field := range fields { - cols[i] = string(field.Name) - dests[i] = &vals[i] - } - - for rows.Next() { - err := rows.Scan(dests...) - if err != nil { - return nil, err - } - - m := StringMap{} - for i, col := range cols { - m[col] = vals[i].String - } - - out = append(out, m) - } - if err := rows.Err(); err != nil { - return nil, err - } - return out, nil -} - -func (self *LiveConnection) QueryVal(val interface{}, sql string, params ...interface{}) error { - return self.conn.QueryRow(context.TODO(), sql, params...).Scan(val) -} diff --git a/lib/format/pgsql8/live/connection_mock.go b/lib/format/pgsql8/live/connection_mock.go deleted file mode 100644 index 15fd9ae..0000000 --- a/lib/format/pgsql8/live/connection_mock.go +++ /dev/null @@ -1,139 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: github.com/dbsteward/dbsteward/lib/format/pgsql8/live (interfaces: Connection) - -// Package live is a generated GoMock package. -package live - -import ( - gomock "github.com/golang/mock/gomock" - v4 "github.com/jackc/pgx/v4" - reflect "reflect" -) - -// MockConnection is a mock of Connection interface -type MockConnection struct { - ctrl *gomock.Controller - recorder *MockConnectionMockRecorder -} - -// MockConnectionMockRecorder is the mock recorder for MockConnection -type MockConnectionMockRecorder struct { - mock *MockConnection -} - -// NewMockConnection creates a new mock instance -func NewMockConnection(ctrl *gomock.Controller) *MockConnection { - mock := &MockConnection{ctrl: ctrl} - mock.recorder = &MockConnectionMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use -func (m *MockConnection) EXPECT() *MockConnectionMockRecorder { - return m.recorder -} - -// Disconnect mocks base method -func (m *MockConnection) Disconnect() { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Disconnect") -} - -// Disconnect indicates an expected call of Disconnect -func (mr *MockConnectionMockRecorder) Disconnect() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Disconnect", reflect.TypeOf((*MockConnection)(nil).Disconnect)) -} - -// Query mocks base method -func (m *MockConnection) Query(arg0 string, arg1 ...interface{}) (v4.Rows, error) { - m.ctrl.T.Helper() - varargs := []interface{}{arg0} - for _, a := range arg1 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Query", varargs...) - ret0, _ := ret[0].(v4.Rows) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Query indicates an expected call of Query -func (mr *MockConnectionMockRecorder) Query(arg0 interface{}, arg1 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0}, arg1...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Query", reflect.TypeOf((*MockConnection)(nil).Query), varargs...) -} - -// QueryMap mocks base method -func (m *MockConnection) QueryMap(arg0 string, arg1 ...interface{}) (StringMapList, error) { - m.ctrl.T.Helper() - varargs := []interface{}{arg0} - for _, a := range arg1 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "QueryMap", varargs...) - ret0, _ := ret[0].(StringMapList) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// QueryMap indicates an expected call of QueryMap -func (mr *MockConnectionMockRecorder) QueryMap(arg0 interface{}, arg1 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0}, arg1...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryMap", reflect.TypeOf((*MockConnection)(nil).QueryMap), varargs...) -} - -// QueryRow mocks base method -func (m *MockConnection) QueryRow(arg0 string, arg1 ...interface{}) v4.Row { - m.ctrl.T.Helper() - varargs := []interface{}{arg0} - for _, a := range arg1 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "QueryRow", varargs...) - ret0, _ := ret[0].(v4.Row) - return ret0 -} - -// QueryRow indicates an expected call of QueryRow -func (mr *MockConnectionMockRecorder) QueryRow(arg0 interface{}, arg1 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0}, arg1...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryRow", reflect.TypeOf((*MockConnection)(nil).QueryRow), varargs...) -} - -// QueryVal mocks base method -func (m *MockConnection) QueryVal(arg0 interface{}, arg1 string, arg2 ...interface{}) error { - m.ctrl.T.Helper() - varargs := []interface{}{arg0, arg1} - for _, a := range arg2 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "QueryVal", varargs...) - ret0, _ := ret[0].(error) - return ret0 -} - -// QueryVal indicates an expected call of QueryVal -func (mr *MockConnectionMockRecorder) QueryVal(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{arg0, arg1}, arg2...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryVal", reflect.TypeOf((*MockConnection)(nil).QueryVal), varargs...) -} - -// Version mocks base method -func (m *MockConnection) Version() (VersionNum, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Version") - ret0, _ := ret[0].(VersionNum) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Version indicates an expected call of Version -func (mr *MockConnectionMockRecorder) Version() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Version", reflect.TypeOf((*MockConnection)(nil).Version)) -} diff --git a/lib/format/pgsql8/live/features.go b/lib/format/pgsql8/live/features.go deleted file mode 100644 index 26585e3..0000000 --- a/lib/format/pgsql8/live/features.go +++ /dev/null @@ -1,32 +0,0 @@ -package live - -func VersAtLeast(major, minor int) func(VersionNum) bool { - return func(v VersionNum) bool { - return v.IsAtLeast(major, minor) - } -} - -// In 9.1, `information_schema.triggers` deprecated use of the `action_timing` -// column in favor of `condition_timing`. As far as I can tell, the two columns -// are functionally equivalent. -var FEAT_TRIGGER_USE_ACTION_TIMING = VersAtLeast(9, 1) - -// In 10.0 `pg_catalog.pg_sequence` became available for use, and the old ability -// to SELECT from the sequence got heavily changed -// -// https://www.postgresql.org/docs/10/catalog-pg-sequence.html -var FEAT_SEQUENCE_USE_CATALOG = VersAtLeast(10, 0) - -// In 12.0 pg_catalog.pg_constraint.consrc was removed, in favor of using -// `pg_get_constraintdef(oid)`. Technically, this capability has existed since 8.0, -// however, `consrc` contained the constraint definition as originally written, -// which we preferred over the parsed+pretty-printed version. -// -// https://www.postgresql.org/docs/12/catalog-pg-constraint.html -var FEAT_CONSTRAINT_USE_GETTER = VersAtLeast(12, 0) - -// In 11.0 pg_catalog.pg_proc removed use of `proisagg` and `proiswindow` -// in favor of `prokind` values of 'a' and w' respectively. -// -// https://www.postgresql.org/docs/11/catalog-pg-proc.html -var FEAT_FUNCTION_USE_KIND = VersAtLeast(11, 0) diff --git a/lib/format/pgsql8/live/introspector.go b/lib/format/pgsql8/live/introspector.go deleted file mode 100644 index 07247d8..0000000 --- a/lib/format/pgsql8/live/introspector.go +++ /dev/null @@ -1,624 +0,0 @@ -package live - -import ( - "fmt" - - "github.com/dbsteward/dbsteward/lib/util" - "github.com/jackc/pgx/v4" - "github.com/pkg/errors" -) - -//go:generate $ROOTDIR/run _mockgen Introspector - -// TODO(go, pgsql) Add unit tests for all of this... somehow - -type IntrospectorFactory interface { - NewIntrospector(Connection) (Introspector, error) -} - -type LiveIntrospectorFactory struct{} - -var _ IntrospectorFactory = &LiveIntrospectorFactory{} - -func (*LiveIntrospectorFactory) NewIntrospector(conn Connection) (Introspector, error) { - vers, err := conn.Version() - if err != nil { - return nil, err - } - return &LiveIntrospector{conn, vers}, nil -} - -type ConstantIntrospectorFactory struct { - Introspector Introspector -} - -var _ IntrospectorFactory = &ConstantIntrospectorFactory{} - -func (self *ConstantIntrospectorFactory) NewIntrospector(Connection) (Introspector, error) { - return self.Introspector, nil -} - -type Introspector interface { - GetServerVersion() (VersionNum, error) - GetTableList() ([]TableEntry, error) - GetSchemaOwner(schema string) (string, error) - GetTableStorageOptions(schema, table string) (map[string]string, error) - GetColumns(schema, table string) ([]ColumnEntry, error) - GetIndexes(schema, table string) ([]IndexEntry, error) - GetSequenceRelList(schema string, sequenceCols []string) ([]SequenceRelEntry, error) - GetSequencesForRel(schema, rel string) ([]SequenceEntry, error) - GetViews() ([]ViewEntry, error) - GetConstraints() ([]ConstraintEntry, error) - GetForeignKeys() ([]ForeignKeyEntry, error) - GetFunctions() ([]FunctionEntry, error) - GetFunctionArgs(Oid) ([]FunctionArgEntry, error) - GetTriggers() ([]TriggerEntry, error) - GetTablePerms() ([]TablePermEntry, error) - GetSequencePerms(seq string) ([]SequencePermEntry, error) -} - -type LiveIntrospector struct { - conn Connection - vers VersionNum -} - -var _ Introspector = &LiveIntrospector{} - -func (self *LiveIntrospector) GetServerVersion() (VersionNum, error) { - return self.vers, nil -} - -// TODO(go,3) can we elevate this to an engine-agnostic interface? -// TODO(go,3) can we defer this to model operations entirely? - -func (self *LiveIntrospector) GetTableList() ([]TableEntry, error) { - // TODO(go,3) move column description to column query - // Note that old versions of postgres don't support array_agg(description ORDER BY objsubid) - // so we need to use subquery to do ordering - res, err := self.conn.Query(` - SELECT - t.schemaname, t.tablename, t.tableowner, t.tablespace, - sd.description as schema_description, td.description as table_description, - ( SELECT array_agg(pn.nspname || '.' || pc.relname) - FROM pg_catalog.pg_inherits i - LEFT JOIN pg_catalog.pg_class pc ON (i.inhparent = pc.oid) - LEFT JOIN pg_catalog.pg_namespace pn ON (pc.relnamespace = pn.oid) - WHERE i.inhrelid = c.oid) AS parent_tables - FROM pg_catalog.pg_tables t - LEFT JOIN pg_catalog.pg_namespace n ON (n.nspname = t.schemaname) - LEFT JOIN pg_catalog.pg_class c ON (c.relname = t.tablename AND c.relnamespace = n.oid) - LEFT JOIN pg_catalog.pg_description td ON (td.objoid = c.oid AND td.classoid = c.tableoid AND td.objsubid = 0) - LEFT JOIN pg_catalog.pg_description sd ON (sd.objoid = n.oid) - WHERE schemaname NOT IN ('information_schema', 'pg_catalog') - ORDER BY schemaname, tablename; - `) - if err != nil { - return nil, errors.Wrap(err, "while running query") - } - - out := []TableEntry{} - for res.Next() { - entry := TableEntry{} - err := res.Scan( - &entry.Schema, &entry.Table, &entry.Owner, &entry.Tablespace, - &maybeStr{&entry.SchemaDescription}, &maybeStr{&entry.TableDescription}, - &entry.ParentTables, - ) - if err != nil { - return nil, errors.Wrap(err, "while scanning result") - } - out = append(out, entry) - } - if err := res.Err(); err != nil { - return nil, errors.Wrap(err, "while iterating results") - } - return out, nil -} - -func (self *LiveIntrospector) GetSchemaOwner(schema string) (string, error) { - var owner string - err := self.conn.QueryVal(&owner, `SELECT schema_owner FROM information_schema.schemata WHERE schema_name = $1`, schema) - return owner, err -} - -func (self *LiveIntrospector) GetTableStorageOptions(schema, table string) (map[string]string, error) { - // TODO(feat) can we just add this to the main query? - // NOTE: pg 11.0 dropped support for "with oids" or "oids=true" in DDL - // pg 12.0 drops the relhasoids column from pg_class - var opts struct { - Options []string - HasOids bool - } - - relhasoidsCol := "false as relhasoids" - if self.vers.IsOlderThan(12, 0) { - relhasoidsCol = "relhasoids" - } - - res := self.conn.QueryRow(fmt.Sprintf(` - SELECT reloptions, %s - FROM pg_catalog.pg_class - WHERE relname = $1 - AND relnamespace = ( - SELECT oid - FROM pg_catalog.pg_namespace - WHERE nspname = $2 - ) - `, relhasoidsCol), table, schema) - - err := res.Scan(&opts.Options, &opts.HasOids) - if err != nil { - return nil, err - } - - // Options[i] is formatted as key=value - params := util.CollectKV(opts.Options, "=") - - // dbsteward/dbsteward#97: with oids=false is the default - if opts.HasOids { - params["oids"] = "true" - } - - return params, nil -} - -func (self *LiveIntrospector) GetColumns(schema, table string) ([]ColumnEntry, error) { - res, err := self.conn.Query(` - SELECT - column_name, column_default, is_nullable = 'YES', pgd.description, - ordinal_position, format_type(atttypid, atttypmod) as attribute_data_type - FROM information_schema.columns - JOIN pg_class pgc ON (pgc.relname = table_name AND pgc.relkind='r') - JOIN pg_namespace nsp ON (nsp.nspname = table_schema AND nsp.oid = pgc.relnamespace) - JOIN pg_attribute pga ON (pga.attrelid = pgc.oid AND columns.column_name = pga.attname) - LEFT JOIN pg_description pgd ON (pgd.objoid = pgc.oid AND pgd.classoid = pgc.tableoid AND pgd.objsubid = ordinal_position) - WHERE table_schema=$1 AND table_name=$2 - AND attnum > 0 - AND NOT attisdropped - ORDER BY ordinal_position ASC - `, schema, table) - if err != nil { - return nil, errors.Wrap(err, "while running query") - } - - out := []ColumnEntry{} - for res.Next() { - entry := ColumnEntry{} - err := res.Scan( - &entry.Name, &maybeStr{&entry.Default}, &entry.Nullable, - &maybeStr{&entry.Description}, &entry.Position, &entry.AttrType, - ) - if err != nil { - return nil, errors.Wrap(err, "while scanning result") - } - out = append(out, entry) - } - if err := res.Err(); err != nil { - return nil, errors.Wrap(err, "while iterating results") - } - return out, nil -} - -func (self *LiveIntrospector) GetIndexes(schema, table string) ([]IndexEntry, error) { - // TODO(go,nth) double check the `relname NOT IN` clause, it smells fishy to me - res, err := self.conn.Query(` - SELECT - ic.relname, i.indisunique, - ( - -- get the n'th dimension's definition - SELECT array_agg(pg_catalog.pg_get_indexdef(i.indexrelid, n, true)) - FROM generate_series(1, i.indnatts) AS n - ) AS dimensions - FROM pg_index i - LEFT JOIN pg_class ic ON ic.oid = i.indexrelid - LEFT JOIN pg_class tc ON tc.oid = i.indrelid - LEFT JOIN pg_catalog.pg_namespace n ON n.oid = tc.relnamespace - WHERE tc.relname = $2 - AND n.nspname = $1 - AND i.indisprimary != 't' - AND ic.relname NOT IN ( - SELECT constraint_name - FROM information_schema.table_constraints - WHERE table_schema = $1 - AND table_name = $2); - `, schema, table) - if err != nil { - return nil, errors.Wrap(err, "while running query") - } - - out := []IndexEntry{} - for res.Next() { - entry := IndexEntry{} - err := res.Scan(&entry.Name, &entry.Unique, &entry.Dimensions) - if err != nil { - return nil, errors.Wrap(err, "while scanning result") - } - out = append(out, entry) - } - if err := res.Err(); err != nil { - return nil, errors.Wrap(err, "while iterating results") - } - return out, nil -} - -func (self *LiveIntrospector) GetSequenceRelList(schema string, sequenceCols []string) ([]SequenceRelEntry, error) { - sql := ` - SELECT s.relname, r.rolname - FROM pg_statio_all_sequences s - JOIN pg_class c ON (s.relname = c.relname) - JOIN pg_roles r ON (c.relowner = r.oid) - WHERE schemaname = $1 - ` - params := []interface{}{schema} - if len(sequenceCols) > 0 { - sql += `AND s.relname != ANY($2)` - params = append(params, sequenceCols) - } - sql += `GROUP BY s.relname, r.rolname` - res, err := self.conn.Query(sql, params...) - if err != nil { - return nil, errors.Wrap(err, "while running query") - } - - out := []SequenceRelEntry{} - for res.Next() { - entry := SequenceRelEntry{} - err := res.Scan(&entry.Name, &entry.Owner) - if err != nil { - return nil, errors.Wrap(err, "while scanning result") - } - out = append(out, entry) - } - if err := res.Err(); err != nil { - return nil, errors.Wrap(err, "while iterating results") - } - return out, nil -} - -func (self *LiveIntrospector) GetSequencesForRel(schema, rel string) ([]SequenceEntry, error) { - // TODO(feat) can we merge into GetSequenceRelList()? This is kept separate just because - // the old code was too - var res pgx.Rows - var err error - - // Note that we select equivalent values in the same order so we can reuse the same scanning code - if FEAT_SEQUENCE_USE_CATALOG(self.vers) { - res, err = self.conn.Query(` - SELECT seqcache, seqstart, seqmin, seqmax, seqincrement, seqcycle - FROM pg_catalog.pg_sequence s - LEFT JOIN pg_catalog.pg_class c ON s.seqrelid = c.oid - LEFT JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid - WHERE n.nspname = $1 AND c.relname = $2 - `, schema, rel) - } else { - res, err = self.conn.Query(fmt.Sprintf(` - SELECT cache_value, start_value, min_value, max_value, increment_by, is_cycled - FROM "%s"."%s" - `, schema, rel)) - } - if err != nil { - return nil, errors.Wrap(err, "while running query") - } - - out := []SequenceEntry{} - for res.Next() { - entry := SequenceEntry{} - err := res.Scan(&entry.Cache, &entry.Start, &entry.Min, &entry.Max, &entry.Increment, &entry.Cycled) - if err != nil { - return nil, errors.Wrap(err, "while scanning result") - } - out = append(out, entry) - } - if err := res.Err(); err != nil { - return nil, errors.Wrap(err, "while iterating results") - } - return out, nil -} - -func (self *LiveIntrospector) GetViews() ([]ViewEntry, error) { - res, err := self.conn.Query(` - SELECT schemaname, viewname, viewowner, definition - FROM pg_catalog.pg_views - WHERE schemaname NOT IN ('information_schema', 'pg_catalog') - ORDER BY schemaname, viewname; - `) - if err != nil { - return nil, errors.Wrap(err, "while running query") - } - - out := []ViewEntry{} - for res.Next() { - entry := ViewEntry{} - err := res.Scan(&entry.Schema, &entry.Name, &entry.Owner, &entry.Definition) - if err != nil { - return nil, errors.Wrap(err, "while scanning result") - } - out = append(out, entry) - } - if err := res.Err(); err != nil { - return nil, errors.Wrap(err, "while iterating results") - } - return out, nil -} - -func (self *LiveIntrospector) GetConstraints() ([]ConstraintEntry, error) { - consrcCol := "consrc AS check_src" - if FEAT_CONSTRAINT_USE_GETTER(self.vers) { - // NOTE: Passing `true` as second parameter "pretty-prints" the definition, however: - // > The pretty-printed format is more readable, but the default format is more likely - // > to be interpreted the same way by future versions of PostgreSQL; avoid using - // > pretty-printed output for dump purposes - // - https://www.postgresql.org/docs/12/functions-info.html - consrcCol = "pg_get_constraintdef(pgc.oid) AS check_src" - } - - res, err := self.conn.Query(fmt.Sprintf(` - SELECT - nspname AS table_schema, - relname AS table_name, - conname AS constraint_name, - contype AS constraint_type, - %s, - ( - SELECT array_agg(attname) - FROM unnest(conkey) num - INNER JOIN pg_catalog.pg_attribute pga ON pga.attrelid = pgt.oid AND pga.attnum = num - )::text[] AS columns - FROM pg_catalog.pg_constraint pgc - LEFT JOIN pg_catalog.pg_class pgt ON pgc.conrelid = pgt.oid - LEFT JOIN pg_catalog.pg_namespace pgn ON pgc.connamespace = pgn.oid - WHERE pgn.nspname not in ('information_schema', 'pg_catalog') - AND contype != 'f' -- ignore foreign keys here - ORDER BY pgn.nspname, pgt.relname - `, consrcCol)) - if err != nil { - return nil, errors.Wrap(err, "while running query") - } - - out := []ConstraintEntry{} - for res.Next() { - entry := ConstraintEntry{} - err := res.Scan(&entry.Schema, &entry.Table, &entry.Name, &char2str{&entry.Type}, &entry.CheckDef, &entry.Columns) - if err != nil { - return nil, errors.Wrap(err, "while scanning result") - } - out = append(out, entry) - } - if err := res.Err(); err != nil { - return nil, errors.Wrap(err, "while iterating results") - } - return out, nil -} - -func (self *LiveIntrospector) GetForeignKeys() ([]ForeignKeyEntry, error) { - // We cannot accurately retrieve FOREIGN KEYs via information_schema - // We must rely on getting them from pg_catalog instead - // See http://stackoverflow.com/questions/1152260/postgres-sql-to-list-table-foreign-keys - res, err := self.conn.Query(` - SELECT - con.constraint_name, con.update_rule, con.delete_rule, - lns.nspname AS local_schema, lt_cl.relname AS local_table, array_agg(lc_att.attname)::text[] AS local_columns, - fns.nspname AS foreign_schema, ft_cl.relname AS foreign_table, array_agg(fc_att.attname)::text[] AS foreign_columns - FROM ( - -- get column mappings - SELECT - local_constraint.conrelid AS local_table, unnest(local_constraint.conkey) AS local_col, - local_constraint.confrelid AS foreign_table, unnest(local_constraint.confkey) AS foreign_col, - local_constraint.conname AS constraint_name, local_constraint.confupdtype AS update_rule, local_constraint.confdeltype as delete_rule - FROM pg_class cl - INNER JOIN pg_namespace ns ON cl.relnamespace = ns.oid - INNER JOIN pg_constraint local_constraint ON local_constraint.conrelid = cl.oid - WHERE ns.nspname NOT IN ('pg_catalog','information_schema') - AND local_constraint.contype = 'f' - ) con - INNER JOIN pg_class lt_cl ON lt_cl.oid = con.local_table - INNER JOIN pg_namespace lns ON lns.oid = lt_cl.relnamespace - INNER JOIN pg_attribute lc_att ON lc_att.attrelid = con.local_table AND lc_att.attnum = con.local_col - INNER JOIN pg_class ft_cl ON ft_cl.oid = con.foreign_table - INNER JOIN pg_namespace fns ON fns.oid = ft_cl.relnamespace - INNER JOIN pg_attribute fc_att ON fc_att.attrelid = con.foreign_table AND fc_att.attnum = con.foreign_col - GROUP BY con.constraint_name, lns.nspname, lt_cl.relname, fns.nspname, ft_cl.relname, con.update_rule, con.delete_rule; - `) - if err != nil { - return nil, errors.Wrap(err, "while running query") - } - - out := []ForeignKeyEntry{} - for res.Next() { - entry := ForeignKeyEntry{} - err := res.Scan( - &entry.ConstraintName, &char2str{&entry.UpdateRule}, &char2str{&entry.DeleteRule}, - &entry.LocalSchema, &entry.LocalTable, &entry.LocalColumns, - &entry.ForeignSchema, &entry.ForeignTable, &entry.ForeignColumns, - ) - if err != nil { - return nil, errors.Wrap(err, "while scanning result") - } - out = append(out, entry) - } - if err := res.Err(); err != nil { - return nil, errors.Wrap(err, "while iterating results") - } - return out, nil -} - -func (self *LiveIntrospector) GetFunctions() ([]FunctionEntry, error) { - typeCase := ` - WHEN p.proisagg THEN 'aggregate' - WHEN p.proiswindow THEN 'window' - ` - if FEAT_FUNCTION_USE_KIND(self.vers) { - typeCase = ` - WHEN p.prokind = 'a' THEN 'aggregate' - WHEN p.prokind = 'w' THEN 'window' - ` - } - - res, err := self.conn.Query(fmt.Sprintf(` - SELECT - p.oid as oid, n.nspname as schema, p.proname as name, - pg_catalog.pg_get_function_result(p.oid) as return_type, - CASE - %s - WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN 'trigger' - ELSE 'normal' - END as type, - CASE - WHEN p.provolatile = 'i' THEN 'IMMUTABLE' - WHEN p.provolatile = 's' THEN 'STABLE' - WHEN p.provolatile = 'v' THEN 'VOLATILE' - END as volatility, - pg_catalog.pg_get_userbyid(p.proowner) as owner, - l.lanname as language, - p.prosrc as source, - COALESCE(pg_catalog.obj_description(p.oid, 'pg_proc'), '') as description - FROM pg_catalog.pg_proc p - LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace - LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang - WHERE n.nspname NOT IN ('pg_catalog', 'information_schema'); - `, typeCase)) - if err != nil { - return nil, errors.Wrap(err, "while running query") - } - - out := []FunctionEntry{} - for res.Next() { - entry := FunctionEntry{} - err := res.Scan( - &entry.Oid, &entry.Schema, &entry.Name, &entry.Return, - &entry.Type, &entry.Volatility, &entry.Owner, - &entry.Language, &entry.Source, &entry.Description, - ) - if err != nil { - return nil, errors.Wrap(err, "while scanning result") - } - out = append(out, entry) - } - if err := res.Err(); err != nil { - return nil, errors.Wrap(err, "while iterating results") - } - return out, nil -} - -func (self *LiveIntrospector) GetFunctionArgs(fnOid Oid) ([]FunctionArgEntry, error) { - // unnest the proargtypes (which are in ordinal order) and get the correct format for them. - // information_schema.parameters does not contain enough information to get correct type (e.g. ARRAY) - // Note: * proargnames can be empty (not null) if there are no parameters names - // * proargnames will contain empty strings for unnamed parameters if there are other named - // parameters, e.g. {"", parameter_name} - // * proargtypes is an oidvector, enjoy the hackery to deal with NULL proargnames - // * proallargtypes is NULL when all arguments are IN. - // TODO(go,3) use something besides oid - // TODO(feat) support directionality - res, err := self.conn.Query(` - SELECT - unnest(coalesce( - proargnames, - array_fill(''::text, ARRAY[( - SELECT count(*) - FROM unnest(coalesce(proallargtypes, proargtypes)) - )]::int[]) - )) as parameter_name, - format_type(unnest(coalesce(proallargtypes, proargtypes)), NULL) AS data_type - FROM pg_proc pr - WHERE oid = $1 - `, fnOid) - if err != nil { - return nil, errors.Wrap(err, "while running query") - } - - out := []FunctionArgEntry{} - for res.Next() { - entry := FunctionArgEntry{} - err := res.Scan(&entry.Name, &entry.Type) - if err != nil { - return nil, errors.Wrap(err, "while scanning result") - } - out = append(out, entry) - } - if err := res.Err(); err != nil { - return nil, errors.Wrap(err, "while iterating results") - } - return out, nil -} - -func (self *LiveIntrospector) GetTriggers() ([]TriggerEntry, error) { - timingCol := "condition_timing" - if FEAT_TRIGGER_USE_ACTION_TIMING(self.vers) { - timingCol = "action_timing" - } - res, err := self.conn.Query(fmt.Sprintf(` - SELECT - event_object_schema, event_object_table, trigger_name, - event_manipulation, %s, - action_orientation, action_statement - FROM information_schema.triggers - WHERE trigger_schema NOT IN ('pg_catalog', 'information_schema') - `, timingCol)) - if err != nil { - return nil, errors.Wrap(err, "while running query") - } - - out := []TriggerEntry{} - for res.Next() { - entry := TriggerEntry{} - err := res.Scan( - &entry.Schema, &entry.Table, &entry.Name, &entry.Event, - &entry.Timing, &entry.Orientation, &entry.Statement, - ) - if err != nil { - return nil, errors.Wrap(err, "while scanning result") - } - out = append(out, entry) - } - if err := res.Err(); err != nil { - return nil, errors.Wrap(err, "while iterating results") - } - return out, nil -} - -func (self *LiveIntrospector) GetTablePerms() ([]TablePermEntry, error) { - res, err := self.conn.Query(` - SELECT table_schema, table_name, grantee, privilege_type, is_grantable = 'YES' - FROM information_schema.table_privileges - WHERE table_schema NOT IN ('pg_catalog', 'information_schema') - `) - if err != nil { - return nil, errors.Wrap(err, "while running query") - } - - out := []TablePermEntry{} - for res.Next() { - entry := TablePermEntry{} - err := res.Scan(&entry.Schema, &entry.Table, &entry.Grantee, &entry.Type, &entry.Grantable) - if err != nil { - return nil, errors.Wrap(err, "while scanning result") - } - out = append(out, entry) - } - if err := res.Err(); err != nil { - return nil, errors.Wrap(err, "while iterating results") - } - return out, nil -} - -func (self *LiveIntrospector) GetSequencePerms(seq string) ([]SequencePermEntry, error) { - res, err := self.conn.Query(`SELECT relacl FROM pg_class WHERE relname = $1`, seq) - if err != nil { - return nil, errors.Wrap(err, "while running query") - } - - out := []SequencePermEntry{} - for res.Next() { - entry := SequencePermEntry{} - err := res.Scan(&entry.Acl) - if err != nil { - return nil, errors.Wrap(err, "while scanning result") - } - out = append(out, entry) - } - if err := res.Err(); err != nil { - return nil, errors.Wrap(err, "while iterating results") - } - return out, nil -} diff --git a/lib/format/pgsql8/live/introspector_mock.go b/lib/format/pgsql8/live/introspector_mock.go deleted file mode 100644 index 2140e96..0000000 --- a/lib/format/pgsql8/live/introspector_mock.go +++ /dev/null @@ -1,273 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: github.com/dbsteward/dbsteward/lib/format/pgsql8/live (interfaces: Introspector) - -// Package live is a generated GoMock package. -package live - -import ( - gomock "github.com/golang/mock/gomock" - reflect "reflect" -) - -// MockIntrospector is a mock of Introspector interface -type MockIntrospector struct { - ctrl *gomock.Controller - recorder *MockIntrospectorMockRecorder -} - -// MockIntrospectorMockRecorder is the mock recorder for MockIntrospector -type MockIntrospectorMockRecorder struct { - mock *MockIntrospector -} - -// NewMockIntrospector creates a new mock instance -func NewMockIntrospector(ctrl *gomock.Controller) *MockIntrospector { - mock := &MockIntrospector{ctrl: ctrl} - mock.recorder = &MockIntrospectorMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use -func (m *MockIntrospector) EXPECT() *MockIntrospectorMockRecorder { - return m.recorder -} - -// GetColumns mocks base method -func (m *MockIntrospector) GetColumns(arg0, arg1 string) ([]ColumnEntry, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetColumns", arg0, arg1) - ret0, _ := ret[0].([]ColumnEntry) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetColumns indicates an expected call of GetColumns -func (mr *MockIntrospectorMockRecorder) GetColumns(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetColumns", reflect.TypeOf((*MockIntrospector)(nil).GetColumns), arg0, arg1) -} - -// GetConstraints mocks base method -func (m *MockIntrospector) GetConstraints() ([]ConstraintEntry, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetConstraints") - ret0, _ := ret[0].([]ConstraintEntry) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetConstraints indicates an expected call of GetConstraints -func (mr *MockIntrospectorMockRecorder) GetConstraints() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetConstraints", reflect.TypeOf((*MockIntrospector)(nil).GetConstraints)) -} - -// GetForeignKeys mocks base method -func (m *MockIntrospector) GetForeignKeys() ([]ForeignKeyEntry, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetForeignKeys") - ret0, _ := ret[0].([]ForeignKeyEntry) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetForeignKeys indicates an expected call of GetForeignKeys -func (mr *MockIntrospectorMockRecorder) GetForeignKeys() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetForeignKeys", reflect.TypeOf((*MockIntrospector)(nil).GetForeignKeys)) -} - -// GetFunctionArgs mocks base method -func (m *MockIntrospector) GetFunctionArgs(arg0 Oid) ([]FunctionArgEntry, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetFunctionArgs", arg0) - ret0, _ := ret[0].([]FunctionArgEntry) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetFunctionArgs indicates an expected call of GetFunctionArgs -func (mr *MockIntrospectorMockRecorder) GetFunctionArgs(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFunctionArgs", reflect.TypeOf((*MockIntrospector)(nil).GetFunctionArgs), arg0) -} - -// GetFunctions mocks base method -func (m *MockIntrospector) GetFunctions() ([]FunctionEntry, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetFunctions") - ret0, _ := ret[0].([]FunctionEntry) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetFunctions indicates an expected call of GetFunctions -func (mr *MockIntrospectorMockRecorder) GetFunctions() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFunctions", reflect.TypeOf((*MockIntrospector)(nil).GetFunctions)) -} - -// GetIndexes mocks base method -func (m *MockIntrospector) GetIndexes(arg0, arg1 string) ([]IndexEntry, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetIndexes", arg0, arg1) - ret0, _ := ret[0].([]IndexEntry) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetIndexes indicates an expected call of GetIndexes -func (mr *MockIntrospectorMockRecorder) GetIndexes(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetIndexes", reflect.TypeOf((*MockIntrospector)(nil).GetIndexes), arg0, arg1) -} - -// GetSchemaOwner mocks base method -func (m *MockIntrospector) GetSchemaOwner(arg0 string) (string, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSchemaOwner", arg0) - ret0, _ := ret[0].(string) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetSchemaOwner indicates an expected call of GetSchemaOwner -func (mr *MockIntrospectorMockRecorder) GetSchemaOwner(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSchemaOwner", reflect.TypeOf((*MockIntrospector)(nil).GetSchemaOwner), arg0) -} - -// GetSequencePerms mocks base method -func (m *MockIntrospector) GetSequencePerms(arg0 string) ([]SequencePermEntry, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSequencePerms", arg0) - ret0, _ := ret[0].([]SequencePermEntry) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetSequencePerms indicates an expected call of GetSequencePerms -func (mr *MockIntrospectorMockRecorder) GetSequencePerms(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSequencePerms", reflect.TypeOf((*MockIntrospector)(nil).GetSequencePerms), arg0) -} - -// GetSequenceRelList mocks base method -func (m *MockIntrospector) GetSequenceRelList(arg0 string, arg1 []string) ([]SequenceRelEntry, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSequenceRelList", arg0, arg1) - ret0, _ := ret[0].([]SequenceRelEntry) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetSequenceRelList indicates an expected call of GetSequenceRelList -func (mr *MockIntrospectorMockRecorder) GetSequenceRelList(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSequenceRelList", reflect.TypeOf((*MockIntrospector)(nil).GetSequenceRelList), arg0, arg1) -} - -// GetSequencesForRel mocks base method -func (m *MockIntrospector) GetSequencesForRel(arg0, arg1 string) ([]SequenceEntry, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSequencesForRel", arg0, arg1) - ret0, _ := ret[0].([]SequenceEntry) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetSequencesForRel indicates an expected call of GetSequencesForRel -func (mr *MockIntrospectorMockRecorder) GetSequencesForRel(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSequencesForRel", reflect.TypeOf((*MockIntrospector)(nil).GetSequencesForRel), arg0, arg1) -} - -// GetServerVersion mocks base method -func (m *MockIntrospector) GetServerVersion() (VersionNum, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetServerVersion") - ret0, _ := ret[0].(VersionNum) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetServerVersion indicates an expected call of GetServerVersion -func (mr *MockIntrospectorMockRecorder) GetServerVersion() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetServerVersion", reflect.TypeOf((*MockIntrospector)(nil).GetServerVersion)) -} - -// GetTableList mocks base method -func (m *MockIntrospector) GetTableList() ([]TableEntry, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTableList") - ret0, _ := ret[0].([]TableEntry) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetTableList indicates an expected call of GetTableList -func (mr *MockIntrospectorMockRecorder) GetTableList() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTableList", reflect.TypeOf((*MockIntrospector)(nil).GetTableList)) -} - -// GetTablePerms mocks base method -func (m *MockIntrospector) GetTablePerms() ([]TablePermEntry, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTablePerms") - ret0, _ := ret[0].([]TablePermEntry) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetTablePerms indicates an expected call of GetTablePerms -func (mr *MockIntrospectorMockRecorder) GetTablePerms() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTablePerms", reflect.TypeOf((*MockIntrospector)(nil).GetTablePerms)) -} - -// GetTableStorageOptions mocks base method -func (m *MockIntrospector) GetTableStorageOptions(arg0, arg1 string) (map[string]string, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTableStorageOptions", arg0, arg1) - ret0, _ := ret[0].(map[string]string) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetTableStorageOptions indicates an expected call of GetTableStorageOptions -func (mr *MockIntrospectorMockRecorder) GetTableStorageOptions(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTableStorageOptions", reflect.TypeOf((*MockIntrospector)(nil).GetTableStorageOptions), arg0, arg1) -} - -// GetTriggers mocks base method -func (m *MockIntrospector) GetTriggers() ([]TriggerEntry, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTriggers") - ret0, _ := ret[0].([]TriggerEntry) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetTriggers indicates an expected call of GetTriggers -func (mr *MockIntrospectorMockRecorder) GetTriggers() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTriggers", reflect.TypeOf((*MockIntrospector)(nil).GetTriggers)) -} - -// GetViews mocks base method -func (m *MockIntrospector) GetViews() ([]ViewEntry, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetViews") - ret0, _ := ret[0].([]ViewEntry) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetViews indicates an expected call of GetViews -func (mr *MockIntrospectorMockRecorder) GetViews() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetViews", reflect.TypeOf((*MockIntrospector)(nil).GetViews)) -} diff --git a/lib/format/pgsql8/live/scanners.go b/lib/format/pgsql8/live/scanners.go deleted file mode 100644 index 0d72df7..0000000 --- a/lib/format/pgsql8/live/scanners.go +++ /dev/null @@ -1,35 +0,0 @@ -package live - -import ( - "database/sql" - "fmt" -) - -type maybeStr struct { - str *string -} - -func (self *maybeStr) Scan(value interface{}) error { - s := sql.NullString{} - err := s.Scan(value) - if err != nil { - return err - } - *self.str = s.String - return nil -} - -// For reasons unknown, pgx doesn't know how to scan a pgsql char into a go string -type char2str struct { - str *string -} - -func (self *char2str) Scan(value interface{}) error { - switch v := value.(type) { - case []uint8: - *self.str = string(v) - default: - return fmt.Errorf("unexpected underlying pgx type %T (%v) for a pgsql char", v, v) - } - return nil -} diff --git a/lib/format/pgsql8/live/types.go b/lib/format/pgsql8/live/types.go deleted file mode 100644 index 2ce16c2..0000000 --- a/lib/format/pgsql8/live/types.go +++ /dev/null @@ -1,118 +0,0 @@ -package live - -import ( - "database/sql" - - "github.com/jackc/pgtype" -) - -type TableEntry struct { - Schema string - Table string - Owner string - Tablespace *string - SchemaDescription string - TableDescription string - ParentTables []string -} - -type ColumnEntry struct { - Name string - Default string - Nullable bool - Description string - Position int - AttrType string -} - -type IndexEntry struct { - Name string - Unique bool - Dimensions []string -} - -type SequenceRelEntry struct { - Name string - Owner string -} - -type SequenceEntry struct { - Cache sql.NullInt64 - Start sql.NullInt64 - Min sql.NullInt64 - Max sql.NullInt64 - Increment sql.NullInt64 - Cycled bool -} - -type ViewEntry struct { - Schema string - Name string - Owner string - Definition string -} - -type ConstraintEntry struct { - Schema string - Table string - Name string - Type string - CheckDef *string - Columns []string -} - -type ForeignKeyEntry struct { - ConstraintName string - UpdateRule string - DeleteRule string - LocalSchema string - LocalTable string - LocalColumns []string - ForeignSchema string - ForeignTable string - ForeignColumns []string -} - -type Oid struct { - pgtype.OID -} - -type FunctionEntry struct { - Oid Oid - Schema string - Name string - Return string - Type string - Volatility string - Owner string - Language string - Source string - Description string -} - -type FunctionArgEntry struct { - Name string - Type string -} - -type TriggerEntry struct { - Schema string - Table string - Name string - Event string - Timing string - Orientation string - Statement string -} - -type TablePermEntry struct { - Schema string - Table string - Grantee string - Type string - Grantable bool -} - -type SequencePermEntry struct { - Acl string -} diff --git a/lib/format/pgsql8/live/version.go b/lib/format/pgsql8/live/version.go deleted file mode 100644 index 29474b1..0000000 --- a/lib/format/pgsql8/live/version.go +++ /dev/null @@ -1,59 +0,0 @@ -package live - -import "fmt" - -// https://www.postgresql.org/support/versioning/ -// This is obtained from `SHOW server_version_num;` -// Prior to 10.0, Version X.Y.Z was represented as X*10000+Y*100+Z -// 8.4.22 -> 80422 -// 9.1.0 -> 90100 -// Starting with 10.0, Version X.Y is represented as X*10000 + Y -// 12.5 -> 120005 -type VersionNum int - -func NewVersionNum(major, minor int, patch ...int) VersionNum { - if major >= 10 { - // disregard patch after 10.0 - return VersionNum(major*10000 + minor) - } - // if patch not provided assume 0 - if len(patch) == 0 { - patch = []int{0} - } - return VersionNum(major*10000 + minor*100 + patch[0]) -} - -func (self VersionNum) IsOlderThan(major, minor int, patch ...int) bool { - return self < NewVersionNum(major, minor, patch...) -} - -func (self VersionNum) IsAtLeast(major, minor int, patch ...int) bool { - return !self.IsOlderThan(major, minor, patch...) -} - -func (self VersionNum) String() string { - major := self.Major() - if major < 10 { - return fmt.Sprintf("%d.%d.%d", major, self.Minor(), self.Patch()) - } else { - return fmt.Sprintf("%d.%d", major, self.Minor()) - } -} - -func (self VersionNum) Major() int { - return int(self) / 10000 -} - -func (self VersionNum) Minor() int { - if self < 10000 { - return (int(self) % 10000) / 100 - } - return int(self) % 10000 -} - -func (self VersionNum) Patch() int { - if self < 10000 { - return int(self) % 100 - } - return 0 -} diff --git a/lib/format/pgsql8/operations.go b/lib/format/pgsql8/operations.go index e6c721c..966e367 100644 --- a/lib/format/pgsql8/operations.go +++ b/lib/format/pgsql8/operations.go @@ -6,8 +6,6 @@ import ( "strings" "time" - "github.com/dbsteward/dbsteward/lib/format/pgsql8/live" - "github.com/dbsteward/dbsteward/lib/format/pgsql8/sql" "github.com/dbsteward/dbsteward/lib/format/sql99" "github.com/dbsteward/dbsteward/lib/output" @@ -21,8 +19,8 @@ type Operations struct { *sql99.Operations EscapeStringValues bool - IntrospectorFactory live.IntrospectorFactory - ConnectionFactory live.ConnectionFactory + IntrospectorFactory IntrospectorFactory + ConnectionFactory ConnectionFactory quoter output.Quoter } @@ -31,8 +29,8 @@ func NewOperations() *Operations { pgsql := &Operations{ Operations: sql99.NewOperations(), EscapeStringValues: false, - IntrospectorFactory: &live.LiveIntrospectorFactory{}, - ConnectionFactory: &live.LiveConnectionFactory{}, + IntrospectorFactory: &LiveIntrospectorFactory{}, + ConnectionFactory: &LiveConnectionFactory{}, } pgsql.Operations.Operations = pgsql return pgsql @@ -819,7 +817,7 @@ func (self *Operations) CompareDbData(doc *ir.Definition, host string, port uint } return doc } -func (self *Operations) compareDbDataRow(conn live.Connection, colType, xmlValue, dbValue string) (bool, string, string) { +func (self *Operations) compareDbDataRow(conn Connection, colType, xmlValue, dbValue string) (bool, string, string) { colType = strings.ToLower(colType) xmlValue = self.pgdataHomogenize(colType, xmlValue) dbValue = self.pgdataHomogenize(colType, dbValue) diff --git a/lib/format/pgsql8/operations_extract_schema_test.go b/lib/format/pgsql8/operations_extract_schema_test.go index 525b75b..2fccc66 100644 --- a/lib/format/pgsql8/operations_extract_schema_test.go +++ b/lib/format/pgsql8/operations_extract_schema_test.go @@ -12,11 +12,10 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" - "github.com/dbsteward/dbsteward/lib/format/pgsql8/live" "github.com/dbsteward/dbsteward/lib/ir" ) -var PG_8_0 live.VersionNum = live.NewVersionNum(8, 0) +var PG_8_0 pgsql8.VersionNum = pgsql8.NewVersionNum(8, 0) // TODO(go,3) is there a way to make this set of tests a whole lot less annoying? // TODO(go,pgsql) the v1 ExtractionTest tested what is now ExtractSchema, Introspector, Connection, _and_ postgres @@ -26,7 +25,7 @@ var PG_8_0 live.VersionNum = live.NewVersionNum(8, 0) /* Copy+paste and change for each test: func TestOperations_ExtractSchema_Something(t *testing.T) { ctrl := gomock.NewController(t) - introspector := live.NewMockIntrospector(ctrl) + introspector := pgsql8.NewMockIntrospector(ctrl) introspector.EXPECT().GetSchemaOwner(gomock.Any()).AnyTimes() introspector.EXPECT().GetTableList().AnyTimes() @@ -50,7 +49,7 @@ func TestOperations_ExtractSchema_Something(t *testing.T) { func TestOperations_ExtractSchema_Indexes(t *testing.T) { ctrl := gomock.NewController(t) - introspector := live.NewMockIntrospector(ctrl) + introspector := pgsql8.NewMockIntrospector(ctrl) introspector.EXPECT().GetSchemaOwner(gomock.Any()).AnyTimes() introspector.EXPECT().GetTableStorageOptions(gomock.Any(), gomock.Any()).AnyTimes() @@ -63,33 +62,33 @@ func TestOperations_ExtractSchema_Indexes(t *testing.T) { introspector.EXPECT().GetTablePerms().AnyTimes() introspector.EXPECT().GetSequencePerms(gomock.Any()).AnyTimes() - introspector.EXPECT().GetTableList().Return([]live.TableEntry{ - live.TableEntry{ + introspector.EXPECT().GetTableList().Return([]pgsql8.TableEntry{ + pgsql8.TableEntry{ Schema: "public", Table: "test", }, }, nil) - introspector.EXPECT().GetColumns("public", "test").Return([]live.ColumnEntry{ - live.ColumnEntry{ + introspector.EXPECT().GetColumns("public", "test").Return([]pgsql8.ColumnEntry{ + pgsql8.ColumnEntry{ Name: "col1", AttrType: "text", Position: 1, }, - live.ColumnEntry{ + pgsql8.ColumnEntry{ Name: "col2", AttrType: "text", Position: 2, }, - live.ColumnEntry{ + pgsql8.ColumnEntry{ Name: "col3", AttrType: "text", Position: 3, }, }, nil) - introspector.EXPECT().GetIndexes("public", "test").Return([]live.IndexEntry{ + introspector.EXPECT().GetIndexes("public", "test").Return([]pgsql8.IndexEntry{ // test that both column and functional expressions work as expected - live.IndexEntry{ + pgsql8.IndexEntry{ Name: "testidx", Dimensions: []string{ "lower(col1)", @@ -100,11 +99,11 @@ func TestOperations_ExtractSchema_Indexes(t *testing.T) { }, }, // test that index column order is extracted correctly - live.IndexEntry{ + pgsql8.IndexEntry{ Name: "testidx2", Dimensions: []string{"col1", "col2", "col3"}, }, - live.IndexEntry{ + pgsql8.IndexEntry{ Name: "testidx3", Dimensions: []string{"col2", "col1", "col3"}, }, @@ -153,7 +152,7 @@ func TestOperations_ExtractSchema_Indexes(t *testing.T) { func TestOperations_ExtractSchema_CompoundUniqueConstraint(t *testing.T) { ctrl := gomock.NewController(t) - introspector := live.NewMockIntrospector(ctrl) + introspector := pgsql8.NewMockIntrospector(ctrl) introspector.EXPECT().GetSchemaOwner(gomock.Any()).AnyTimes() introspector.EXPECT().GetTableStorageOptions(gomock.Any(), gomock.Any()).AnyTimes() @@ -166,32 +165,32 @@ func TestOperations_ExtractSchema_CompoundUniqueConstraint(t *testing.T) { introspector.EXPECT().GetSequencePerms(gomock.Any()).AnyTimes() introspector.EXPECT().GetIndexes("public", "test").AnyTimes() - introspector.EXPECT().GetTableList().Return([]live.TableEntry{ - live.TableEntry{ + introspector.EXPECT().GetTableList().Return([]pgsql8.TableEntry{ + pgsql8.TableEntry{ Schema: "public", Table: "test", }, }, nil) - introspector.EXPECT().GetColumns("public", "test").Return([]live.ColumnEntry{ - live.ColumnEntry{ + introspector.EXPECT().GetColumns("public", "test").Return([]pgsql8.ColumnEntry{ + pgsql8.ColumnEntry{ Name: "col1", AttrType: "bigint", Nullable: false, Position: 1, }, - live.ColumnEntry{ + pgsql8.ColumnEntry{ Name: "col2", AttrType: "bigint", Nullable: false, Position: 2, }, - live.ColumnEntry{ + pgsql8.ColumnEntry{ Name: "col3", AttrType: "character varying(20)", Nullable: false, Position: 3, }, - live.ColumnEntry{ + pgsql8.ColumnEntry{ Name: "col4", AttrType: "character varying(20)", Nullable: true, @@ -199,8 +198,8 @@ func TestOperations_ExtractSchema_CompoundUniqueConstraint(t *testing.T) { }, }, nil) - introspector.EXPECT().GetConstraints().Return([]live.ConstraintEntry{ - live.ConstraintEntry{ + introspector.EXPECT().GetConstraints().Return([]pgsql8.ConstraintEntry{ + pgsql8.ConstraintEntry{ Schema: "public", Table: "test", Name: "test_constraint", @@ -224,23 +223,23 @@ func TestOperations_ExtractSchema_CompoundUniqueConstraint(t *testing.T) { func TestOperations_ExtractSchema_TableComments(t *testing.T) { ctrl := gomock.NewController(t) - introspector := live.NewMockIntrospector(ctrl) + introspector := pgsql8.NewMockIntrospector(ctrl) schemaDesc := "A description of the public schema" tableDesc := "A description of the test table" colDesc := "A description of col1 on the test table" introspector.EXPECT().GetSchemaOwner(gomock.Any()).AnyTimes() - introspector.EXPECT().GetTableList().Return([]live.TableEntry{ - live.TableEntry{ + introspector.EXPECT().GetTableList().Return([]pgsql8.TableEntry{ + pgsql8.TableEntry{ Schema: "public", SchemaDescription: schemaDesc, Table: "test", TableDescription: tableDesc, }, }, nil) - introspector.EXPECT().GetColumns(gomock.Any(), gomock.Any()).Return([]live.ColumnEntry{ - live.ColumnEntry{ + introspector.EXPECT().GetColumns(gomock.Any(), gomock.Any()).Return([]pgsql8.ColumnEntry{ + pgsql8.ColumnEntry{ Name: "col1", AttrType: "text", Description: colDesc, @@ -249,7 +248,7 @@ func TestOperations_ExtractSchema_TableComments(t *testing.T) { introspector.EXPECT().GetTableStorageOptions(gomock.Any(), gomock.Any()).AnyTimes() introspector.EXPECT().GetSequenceRelList(gomock.Any(), gomock.Any()).AnyTimes() introspector.EXPECT().GetIndexes(gomock.Any(), gomock.Any()).AnyTimes() - introspector.EXPECT().GetConstraints().Return([]live.ConstraintEntry{ + introspector.EXPECT().GetConstraints().Return([]pgsql8.ConstraintEntry{ {Schema: "public", Table: "test", Name: "test_col1_pkey", Type: "p", Columns: []string{"col1"}}, }, nil) introspector.EXPECT().GetForeignKeys().AnyTimes() @@ -268,7 +267,7 @@ func TestOperations_ExtractSchema_TableComments(t *testing.T) { func TestOperations_ExtractSchema_FunctionAmpersands(t *testing.T) { ctrl := gomock.NewController(t) - introspector := live.NewMockIntrospector(ctrl) + introspector := pgsql8.NewMockIntrospector(ctrl) body := strings.TrimSpace(` DECLARE @@ -287,9 +286,9 @@ END; introspector.EXPECT().GetIndexes(gomock.Any(), gomock.Any()).AnyTimes() introspector.EXPECT().GetConstraints().AnyTimes() introspector.EXPECT().GetForeignKeys().AnyTimes() - introspector.EXPECT().GetFunctions().Return([]live.FunctionEntry{ - live.FunctionEntry{ - Oid: live.Oid{1}, + introspector.EXPECT().GetFunctions().Return([]pgsql8.FunctionEntry{ + pgsql8.FunctionEntry{ + Oid: pgsql8.Oid{1}, Schema: "public", Name: "rates_overlap", Return: "boolean", @@ -300,7 +299,7 @@ END; Source: body, }, }, nil) - introspector.EXPECT().GetFunctionArgs(live.Oid{1}).Return([]live.FunctionArgEntry{ + introspector.EXPECT().GetFunctionArgs(pgsql8.Oid{1}).Return([]pgsql8.FunctionArgEntry{ {"rates_a", "money"}, {"rates_b", "money"}, }, nil) @@ -329,7 +328,7 @@ END; func TestOperations_ExtractSchema_FunctionArgs(t *testing.T) { ctrl := gomock.NewController(t) - introspector := live.NewMockIntrospector(ctrl) + introspector := pgsql8.NewMockIntrospector(ctrl) body := `BEGIN RETURN 1; END;` @@ -341,9 +340,9 @@ func TestOperations_ExtractSchema_FunctionArgs(t *testing.T) { introspector.EXPECT().GetIndexes(gomock.Any(), gomock.Any()).AnyTimes() introspector.EXPECT().GetConstraints().AnyTimes() introspector.EXPECT().GetForeignKeys().AnyTimes() - introspector.EXPECT().GetFunctions().Return([]live.FunctionEntry{ - live.FunctionEntry{ - Oid: live.Oid{1}, + introspector.EXPECT().GetFunctions().Return([]pgsql8.FunctionEntry{ + pgsql8.FunctionEntry{ + Oid: pgsql8.Oid{1}, Schema: "public", Name: "increment1", Return: "integer", @@ -351,8 +350,8 @@ func TestOperations_ExtractSchema_FunctionArgs(t *testing.T) { Language: "plpgsql", Source: body, }, - live.FunctionEntry{ - Oid: live.Oid{2}, + pgsql8.FunctionEntry{ + Oid: pgsql8.Oid{2}, Schema: "public", Name: "increment2", Return: "integer", @@ -360,8 +359,8 @@ func TestOperations_ExtractSchema_FunctionArgs(t *testing.T) { Language: "plpgsql", Source: body, }, - live.FunctionEntry{ - Oid: live.Oid{3}, + pgsql8.FunctionEntry{ + Oid: pgsql8.Oid{3}, Schema: "public", Name: "increment3", Return: "integer", @@ -369,8 +368,8 @@ func TestOperations_ExtractSchema_FunctionArgs(t *testing.T) { Language: "plpgsql", Source: body, }, - live.FunctionEntry{ - Oid: live.Oid{4}, + pgsql8.FunctionEntry{ + Oid: pgsql8.Oid{4}, Schema: "public", Name: "increment4", Return: "integer", @@ -380,21 +379,21 @@ func TestOperations_ExtractSchema_FunctionArgs(t *testing.T) { }, }, nil) // array type and argument names - introspector.EXPECT().GetFunctionArgs(live.Oid{1}).Return([]live.FunctionArgEntry{ + introspector.EXPECT().GetFunctionArgs(pgsql8.Oid{1}).Return([]pgsql8.FunctionArgEntry{ {"arg1", "integer[]"}, {"arg2", "uuid[]"}, }, nil) // array type and no argument names - introspector.EXPECT().GetFunctionArgs(live.Oid{2}).Return([]live.FunctionArgEntry{ + introspector.EXPECT().GetFunctionArgs(pgsql8.Oid{2}).Return([]pgsql8.FunctionArgEntry{ {"", "integer[]"}, {"", "uuid[]"}, }, nil) // array type and mixed argument names - introspector.EXPECT().GetFunctionArgs(live.Oid{3}).Return([]live.FunctionArgEntry{ + introspector.EXPECT().GetFunctionArgs(pgsql8.Oid{3}).Return([]pgsql8.FunctionArgEntry{ {"arg1", "integer[]"}, {"", "uuid[]"}, }, nil) - introspector.EXPECT().GetFunctionArgs(live.Oid{4}).Return([]live.FunctionArgEntry{ + introspector.EXPECT().GetFunctionArgs(pgsql8.Oid{4}).Return([]pgsql8.FunctionArgEntry{ {"", "integer[]"}, {"arg1", "uuid[]"}, }, nil) @@ -427,13 +426,13 @@ func TestOperations_ExtractSchema_FunctionArgs(t *testing.T) { func TestOperations_ExtractSchema_TableArrayType(t *testing.T) { ctrl := gomock.NewController(t) - introspector := live.NewMockIntrospector(ctrl) + introspector := pgsql8.NewMockIntrospector(ctrl) introspector.EXPECT().GetSchemaOwner(gomock.Any()).AnyTimes() - introspector.EXPECT().GetTableList().Return([]live.TableEntry{ + introspector.EXPECT().GetTableList().Return([]pgsql8.TableEntry{ {Schema: "public", Table: "test"}, }, nil) - introspector.EXPECT().GetColumns("public", "test").Return([]live.ColumnEntry{ + introspector.EXPECT().GetColumns("public", "test").Return([]pgsql8.ColumnEntry{ {Name: "name", AttrType: "text[]"}, }, nil) introspector.EXPECT().GetTableStorageOptions(gomock.Any(), gomock.Any()).AnyTimes() @@ -454,7 +453,7 @@ func TestOperations_ExtractSchema_TableArrayType(t *testing.T) { func TestOperations_ExtractSchema_FKReferentialConstraints(t *testing.T) { ctrl := gomock.NewController(t) - introspector := live.NewMockIntrospector(ctrl) + introspector := pgsql8.NewMockIntrospector(ctrl) // CREATE TABLE dummy (foo int, bar varchar(32), PRIMARY KEY (foo, bar)); // CREATE TABLE test ( @@ -467,15 +466,15 @@ func TestOperations_ExtractSchema_FKReferentialConstraints(t *testing.T) { // ); introspector.EXPECT().GetSchemaOwner(gomock.Any()).AnyTimes() - introspector.EXPECT().GetTableList().Return([]live.TableEntry{ + introspector.EXPECT().GetTableList().Return([]pgsql8.TableEntry{ {Schema: "public", Table: "dummy"}, {Schema: "public", Table: "test"}, }, nil) - introspector.EXPECT().GetColumns("public", "dummy").Return([]live.ColumnEntry{ + introspector.EXPECT().GetColumns("public", "dummy").Return([]pgsql8.ColumnEntry{ {Name: "feux", AttrType: "integer"}, {Name: "barf", AttrType: "character varying(32)"}, }, nil) - introspector.EXPECT().GetColumns("public", "test").Return([]live.ColumnEntry{ + introspector.EXPECT().GetColumns("public", "test").Return([]pgsql8.ColumnEntry{ {Name: "id", AttrType: "integer"}, {Name: "foo", AttrType: "integer"}, {Name: "bar", AttrType: "character varying(32)"}, @@ -483,12 +482,12 @@ func TestOperations_ExtractSchema_FKReferentialConstraints(t *testing.T) { introspector.EXPECT().GetTableStorageOptions(gomock.Any(), gomock.Any()).AnyTimes() introspector.EXPECT().GetSequenceRelList(gomock.Any(), gomock.Any()).AnyTimes() introspector.EXPECT().GetIndexes(gomock.Any(), gomock.Any()).AnyTimes() - introspector.EXPECT().GetConstraints().Return([]live.ConstraintEntry{ + introspector.EXPECT().GetConstraints().Return([]pgsql8.ConstraintEntry{ {Schema: "public", Table: "dummy", Name: "dummy_pkey", Type: "p", Columns: []string{"foo", "bar"}}, {Schema: "public", Table: "test", Name: "test_pkey", Type: "p", Columns: []string{"id"}}, }, nil) - introspector.EXPECT().GetForeignKeys().Return([]live.ForeignKeyEntry{ - live.ForeignKeyEntry{ + introspector.EXPECT().GetForeignKeys().Return([]pgsql8.ForeignKeyEntry{ + pgsql8.ForeignKeyEntry{ ConstraintName: "test_foo_fkey", UpdateRule: "a", DeleteRule: "n", @@ -535,28 +534,28 @@ func TestOperations_ExtractSchema_Sequences(t *testing.T) { // the ones marked (b) test that sequences which are used as defaults in a column are extracted as a serial column instead ctrl := gomock.NewController(t) - introspector := live.NewMockIntrospector(ctrl) + introspector := pgsql8.NewMockIntrospector(ctrl) introspector.EXPECT().GetSchemaOwner(gomock.Any()).AnyTimes() - introspector.EXPECT().GetTableList().Return([]live.TableEntry{ + introspector.EXPECT().GetTableList().Return([]pgsql8.TableEntry{ {Schema: "public", Table: "user"}, }, nil) - introspector.EXPECT().GetColumns("public", "user").Return([]live.ColumnEntry{ + introspector.EXPECT().GetColumns("public", "user").Return([]pgsql8.ColumnEntry{ {Name: "user_id", AttrType: "integer", Default: "nextval('test_seq')"}, {Name: "user_name", AttrType: "varchar(100)"}, }, nil) introspector.EXPECT().GetTableStorageOptions(gomock.Any(), gomock.Any()).AnyTimes() - introspector.EXPECT().GetSequenceRelList("public", []string{"test_seq"}).Return([]live.SequenceRelEntry{ + introspector.EXPECT().GetSequenceRelList("public", []string{"test_seq"}).Return([]pgsql8.SequenceRelEntry{ {Name: "blah", Owner: "owner"}, }, nil) - introspector.EXPECT().GetSequencesForRel("public", "test_seq").Return([]live.SequenceEntry{ + introspector.EXPECT().GetSequencesForRel("public", "test_seq").Return([]pgsql8.SequenceEntry{ {Start: sql.NullInt64{1, true}, Increment: sql.NullInt64{1, true}, Cache: sql.NullInt64{1, true}, Max: sql.NullInt64{15, true}}, }, nil) - introspector.EXPECT().GetSequencesForRel("public", "blah").Return([]live.SequenceEntry{ + introspector.EXPECT().GetSequencesForRel("public", "blah").Return([]pgsql8.SequenceEntry{ {Cache: sql.NullInt64{5, true}, Min: sql.NullInt64{3, true}, Max: sql.NullInt64{10, true}}, }, nil) introspector.EXPECT().GetIndexes(gomock.Any(), gomock.Any()).AnyTimes() - introspector.EXPECT().GetConstraints().Return([]live.ConstraintEntry{ + introspector.EXPECT().GetConstraints().Return([]pgsql8.ConstraintEntry{ {Schema: "public", Table: "user", Name: "user_pkey", Type: "p", Columns: []string{"user_id"}}, }, nil) introspector.EXPECT().GetForeignKeys().AnyTimes() @@ -587,7 +586,7 @@ func TestOperations_ExtractSchema_Sequences(t *testing.T) { }, schema.Sequences) } -func commonExtract(introspector *live.MockIntrospector, version live.VersionNum) *ir.Schema { +func commonExtract(introspector *pgsql8.MockIntrospector, version pgsql8.VersionNum) *ir.Schema { ops := pgsql8.GlobalOperations origCF := ops.ConnectionFactory origIF := ops.IntrospectorFactory @@ -596,10 +595,10 @@ func commonExtract(introspector *live.MockIntrospector, version live.VersionNum) ops.IntrospectorFactory = origIF }() - ops.ConnectionFactory = &live.ConstantConnectionFactory{ - Connection: &live.NullConnection{}, + ops.ConnectionFactory = &pgsql8.ConstantConnectionFactory{ + Connection: &pgsql8.NullConnection{}, } - ops.IntrospectorFactory = &live.ConstantIntrospectorFactory{ + ops.IntrospectorFactory = &pgsql8.ConstantIntrospectorFactory{ Introspector: introspector, } introspector.EXPECT().GetServerVersion().Return(version, nil) diff --git a/lib/output/output_file_segmenter_mock.go b/lib/output/output_file_segmenter_mock.go index 1315ab7..72cfb0b 100644 --- a/lib/output/output_file_segmenter_mock.go +++ b/lib/output/output_file_segmenter_mock.go @@ -5,34 +5,35 @@ package output import ( - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) -// MockOutputFileSegmenter is a mock of OutputFileSegmenter interface +// MockOutputFileSegmenter is a mock of OutputFileSegmenter interface. type MockOutputFileSegmenter struct { ctrl *gomock.Controller recorder *MockOutputFileSegmenterMockRecorder } -// MockOutputFileSegmenterMockRecorder is the mock recorder for MockOutputFileSegmenter +// MockOutputFileSegmenterMockRecorder is the mock recorder for MockOutputFileSegmenter. type MockOutputFileSegmenterMockRecorder struct { mock *MockOutputFileSegmenter } -// NewMockOutputFileSegmenter creates a new mock instance +// NewMockOutputFileSegmenter creates a new mock instance. func NewMockOutputFileSegmenter(ctrl *gomock.Controller) *MockOutputFileSegmenter { mock := &MockOutputFileSegmenter{ctrl: ctrl} mock.recorder = &MockOutputFileSegmenterMockRecorder{mock} return mock } -// EXPECT returns an object that allows the caller to indicate expected use +// EXPECT returns an object that allows the caller to indicate expected use. func (m *MockOutputFileSegmenter) EXPECT() *MockOutputFileSegmenterMockRecorder { return m.recorder } -// AppendFooter mocks base method +// AppendFooter mocks base method. func (m *MockOutputFileSegmenter) AppendFooter(arg0 string, arg1 ...interface{}) { m.ctrl.T.Helper() varargs := []interface{}{arg0} @@ -42,14 +43,14 @@ func (m *MockOutputFileSegmenter) AppendFooter(arg0 string, arg1 ...interface{}) m.ctrl.Call(m, "AppendFooter", varargs...) } -// AppendFooter indicates an expected call of AppendFooter +// AppendFooter indicates an expected call of AppendFooter. func (mr *MockOutputFileSegmenterMockRecorder) AppendFooter(arg0 interface{}, arg1 ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() varargs := append([]interface{}{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AppendFooter", reflect.TypeOf((*MockOutputFileSegmenter)(nil).AppendFooter), varargs...) } -// AppendHeader mocks base method +// AppendHeader mocks base method. func (m *MockOutputFileSegmenter) AppendHeader(arg0 string, arg1 ...interface{}) { m.ctrl.T.Helper() varargs := []interface{}{arg0} @@ -59,26 +60,26 @@ func (m *MockOutputFileSegmenter) AppendHeader(arg0 string, arg1 ...interface{}) m.ctrl.Call(m, "AppendHeader", varargs...) } -// AppendHeader indicates an expected call of AppendHeader +// AppendHeader indicates an expected call of AppendHeader. func (mr *MockOutputFileSegmenterMockRecorder) AppendHeader(arg0 interface{}, arg1 ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() varargs := append([]interface{}{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AppendHeader", reflect.TypeOf((*MockOutputFileSegmenter)(nil).AppendHeader), varargs...) } -// Close mocks base method +// Close mocks base method. func (m *MockOutputFileSegmenter) Close() { m.ctrl.T.Helper() m.ctrl.Call(m, "Close") } -// Close indicates an expected call of Close +// Close indicates an expected call of Close. func (mr *MockOutputFileSegmenterMockRecorder) Close() *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockOutputFileSegmenter)(nil).Close)) } -// SetHeader mocks base method +// SetHeader mocks base method. func (m *MockOutputFileSegmenter) SetHeader(arg0 string, arg1 ...interface{}) { m.ctrl.T.Helper() varargs := []interface{}{arg0} @@ -88,14 +89,14 @@ func (m *MockOutputFileSegmenter) SetHeader(arg0 string, arg1 ...interface{}) { m.ctrl.Call(m, "SetHeader", varargs...) } -// SetHeader indicates an expected call of SetHeader +// SetHeader indicates an expected call of SetHeader. func (mr *MockOutputFileSegmenterMockRecorder) SetHeader(arg0 interface{}, arg1 ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() varargs := append([]interface{}{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetHeader", reflect.TypeOf((*MockOutputFileSegmenter)(nil).SetHeader), varargs...) } -// Write mocks base method +// Write mocks base method. func (m *MockOutputFileSegmenter) Write(arg0 string, arg1 ...interface{}) { m.ctrl.T.Helper() varargs := []interface{}{arg0} @@ -105,14 +106,14 @@ func (m *MockOutputFileSegmenter) Write(arg0 string, arg1 ...interface{}) { m.ctrl.Call(m, "Write", varargs...) } -// Write indicates an expected call of Write +// Write indicates an expected call of Write. func (mr *MockOutputFileSegmenterMockRecorder) Write(arg0 interface{}, arg1 ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() varargs := append([]interface{}{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Write", reflect.TypeOf((*MockOutputFileSegmenter)(nil).Write), varargs...) } -// WriteSql mocks base method +// WriteSql mocks base method. func (m *MockOutputFileSegmenter) WriteSql(arg0 ...ToSql) { m.ctrl.T.Helper() varargs := []interface{}{} @@ -122,7 +123,7 @@ func (m *MockOutputFileSegmenter) WriteSql(arg0 ...ToSql) { m.ctrl.Call(m, "WriteSql", varargs...) } -// WriteSql indicates an expected call of WriteSql +// WriteSql indicates an expected call of WriteSql. func (mr *MockOutputFileSegmenterMockRecorder) WriteSql(arg0 ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WriteSql", reflect.TypeOf((*MockOutputFileSegmenter)(nil).WriteSql), arg0...) diff --git a/run b/run old mode 100644 new mode 100755