diff --git a/translators/sqlite.go b/translators/sqlite.go index 76a31af..8749c22 100644 --- a/translators/sqlite.go +++ b/translators/sqlite.go @@ -37,7 +37,7 @@ func (p *SQLite) CreateTable(t fizz.Table) (string, error) { for _, c := range t.Columns { if c.Primary { switch strings.ToLower(c.ColType) { - case "integer", "int": + case "integer", "int", "bigint": s = fmt.Sprintf("\"%s\" INTEGER PRIMARY KEY AUTOINCREMENT", c.Name) case "string", "text", "uuid": s = fmt.Sprintf("\"%s\" TEXT PRIMARY KEY", c.Name) @@ -400,7 +400,7 @@ func (p *SQLite) colType(c fizz.Column) string { return "NUMERIC" case "string", "text": return "TEXT" - case "int", "integer": + case "int", "integer", "bigint": return "INTEGER" case "float": // precision and scale not supported here diff --git a/translators/sqlite_test.go b/translators/sqlite_test.go index 6ac738b..667f269 100644 --- a/translators/sqlite_test.go +++ b/translators/sqlite_test.go @@ -145,6 +145,42 @@ PRIMARY KEY("user_id", "profile_id") r.Equal(ddl, res) } +func (p *SQLiteSuite) Test_SQLite_CreateTable_WithBigIntPrimaryKey() { + r := p.Require() + ddl := `CREATE TABLE "users" ( +"id" INTEGER PRIMARY KEY AUTOINCREMENT, +"first_name" TEXT NOT NULL, +"last_name" TEXT NOT NULL, +"email" TEXT NOT NULL, +"permissions" TEXT, +"age" INTEGER DEFAULT '40', +"raw" BLOB NOT NULL, +"into" INTEGER NOT NULL, +"flotante" REAL NOT NULL, +"json" TEXT NOT NULL, +"bytes" BLOB NOT NULL, +"created_at" DATETIME NOT NULL, +"updated_at" DATETIME NOT NULL +);` + + res, _ := fizz.AString(` + create_table("users") { + t.Column("id", "bigint", {"primary": true}) + t.Column("first_name", "string", {}) + t.Column("last_name", "string", {}) + t.Column("email", "string", {"size":20}) + t.Column("permissions", "text", {"null": true}) + t.Column("age", "integer", {"null": true, "default": 40}) + t.Column("raw", "blob", {}) + t.Column("into", "int", {}) + t.Column("flotante", "float", {}) + t.Column("json", "json", {}) + t.Column("bytes", "[]byte", {}) + } + `, sqt) + r.Equal(ddl, res) +} + func (p *SQLiteSuite) Test_SQLite_DropTable() { r := p.Require() @@ -208,6 +244,17 @@ func (p *SQLiteSuite) Test_SQLite_AddColumn() { r.Equal(ddl, res) } +func (p *SQLiteSuite) Test_SQLite_AddBigIntColumn() { + r := p.Require() + + ddl := `ALTER TABLE "users" ADD COLUMN "mycolumn" INTEGER NOT NULL;` + schema.schema["users"] = &fizz.Table{} + + res, _ := fizz.AString(`add_column("users", "mycolumn", "bigint")`, sqt) + + r.Equal(ddl, res) +} + func (p *SQLiteSuite) Test_SQLite_DropColumn() { r := p.Require() ddl := `CREATE TABLE "_users_tmp" (