Skip to content

Commit

Permalink
Remove ID column enforcement (#15)
Browse files Browse the repository at this point in the history
* Remove ID column enforcement

Fixes first part of #5. When using the model generator in pop this enforcement
is already done:
https://github.com/gobuffalo/pop/blob/v4.6.3/soda/cmd/generate/model.go#L121

* Remove INT_ID_COL & UUID_ID_COL

* Fix translators tests
  • Loading branch information
stanislas-m authored Aug 20, 2018
1 parent f57f22e commit 2376bb6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
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

0 comments on commit 2376bb6

Please sign in to comment.