@@ -6,9 +6,10 @@ import "strconv"
66import "strings"
77import "database/sql"
88import "github.com/joncrlsn/pgutil"
9+ import "github.com/joncrlsn/misc"
910
1011// ==================================
11- // ColumnRows definition
12+ // ColumnRows definition (a sortable slice of string maps)
1213// ==================================
1314type ColumnRows []map [string ]string
1415
@@ -17,15 +18,13 @@ func (slice ColumnRows) Len() int {
1718}
1819
1920func (slice ColumnRows ) Less (i , j int ) bool {
20- //fmt.Printf("--Less %s:%s with %s:%s", slice[i]["table_name"], slice[i]["column_name"], slice[j]["table_name"], slice[j]["column_name"])
21- if slice [i ]["table_name" ] == slice [j ]["table_name" ] {
22- return slice [i ]["column_name" ] < slice [j ]["column_name" ]
21+ if slice [i ]["table_name" ] != slice [j ]["table_name" ] {
22+ return slice [i ]["table_name" ] < slice [j ]["table_name" ]
2323 }
24- return slice [i ]["table_name " ] < slice [j ]["table_name " ]
24+ return slice [i ]["column_name " ] < slice [j ]["column_name " ]
2525}
2626
2727func (slice ColumnRows ) Swap (i , j int ) {
28- fmt .Printf ("--Swapping %d/%s:%s with %d/%s:%s \n " , i , slice [i ]["table_name" ], slice [i ]["column_name" ], j , slice [j ]["table_name" ], slice [j ]["column_name" ])
2928 slice [i ], slice [j ] = slice [j ], slice [i ]
3029}
3130
@@ -63,17 +62,17 @@ func (c *ColumnSchema) NextRow() bool {
6362func (c * ColumnSchema ) Compare (obj interface {}) int {
6463 c2 , ok := obj .(* ColumnSchema )
6564 if ! ok {
66- fmt .Println ("Error!!!, change needs a ColumnSchema instance" , c2 )
65+ fmt .Println ("Error!!!, Compare needs a ColumnSchema instance" , c2 )
6766 }
6867
69- val := _compareString (c .get ("table_name" ), c2 .get ("table_name" ))
68+ val := misc . CompareStrings (c .get ("table_name" ), c2 .get ("table_name" ))
7069 if val != 0 {
7170 // Table name differed so return that value
7271 return val
7372 }
7473
7574 // Table name was the same so compare column name
76- val = _compareString (c .get ("column_name" ), c2 .get ("column_name" ))
75+ val = misc . CompareStrings (c .get ("column_name" ), c2 .get ("column_name" ))
7776 return val
7877}
7978
@@ -132,7 +131,7 @@ func (c *ColumnSchema) Change(obj interface{}) {
132131 }
133132 }
134133
135- // TODO: Code and test a column change from integer to bigint
134+ // Code and test a column change from integer to bigint
136135 if c .get ("data_type" ) != c2 .get ("data_type" ) {
137136 fmt .Printf ("-- WARNING: This type change may not work well: (%s to %s).\n " , c2 .get ("data_type" ), c .get ("data_type" ))
138137 if strings .HasPrefix (c .get ("data_type" ), "character" ) {
@@ -155,7 +154,7 @@ func (c *ColumnSchema) Change(obj interface{}) {
155154 fmt .Printf ("ALTER TABLE %s ALTER COLUMN %s SET DEFAULT %s;\n " , c .get ("table_name" ), c .get ("column_name" ), c .get ("column_default" ))
156155 }
157156
158- // TODO Detect not-null and nullable change
157+ // Detect not-null and nullable change
159158 if c .get ("is_nullable" ) != c2 .get ("is_nullable" ) {
160159 if c .get ("is_nullable" ) == "YES" {
161160 fmt .Printf ("ALTER TABLE %s ALTER COLUMN %s DROP NOT NULL;\n " , c .get ("table_name" ), c .get ("column_name" ))
0 commit comments