diff --git a/columns.go b/columns.go index e3c04f44..eb94dfd1 100644 --- a/columns.go +++ b/columns.go @@ -7,6 +7,7 @@ import ( "strings" ) +// Deprecated: Fizz won't force you to have an ID field now. var INT_ID_COL = Column{ Name: "id", Primary: true, @@ -14,6 +15,7 @@ var INT_ID_COL = Column{ Options: Options{}, } +// Deprecated: Fizz won't force you to have an ID field now. var UUID_ID_COL = Column{ Name: "id", Primary: true, diff --git a/tables.go b/tables.go index 1341f41c..7caf7995 100644 --- a/tables.go +++ b/tables.go @@ -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() } diff --git a/translators/mysql_test.go b/translators/mysql_test.go index 14d856ed..f20fd1b0 100644 --- a/translators/mysql_test.go +++ b/translators/mysql_test.go @@ -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}) diff --git a/translators/postgres_test.go b/translators/postgres_test.go index 299ec932..2bbb9a7c 100644 --- a/translators/postgres_test.go +++ b/translators/postgres_test.go @@ -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}) diff --git a/translators/sqlite_test.go b/translators/sqlite_test.go index fb791972..93120ce1 100644 --- a/translators/sqlite_test.go +++ b/translators/sqlite_test.go @@ -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} @@ -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}) @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, },