From 8bba71b5eaad1a98c2475419e81b7836460e4171 Mon Sep 17 00:00:00 2001 From: Erik Pettis Date: Tue, 19 Dec 2017 13:27:51 -0500 Subject: [PATCH 1/3] Expose COLUMN_TYPE column for MySQL resolves #86 In MySQL, the DATA_TYPE column contains only the basic type of the column. The COLUMN_TYPE column provides a more detailed explanation of the column's type, including "unsigned" for numeric types. --- database/drivers/mysql/parse.go | 1 + database/info.go | 1 + run/convert.go | 1 + run/data/data.go | 1 + run/preview.go | 2 +- run/preview_test.go | 48 +++++++++++++++++++++++---------- site/content/templates/data.md | 1 + 7 files changed, 40 insertions(+), 15 deletions(-) diff --git a/database/drivers/mysql/parse.go b/database/drivers/mysql/parse.go index f566c2a..673d2a8 100644 --- a/database/drivers/mysql/parse.go +++ b/database/drivers/mysql/parse.go @@ -207,6 +207,7 @@ func toDBColumn(c *columns.Row, log *log.Logger) (*database.Column, *database.En Nullable: c.IsNullable == "YES", HasDefault: c.ColumnDefault.String != "", Type: c.DataType, + ColumnType: c.ColumnType, Orig: *c, IsPrimaryKey: strings.Contains(c.ColumnKey, "PRI"), } diff --git a/database/info.go b/database/info.go index 21bf0e2..9a6bf04 100644 --- a/database/info.go +++ b/database/info.go @@ -64,6 +64,7 @@ type ForeignKey struct { type Column struct { Name string // the original name of the column in the DB Type string // the original type of the column in the DB + ColumnType string // [mysql] a detailed description of the type of the column in the DB IsArray bool // true if the column type is an array Length int // non-zero if the type has a length (e.g. varchar[16]) UserDefined bool // true if the type is user-defined diff --git a/run/convert.go b/run/convert.go index 3a51a4e..5657f9d 100644 --- a/run/convert.go +++ b/run/convert.go @@ -79,6 +79,7 @@ func makeData(log *log.Logger, info *database.Info, cfg *Config) (*data.DBData, Table: table, DBName: c.Name, DBType: c.Type, + ColumnType: c.ColumnType, IsArray: c.IsArray, Length: c.Length, UserDefined: c.UserDefined, diff --git a/run/data/data.go b/run/data/data.go index 195f1a1..625e19b 100644 --- a/run/data/data.go +++ b/run/data/data.go @@ -84,6 +84,7 @@ type Column struct { DBName string // the original name of the column in the DB Type string // the converted name of the type DBType string // the original type of the column in the DB + ColumnType string // [mysql] a detail description of the type of the column in the DB IsArray bool // true if the column type is an array Length int // non-zero if the type has a length (e.g. varchar[16]) UserDefined bool // true if the type is user-defined diff --git a/run/preview.go b/run/preview.go index 764d446..a9d9019 100644 --- a/run/preview.go +++ b/run/preview.go @@ -28,7 +28,7 @@ Enum: {{.Name}}({{$schema}}.{{.DBName}}) {{end -}} {{range .Tables}} Table: {{.Name}}({{$schema}}.{{.DBName}}) -{{makeTable .Columns "{{.Name}}|{{.DBName}}|{{.Type}}|{{.DBType}}|{{.IsArray}}|{{.IsPrimaryKey}}|{{.IsFK}}|{{.HasFKRef}}|{{.Length}}|{{.UserDefined}}|{{.Nullable}}|{{.HasDefault}}" "Name" "DBName" "Type" "DBType" "IsArray" "IsPrimaryKey" "IsFK" "HasFKRef" "Length" "UserDefined" "Nullable" "HasDefault" -}} +{{makeTable .Columns "{{.Name}}|{{.DBName}}|{{.Type}}|{{.DBType}}|{{.ColumnType}}|{{.IsArray}}|{{.IsPrimaryKey}}|{{.IsFK}}|{{.HasFKRef}}|{{.Length}}|{{.UserDefined}}|{{.Nullable}}|{{.HasDefault}}" "Name" "DBName" "Type" "DBType" "ColumnType" "IsArray" "IsPrimaryKey" "IsFK" "HasFKRef" "Length" "UserDefined" "Nullable" "HasDefault" -}} Indexes: {{makeTable .Indexes "{{.Name}}|{{.DBName}}|{{join .Columns.Names \", \"}}" "Name" "DBName" "Columns"}} {{end -}} diff --git a/run/preview_test.go b/run/preview_test.go index 9a33122..04395ae 100644 --- a/run/preview_test.go +++ b/run/preview_test.go @@ -55,6 +55,7 @@ func (dummyDriver) Parse(log *log.Logger, conn string, schemaNames []string, fil Columns: []*database.Column{{ Name: "col1", Type: "int", + ColumnType: "int(10)", IsPrimaryKey: true, }, { Name: "col2", @@ -73,6 +74,7 @@ func (dummyDriver) Parse(log *log.Logger, conn string, schemaNames []string, fil Columns: []*database.Column{{ Name: "col1", Type: "int", + ColumnType: "int(10)", IsPrimaryKey: true, }}, }}, @@ -117,6 +119,7 @@ const expectYaml = `schemas: dbname: col1 type: INTEGER dbtype: int + columntype: int(10) isarray: false length: 0 userdefined: false @@ -134,6 +137,7 @@ const expectYaml = `schemas: dbname: col2 type: '*INTEGER' dbtype: '*int' + columntype: "" isarray: false length: 0 userdefined: false @@ -148,6 +152,7 @@ const expectYaml = `schemas: dbname: col3 type: "" dbtype: string + columntype: "" isarray: false length: 0 userdefined: false @@ -162,6 +167,7 @@ const expectYaml = `schemas: dbname: col4 type: "" dbtype: '*string' + columntype: "" isarray: false length: 0 userdefined: false @@ -177,6 +183,7 @@ const expectYaml = `schemas: dbname: col1 type: INTEGER dbtype: int + columntype: int(10) isarray: false length: 0 userdefined: false @@ -198,6 +205,7 @@ const expectYaml = `schemas: dbname: col1 type: INTEGER dbtype: int + columntype: int(10) isarray: false length: 0 userdefined: false @@ -228,6 +236,7 @@ const expectYaml = `schemas: dbname: col1 type: INTEGER dbtype: int + columntype: "" isarray: false length: 0 userdefined: false @@ -242,6 +251,7 @@ const expectYaml = `schemas: dbname: col2 type: INTEGER dbtype: int + columntype: "" isarray: false length: 0 userdefined: false @@ -260,6 +270,7 @@ const expectYaml = `schemas: dbname: col1 type: INTEGER dbtype: int + columntype: "" isarray: false length: 0 userdefined: false @@ -301,14 +312,14 @@ Enum: abc enum(schema.enum) Table: abc table(schema.table) -+----------+--------+----------+---------+---------+--------------+-------+----------+--------+-------------+----------+------------+ -| Name | DBName | Type | DBType | IsArray | IsPrimaryKey | IsFK | HasFKRef | Length | UserDefined | Nullable | HasDefault | -+----------+--------+----------+---------+---------+--------------+-------+----------+--------+-------------+----------+------------+ -| abc col1 | col1 | INTEGER | int | false | true | false | true | 0 | false | false | false | -| abc col2 | col2 | *INTEGER | *int | false | false | false | false | 0 | false | true | false | -| abc col3 | col3 | | string | false | false | false | false | 0 | false | false | false | -| abc col4 | col4 | | *string | false | false | false | false | 0 | false | true | false | -+----------+--------+----------+---------+---------+--------------+-------+----------+--------+-------------+----------+------------+ ++----------+--------+----------+---------+------------+---------+--------------+-------+----------+--------+-------------+----------+------------+ +| Name | DBName | Type | DBType | ColumnType | IsArray | IsPrimaryKey | IsFK | HasFKRef | Length | UserDefined | Nullable | HasDefault | ++----------+--------+----------+---------+------------+---------+--------------+-------+----------+--------+-------------+----------+------------+ +| abc col1 | col1 | INTEGER | int | int(10) | false | true | false | true | 0 | false | false | false | +| abc col2 | col2 | *INTEGER | *int | | false | false | false | false | 0 | false | true | false | +| abc col3 | col3 | | string | | false | false | false | false | 0 | false | false | false | +| abc col4 | col4 | | *string | | false | false | false | false | 0 | false | true | false | ++----------+--------+----------+---------+------------+---------+--------------+-------+----------+--------+-------------+----------+------------+ Indexes: +---------------+-----------+----------+ | Name | DBName | Columns | @@ -318,12 +329,12 @@ Indexes: Table: abc tb2(schema.tb2) -+----------+--------+---------+--------+---------+--------------+-------+----------+--------+-------------+----------+------------+ -| Name | DBName | Type | DBType | IsArray | IsPrimaryKey | IsFK | HasFKRef | Length | UserDefined | Nullable | HasDefault | -+----------+--------+---------+--------+---------+--------------+-------+----------+--------+-------------+----------+------------+ -| abc col1 | col1 | INTEGER | int | false | true | false | false | 0 | false | false | false | -| abc col2 | col2 | INTEGER | int | false | false | true | false | 0 | false | false | false | -+----------+--------+---------+--------+---------+--------------+-------+----------+--------+-------------+----------+------------+ ++----------+--------+---------+--------+------------+---------+--------------+-------+----------+--------+-------------+----------+------------+ +| Name | DBName | Type | DBType | ColumnType | IsArray | IsPrimaryKey | IsFK | HasFKRef | Length | UserDefined | Nullable | HasDefault | ++----------+--------+---------+--------+------------+---------+--------------+-------+----------+--------+-------------+----------+------------+ +| abc col1 | col1 | INTEGER | int | | false | true | false | false | 0 | false | false | false | +| abc col2 | col2 | INTEGER | int | | false | false | true | false | 0 | false | false | false | ++----------+--------+---------+--------+------------+---------+--------------+-------+----------+--------+-------------+----------+------------+ Indexes: +------+--------+---------+ | Name | DBName | Columns | @@ -378,6 +389,7 @@ var expectJSON = ` "DBName": "col1", "Type": "INTEGER", "DBType": "int", + "ColumnType": "int(10)", "IsArray": false, "Length": 0, "UserDefined": false, @@ -400,6 +412,7 @@ var expectJSON = ` "DBName": "col2", "Type": "*INTEGER", "DBType": "*int", + "ColumnType": "", "IsArray": false, "Length": 0, "UserDefined": false, @@ -416,6 +429,7 @@ var expectJSON = ` "DBName": "col3", "Type": "", "DBType": "string", + "ColumnType": "", "IsArray": false, "Length": 0, "UserDefined": false, @@ -432,6 +446,7 @@ var expectJSON = ` "DBName": "col4", "Type": "", "DBType": "*string", + "ColumnType": "", "IsArray": false, "Length": 0, "UserDefined": false, @@ -450,6 +465,7 @@ var expectJSON = ` "DBName": "col1", "Type": "INTEGER", "DBType": "int", + "ColumnType": "int(10)", "IsArray": false, "Length": 0, "UserDefined": false, @@ -478,6 +494,7 @@ var expectJSON = ` "DBName": "col1", "Type": "INTEGER", "DBType": "int", + "ColumnType": "int(10)", "IsArray": false, "Length": 0, "UserDefined": false, @@ -524,6 +541,7 @@ var expectJSON = ` "DBName": "col1", "Type": "INTEGER", "DBType": "int", + "ColumnType": "", "IsArray": false, "Length": 0, "UserDefined": false, @@ -540,6 +558,7 @@ var expectJSON = ` "DBName": "col2", "Type": "INTEGER", "DBType": "int", + "ColumnType": "", "IsArray": false, "Length": 0, "UserDefined": false, @@ -562,6 +581,7 @@ var expectJSON = ` "DBName": "col1", "Type": "INTEGER", "DBType": "int", + "ColumnType": "", "IsArray": false, "Length": 0, "UserDefined": false, diff --git a/site/content/templates/data.md b/site/content/templates/data.md index eb19282..497f9b6 100644 --- a/site/content/templates/data.md +++ b/site/content/templates/data.md @@ -67,6 +67,7 @@ Column is the data about a DB column of a table. | DBName | string | the original name of the column in the DB | Type |string | the converted name of the type | DBType | string | the original type name of the column in the DB +| ColumnType | string | [mysql] a detailed description of the type of the column in the DB | IsArray | boolean | true if the column type is an array | Length | integer | non-zero if the type has a length (e.g. varchar[16]) | UserDefined | boolean | true if the type is user-defined From 3ea533126b07d3a883984953e24ec2fa1723510f Mon Sep 17 00:00:00 2001 From: Erik Pettis Date: Thu, 21 Dec 2017 12:04:36 -0500 Subject: [PATCH 2/3] Incorporate sign data into type field --- database/drivers/mysql/parse.go | 7 ++++- database/info.go | 1 - run/convert.go | 1 - run/data/data.go | 1 - run/preview.go | 2 +- run/preview_test.go | 48 ++++++++++----------------------- site/content/templates/data.md | 1 - 7 files changed, 21 insertions(+), 40 deletions(-) diff --git a/database/drivers/mysql/parse.go b/database/drivers/mysql/parse.go index d5cc6aa..991c3ce 100644 --- a/database/drivers/mysql/parse.go +++ b/database/drivers/mysql/parse.go @@ -221,7 +221,6 @@ func toDBColumn(c *columns.Row, log *log.Logger) (*database.Column, *database.En Nullable: c.IsNullable == "YES", HasDefault: c.ColumnDefault.String != "", Type: c.DataType, - ColumnType: c.ColumnType, Comment: c.ColumnComment, Orig: *c, IsPrimaryKey: strings.Contains(c.ColumnKey, "PRI"), @@ -234,6 +233,12 @@ func toDBColumn(c *columns.Row, log *log.Logger) (*database.Column, *database.En col.Length = int(c.CharacterMaximumLength.Int64) } + // MySQL ColumnType exposes sign information for numeric types. We want to + // reflect that the type. + if strings.Contains(c.ColumnType, "unsigned") { + col.Type += " unsigned" + } + if col.Type != "enum" { return col, nil, nil } diff --git a/database/info.go b/database/info.go index c6fbb26..edb6795 100644 --- a/database/info.go +++ b/database/info.go @@ -66,7 +66,6 @@ type ForeignKey struct { type Column struct { Name string // the original name of the column in the DB Type string // the original type of the column in the DB - ColumnType string // [mysql] a detailed description of the type of the column in the DB IsArray bool // true if the column type is an array Length int // non-zero if the type has a length (e.g. varchar[16]) UserDefined bool // true if the type is user-defined diff --git a/run/convert.go b/run/convert.go index 287a8c5..54e4e90 100644 --- a/run/convert.go +++ b/run/convert.go @@ -80,7 +80,6 @@ func makeData(log *log.Logger, info *database.Info, cfg *Config) (*data.DBData, Table: table, DBName: c.Name, DBType: c.Type, - ColumnType: c.ColumnType, IsArray: c.IsArray, Length: c.Length, UserDefined: c.UserDefined, diff --git a/run/data/data.go b/run/data/data.go index 44fc7a4..b246616 100644 --- a/run/data/data.go +++ b/run/data/data.go @@ -85,7 +85,6 @@ type Column struct { DBName string // the original name of the column in the DB Type string // the converted name of the type DBType string // the original type of the column in the DB - ColumnType string // [mysql] a detail description of the type of the column in the DB IsArray bool // true if the column type is an array Length int // non-zero if the type has a length (e.g. varchar[16]) UserDefined bool // true if the type is user-defined diff --git a/run/preview.go b/run/preview.go index 969c4c6..2b095b2 100644 --- a/run/preview.go +++ b/run/preview.go @@ -28,7 +28,7 @@ Enum: {{.Name}}({{$schema}}.{{.DBName}}) {{end -}} {{range .Tables}} Table: {{.Name}}({{$schema}}.{{.DBName}}) -{{makeTable .Columns "{{.Name}}|{{.DBName}}|{{.Type}}|{{.DBType}}|{{.ColumnType}}|{{.IsArray}}|{{.IsPrimaryKey}}|{{.IsFK}}|{{.HasFKRef}}|{{.Length}}|{{.UserDefined}}|{{.Nullable}}|{{.HasDefault}}|{{.Comment}}" "Name" "DBName" "Type" "DBType" "ColumnType" "IsArray" "IsPrimaryKey" "IsFK" "HasFKRef" "Length" "UserDefined" "Nullable" "HasDefault" "Comment" -}} +{{makeTable .Columns "{{.Name}}|{{.DBName}}|{{.Type}}|{{.DBType}}|{{.IsArray}}|{{.IsPrimaryKey}}|{{.IsFK}}|{{.HasFKRef}}|{{.Length}}|{{.UserDefined}}|{{.Nullable}}|{{.HasDefault}}|{{.Comment}}" "Name" "DBName" "Type" "DBType" "IsArray" "IsPrimaryKey" "IsFK" "HasFKRef" "Length" "UserDefined" "Nullable" "HasDefault" "Comment" -}} Indexes: {{makeTable .Indexes "{{.Name}}|{{.DBName}}|{{.IsUnique}}|{{join .Columns.Names \", \"}}" "Name" "DBName" "IsUnique" "Columns"}} {{end -}} diff --git a/run/preview_test.go b/run/preview_test.go index 1fa4838..680cc29 100644 --- a/run/preview_test.go +++ b/run/preview_test.go @@ -56,7 +56,6 @@ func (dummyDriver) Parse(log *log.Logger, conn string, schemaNames []string, fil Columns: []*database.Column{{ Name: "col1", Type: "int", - ColumnType: "int(10)", Comment: "first column", IsPrimaryKey: true, }, { @@ -77,7 +76,6 @@ func (dummyDriver) Parse(log *log.Logger, conn string, schemaNames []string, fil Columns: []*database.Column{{ Name: "col1", Type: "int", - ColumnType: "int(10)", Comment: "first column", IsPrimaryKey: true, }}, @@ -124,7 +122,6 @@ const expectYaml = `schemas: dbname: col1 type: INTEGER dbtype: int - columntype: int(10) isarray: false length: 0 userdefined: false @@ -143,7 +140,6 @@ const expectYaml = `schemas: dbname: col2 type: '*INTEGER' dbtype: '*int' - columntype: "" isarray: false length: 0 userdefined: false @@ -159,7 +155,6 @@ const expectYaml = `schemas: dbname: col3 type: "" dbtype: string - columntype: "" isarray: false length: 0 userdefined: false @@ -175,7 +170,6 @@ const expectYaml = `schemas: dbname: col4 type: "" dbtype: '*string' - columntype: "" isarray: false length: 0 userdefined: false @@ -192,7 +186,6 @@ const expectYaml = `schemas: dbname: col1 type: INTEGER dbtype: int - columntype: int(10) isarray: false length: 0 userdefined: false @@ -216,7 +209,6 @@ const expectYaml = `schemas: dbname: col1 type: INTEGER dbtype: int - columntype: int(10) isarray: false length: 0 userdefined: false @@ -249,7 +241,6 @@ const expectYaml = `schemas: dbname: col1 type: INTEGER dbtype: int - columntype: "" isarray: false length: 0 userdefined: false @@ -265,7 +256,6 @@ const expectYaml = `schemas: dbname: col2 type: INTEGER dbtype: int - columntype: "" isarray: false length: 0 userdefined: false @@ -285,7 +275,6 @@ const expectYaml = `schemas: dbname: col1 type: INTEGER dbtype: int - columntype: "" isarray: false length: 0 userdefined: false @@ -328,14 +317,14 @@ Enum: abc enum(schema.enum) Table: abc table(schema.table) -+----------+--------+----------+---------+------------+---------+--------------+-------+----------+--------+-------------+----------+------------+--------------+ -| Name | DBName | Type | DBType | ColumnType | IsArray | IsPrimaryKey | IsFK | HasFKRef | Length | UserDefined | Nullable | HasDefault | Comment | -+----------+--------+----------+---------+------------+---------+--------------+-------+----------+--------+-------------+----------+------------+--------------+ -| abc col1 | col1 | INTEGER | int | int(10) | false | true | false | true | 0 | false | false | false | first column | -| abc col2 | col2 | *INTEGER | *int | | false | false | false | false | 0 | false | true | false | | -| abc col3 | col3 | | string | | false | false | false | false | 0 | false | false | false | | -| abc col4 | col4 | | *string | | false | false | false | false | 0 | false | true | false | | -+----------+--------+----------+---------+------------+---------+--------------+-------+----------+--------+-------------+----------+------------+--------------+ ++----------+--------+----------+---------+---------+--------------+-------+----------+--------+-------------+----------+------------+--------------+ +| Name | DBName | Type | DBType | IsArray | IsPrimaryKey | IsFK | HasFKRef | Length | UserDefined | Nullable | HasDefault | Comment | ++----------+--------+----------+---------+---------+--------------+-------+----------+--------+-------------+----------+------------+--------------+ +| abc col1 | col1 | INTEGER | int | false | true | false | true | 0 | false | false | false | first column | +| abc col2 | col2 | *INTEGER | *int | false | false | false | false | 0 | false | true | false | | +| abc col3 | col3 | | string | false | false | false | false | 0 | false | false | false | | +| abc col4 | col4 | | *string | false | false | false | false | 0 | false | true | false | | ++----------+--------+----------+---------+---------+--------------+-------+----------+--------+-------------+----------+------------+--------------+ Indexes: +---------------+-----------+----------+----------+ | Name | DBName | IsUnique | Columns | @@ -345,12 +334,12 @@ Indexes: Table: abc tb2(schema.tb2) -+----------+--------+---------+--------+------------+---------+--------------+-------+----------+--------+-------------+----------+------------+---------+ -| Name | DBName | Type | DBType | ColumnType | IsArray | IsPrimaryKey | IsFK | HasFKRef | Length | UserDefined | Nullable | HasDefault | Comment | -+----------+--------+---------+--------+------------+---------+--------------+-------+----------+--------+-------------+----------+------------+---------+ -| abc col1 | col1 | INTEGER | int | | false | true | false | false | 0 | false | false | false | | -| abc col2 | col2 | INTEGER | int | | false | false | true | false | 0 | false | false | false | | -+----------+--------+---------+--------+------------+---------+--------------+-------+----------+--------+-------------+----------+------------+---------+ ++----------+--------+---------+--------+---------+--------------+-------+----------+--------+-------------+----------+------------+---------+ +| Name | DBName | Type | DBType | IsArray | IsPrimaryKey | IsFK | HasFKRef | Length | UserDefined | Nullable | HasDefault | Comment | ++----------+--------+---------+--------+---------+--------------+-------+----------+--------+-------------+----------+------------+---------+ +| abc col1 | col1 | INTEGER | int | false | true | false | false | 0 | false | false | false | | +| abc col2 | col2 | INTEGER | int | false | false | true | false | 0 | false | false | false | | ++----------+--------+---------+--------+---------+--------------+-------+----------+--------+-------------+----------+------------+---------+ Indexes: +------+--------+----------+---------+ | Name | DBName | IsUnique | Columns | @@ -406,7 +395,6 @@ var expectJSON = ` "DBName": "col1", "Type": "INTEGER", "DBType": "int", - "ColumnType": "int(10)", "IsArray": false, "Length": 0, "UserDefined": false, @@ -430,7 +418,6 @@ var expectJSON = ` "DBName": "col2", "Type": "*INTEGER", "DBType": "*int", - "ColumnType": "", "IsArray": false, "Length": 0, "UserDefined": false, @@ -448,7 +435,6 @@ var expectJSON = ` "DBName": "col3", "Type": "", "DBType": "string", - "ColumnType": "", "IsArray": false, "Length": 0, "UserDefined": false, @@ -466,7 +452,6 @@ var expectJSON = ` "DBName": "col4", "Type": "", "DBType": "*string", - "ColumnType": "", "IsArray": false, "Length": 0, "UserDefined": false, @@ -486,7 +471,6 @@ var expectJSON = ` "DBName": "col1", "Type": "INTEGER", "DBType": "int", - "ColumnType": "int(10)", "IsArray": false, "Length": 0, "UserDefined": false, @@ -517,7 +501,6 @@ var expectJSON = ` "DBName": "col1", "Type": "INTEGER", "DBType": "int", - "ColumnType": "int(10)", "IsArray": false, "Length": 0, "UserDefined": false, @@ -566,7 +549,6 @@ var expectJSON = ` "DBName": "col1", "Type": "INTEGER", "DBType": "int", - "ColumnType": "", "IsArray": false, "Length": 0, "UserDefined": false, @@ -584,7 +566,6 @@ var expectJSON = ` "DBName": "col2", "Type": "INTEGER", "DBType": "int", - "ColumnType": "", "IsArray": false, "Length": 0, "UserDefined": false, @@ -608,7 +589,6 @@ var expectJSON = ` "DBName": "col1", "Type": "INTEGER", "DBType": "int", - "ColumnType": "", "IsArray": false, "Length": 0, "UserDefined": false, diff --git a/site/content/templates/data.md b/site/content/templates/data.md index 8bdd94c..5d27aed 100644 --- a/site/content/templates/data.md +++ b/site/content/templates/data.md @@ -67,7 +67,6 @@ Column is the data about a DB column of a table. | DBName | string | the original name of the column in the DB | Type |string | the converted name of the type | DBType | string | the original type name of the column in the DB -| ColumnType | string | [mysql] a detailed description of the type of the column in the DB | IsArray | boolean | true if the column type is an array | Length | integer | non-zero if the type has a length (e.g. varchar[16]) | UserDefined | boolean | true if the type is user-defined From 60d6b92e9ebd010cf2342732fd10876fc2eaa0ba Mon Sep 17 00:00:00 2001 From: Erik Pettis Date: Thu, 21 Dec 2017 12:49:30 -0500 Subject: [PATCH 3/3] Return lost table comments in preview --- run/preview.go | 2 +- run/preview_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/run/preview.go b/run/preview.go index 2b095b2..eb02dd2 100644 --- a/run/preview.go +++ b/run/preview.go @@ -27,7 +27,7 @@ Enum: {{.Name}}({{$schema}}.{{.DBName}}) {{makeTable .Values "{{.Name}}|{{.DBName}}|{{.Value}}" "Name" "DBName" "Value" }} {{end -}} {{range .Tables}} -Table: {{.Name}}({{$schema}}.{{.DBName}}) +Table: {{.Name}}({{$schema}}.{{.DBName}}){{if ne .Comment ""}}; {{.Comment}}{{end}} {{makeTable .Columns "{{.Name}}|{{.DBName}}|{{.Type}}|{{.DBType}}|{{.IsArray}}|{{.IsPrimaryKey}}|{{.IsFK}}|{{.HasFKRef}}|{{.Length}}|{{.UserDefined}}|{{.Nullable}}|{{.HasDefault}}|{{.Comment}}" "Name" "DBName" "Type" "DBType" "IsArray" "IsPrimaryKey" "IsFK" "HasFKRef" "Length" "UserDefined" "Nullable" "HasDefault" "Comment" -}} Indexes: {{makeTable .Indexes "{{.Name}}|{{.DBName}}|{{.IsUnique}}|{{join .Columns.Names \", \"}}" "Name" "DBName" "IsUnique" "Columns"}} diff --git a/run/preview_test.go b/run/preview_test.go index 680cc29..f5442b2 100644 --- a/run/preview_test.go +++ b/run/preview_test.go @@ -316,7 +316,7 @@ Enum: abc enum(schema.enum) +---------------+-----------+-------+ -Table: abc table(schema.table) +Table: abc table(schema.table); a table +----------+--------+----------+---------+---------+--------------+-------+----------+--------+-------------+----------+------------+--------------+ | Name | DBName | Type | DBType | IsArray | IsPrimaryKey | IsFK | HasFKRef | Length | UserDefined | Nullable | HasDefault | Comment | +----------+--------+----------+---------+---------+--------------+-------+----------+--------+-------------+----------+------------+--------------+