Skip to content

Commit

Permalink
Use VARCHAR(14) for primary key
Browse files Browse the repository at this point in the history
Rollback the change. Using CHAR(14) is not recommended due to adding
padding.
  • Loading branch information
iamralch committed Jul 28, 2021
1 parent 1bda5df commit 720c82b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions sqlmigr/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func (m *Executor) Setup() error {
up := &bytes.Buffer{}

fmt.Fprintln(up, "CREATE TABLE IF NOT EXISTS migrations (")
fmt.Fprintln(up, " id CHAR(14) NOT NULL PRIMARY KEY,")
fmt.Fprintln(up, " description TEXT NOT NULL,")
fmt.Fprintln(up, " created_at TIMESTAMP NOT NULL")
fmt.Fprintln(up, " id VARCHAR(14) NOT NULL PRIMARY KEY,")
fmt.Fprintln(up, " description TEXT NOT NULL,")
fmt.Fprintln(up, " created_at TIMESTAMP NOT NULL")
fmt.Fprintln(up, ");")
fmt.Fprintln(up)

Expand Down
6 changes: 3 additions & 3 deletions sqlmigr/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ var _ = Describe("Executor", func() {

up := &bytes.Buffer{}
fmt.Fprintln(up, "CREATE TABLE IF NOT EXISTS migrations (")
fmt.Fprintln(up, " id CHAR(14) NOT NULL PRIMARY KEY,")
fmt.Fprintln(up, " description TEXT NOT NULL,")
fmt.Fprintln(up, " created_at TIMESTAMP NOT NULL")
fmt.Fprintln(up, " id VARCHAR(14) NOT NULL PRIMARY KEY,")
fmt.Fprintln(up, " description TEXT NOT NULL,")
fmt.Fprintln(up, " created_at TIMESTAMP NOT NULL")
fmt.Fprintln(up, ");")
fmt.Fprintln(up)
Expect(string(data)).To(Equal(up.String()))
Expand Down
5 changes: 3 additions & 2 deletions sqlmigr/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ func (g *Generator) write(filename string, data []byte, perm os.FileMode) error
}

if writer, ok := f.(io.Writer); ok {
n, err := writer.Write(data)
if err == nil && n < len(data) {
var n int

if n, err = writer.Write(data); err == nil && n < len(data) {
err = io.ErrShortWrite
}
}
Expand Down

0 comments on commit 720c82b

Please sign in to comment.