Skip to content

Commit

Permalink
Fix ALTER TYPE to update column types (#973)
Browse files Browse the repository at this point in the history
* fixed alter type to update column types

* tests for alter type with update table columns

* make for loop more readable
  • Loading branch information
timwmillard committed Apr 14, 2021
1 parent a29c34d commit 9aad696
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TYPE event AS enum ('START', 'STOP');

CREATE TABLE log_lines (
id BIGSERIAL PRIMARY KEY,
status "event" NOT NULL
);

ALTER TYPE event RENAME TO "new_event";

-- name: ListAuthors :many
SELECT * FROM log_lines;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "postgresql",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql"
}
]
}
11 changes: 11 additions & 0 deletions internal/sql/catalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,16 @@ func (c *Catalog) renameType(stmt *ast.RenameTypeStmt) error {

}

// Update all the table columns with the new type
for _, schema := range c.Schemas {
for _, table := range schema.Tables {
for _, column := range table.Columns {
if column.Type == *stmt.Type {
column.Type.Name = newName
}
}
}
}

return nil
}

0 comments on commit 9aad696

Please sign in to comment.