Skip to content

Commit

Permalink
Add Table.Type to distinguish views from tables (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
freb committed Jan 23, 2020
1 parent 9aaed63 commit ccfd72b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions database/drivers/mysql/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func parse(log *log.Logger, conn string, schemaNames []string, filterTables func
}
schemas[t.TableSchema] = append(schemas[t.TableSchema], &database.Table{
Name: t.TableName,
Type: t.TableType,
Comment: t.TableComment,
})
}
Expand Down
1 change: 1 addition & 0 deletions database/drivers/postgres/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func parse(log *log.Logger, conn string, schemaNames []string, filterTables func

schemas[t.TableSchema.String] = append(schemas[t.TableSchema.String], &database.Table{
Name: t.TableName.String,
Type: t.TableType.String,
})
}

Expand Down
1 change: 1 addition & 0 deletions database/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type EnumValue struct {
// Table contains the definition of a database table.
type Table struct {
Name string // the original name of the table in the DB
Type string // the table type (e.g. VIEW or BASE TABLE)
Comment string // the comment attached to the table
Columns []*Column // ordered list of columns in this table
Indexes []*Index // list of indexes in this table
Expand Down
1 change: 1 addition & 0 deletions run/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func makeData(log *log.Logger, info *database.Info, cfg *Config) (*data.DBData,
for _, t := range s.Tables {
table := &data.Table{
DBName: t.Name,
Type: t.Type,
Comment: t.Comment,
Schema: sch,
ColumnsByName: make(map[string]*data.Column, len(t.Columns)),
Expand Down
1 change: 1 addition & 0 deletions run/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Schema struct {
type Table struct {
Name string // the converted name of the table
DBName string // the original name of the table in the DB
Type string // the table type (e.g. VIEW or BASE TABLE)
Comment string // the comment attached to the table
Schema *Schema `yaml:"-" json:"-"` // the schema this table is in
Columns Columns // Database columns
Expand Down
6 changes: 6 additions & 0 deletions run/preview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (dummyDriver) Parse(log *log.Logger, conn string, schemaNames []string, fil
Name: "schema",
Tables: []*database.Table{{
Name: "table",
Type: "BASE TABLE",
Comment: "a table",
Columns: []*database.Column{{
Name: "col1",
Expand Down Expand Up @@ -83,6 +84,7 @@ func (dummyDriver) Parse(log *log.Logger, conn string, schemaNames []string, fil
}},
}, {
Name: "tb2",
Type: "BASE TABLE",
Columns: []*database.Column{{
Name: "col1",
Type: "int",
Expand Down Expand Up @@ -117,6 +119,7 @@ const expectYaml = `schemas:
tables:
- name: abc table
dbname: table
type: BASE TABLE
comment: a table
columns:
- name: abc col1
Expand Down Expand Up @@ -242,6 +245,7 @@ const expectYaml = `schemas:
refcolumndbname: col1
- name: abc tb2
dbname: tb2
type: BASE TABLE
comment: ""
columns:
- name: abc col1
Expand Down Expand Up @@ -398,6 +402,7 @@ var expectJSON = `
{
"Name": "abc table",
"DBName": "table",
"Type": "BASE TABLE",
"Comment": "a table",
"Columns": [
{
Expand Down Expand Up @@ -558,6 +563,7 @@ var expectJSON = `
{
"Name": "abc tb2",
"DBName": "tb2",
"Type": "BASE TABLE",
"Comment": "",
"Columns": [
{
Expand Down

0 comments on commit ccfd72b

Please sign in to comment.