Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ID column enforcement #15

Merged
merged 4 commits into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
"strings"
)

// Deprecated: Fizz won't force you to have an ID field now.
var INT_ID_COL = Column{
Name: "id",
Primary: true,
ColType: "integer",
Options: Options{},
}

// Deprecated: Fizz won't force you to have an ID field now.
var UUID_ID_COL = Column{
Name: "id",
Primary: true,
Expand Down
12 changes: 0 additions & 12 deletions tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,6 @@ func (f fizzer) CreateTable(name string, opts map[string]interface{}, help plush
}
}

var foundPrimary bool
for _, c := range t.Columns {
if c.Primary {
foundPrimary = true
break
}
}

if !foundPrimary {
t.Columns = append([]Column{INT_ID_COL}, t.Columns...)
}

if enabled, exists := t.Options["timestamps"]; !exists || enabled == true {
t.Timestamps()
}
Expand Down
1 change: 1 addition & 0 deletions translators/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ PRIMARY KEY(` + "`id`" + `),

res, err := fizz.AString(`
create_table("users") {
t.Column("id", "integer", {"primary": true})
t.Column("first_name", "string", {})
t.Column("last_name", "string", {})
t.Column("email", "string", {"size":20})
Expand Down
1 change: 1 addition & 0 deletions translators/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (p *PostgreSQLSuite) Test_Postgres_CreateTable() {

res, _ := fizz.AString(`
create_table("users") {
t.Column("id", "integer", {"primary": true})
t.Column("first_name", "string", {})
t.Column("last_name", "string", {})
t.Column("email", "string", {"size":20})
Expand Down
16 changes: 12 additions & 4 deletions translators/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import (
"github.com/gobuffalo/fizz/translators"
)

var IntIDCol = fizz.Column{
Name: "id",
Primary: true,
ColType: "integer",
Options: fizz.Options{},
}

var _ fizz.Translator = (*translators.SQLite)(nil)
var schema = &fauxSchema{schema: map[string]*fizz.Table{}}
var sqt = &translators.SQLite{Schema: schema}
Expand Down Expand Up @@ -70,6 +77,7 @@ func (p *SQLiteSuite) Test_SQLite_CreateTable() {

res, _ := fizz.AString(`
create_table("users") {
t.Column("id", "integer", {"primary": true})
t.Column("first_name", "string", {})
t.Column("last_name", "string", {})
t.Column("email", "string", {"size":20})
Expand Down Expand Up @@ -150,7 +158,7 @@ DROP TABLE "_users_tmp";`
schema.schema["users"] = &fizz.Table{
Name: "users",
Columns: []fizz.Column{
fizz.INT_ID_COL,
IntIDCol,
fizz.CREATED_COL,
fizz.UPDATED_COL,
},
Expand Down Expand Up @@ -185,7 +193,7 @@ DROP TABLE "_users_tmp";`
schema.schema["users"] = &fizz.Table{
Name: "users",
Columns: []fizz.Column{
fizz.INT_ID_COL,
IntIDCol,
fizz.CREATED_COL,
fizz.UPDATED_COL,
},
Expand All @@ -209,7 +217,7 @@ DROP TABLE "_users_tmp";`
schema.schema["users"] = &fizz.Table{
Name: "users",
Columns: []fizz.Column{
fizz.INT_ID_COL,
IntIDCol,
fizz.CREATED_COL,
fizz.UPDATED_COL,
},
Expand Down Expand Up @@ -288,7 +296,7 @@ CREATE UNIQUE INDEX "new_ix" ON "users" (id, created_at);`
schema.schema["users"] = &fizz.Table{
Name: "users",
Columns: []fizz.Column{
fizz.INT_ID_COL,
IntIDCol,
fizz.CREATED_COL,
fizz.UPDATED_COL,
},
Expand Down