Error: Sqlite primary key syntax error
- Dominant language
- Go
- Stars
- 786
- Forks
- 61
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 2
Description
Packages:
`github.com/go-rel/rel@v0.41.0`
`github.com/go-rel/migration@v0.3.1`
`github.com/go-rel/sqlite3@v0.11.0`
`github.com/mattn/go-sqlite3@v1.14.19`
Example:
```go
schema.CreateTable("settings", func(t *rel.Table) {
t.String("id", rel.Required(true), rel.Limit(16))
t.String("key", rel.Required(true), rel.Limit(50))
t.String("value")
t.DateTime("created_at", rel.Required(true))
t.DateTime("updated_at", rel.Required(true))
t.PrimaryKey("id", rel.Name("pk_settings"))
t.Unique([]string{"key"}, rel.Name("uq_settings_key"))
})
```
Error:
```bash
Instrumentation: adapter-exec, INSERT INTO "rel_schema_versions" ("version","created_at","updated_at") VALUES (?,?,?);, [[202402011000 2024-02-01 02:23:55 +0100 CET 2024-02-01 02:23:55 +0100 CET]]
Instrumentation: adapter-exec, CREATE TABLE "settings" ("id" VARCHAR(16) NOT NULL, "key" VARCHAR(50) NOT NULL, "value" VARCHAR(255), "created_at" DATETIME NOT NULL, "updated_at" DATETIME NOT NULL, PRIMARY KEY "pk_settings" ("id"), UNIQUE "uq_settings_key" ("key"));, [[]]
Instrumentation: adapter-rollback, rollback transaction, [[]]
panic: near ""pk_settings"": syntax error
goroutine 56 [running]:
github.com/go-rel/migration.check({0x7ff7489cd3a0, 0xc000091830})
/go/pkg/mod/github.com/go-rel/migration@v0.3.1/migration.go:176 +0x5d
github.com/go-rel/migration.(*Migration).Migrate(0xc00005c140, {0x7ff7489d1b98, 0xc000437fb0})
/go/pkg/mod/github.com/go-rel/migration@v0.3.1/migration.go:127 +0x30e
```
The right syntax would be:
```sql
CREATE TABLE "settings" (
"id" VARCHAR(16) NOT NULL,
"key" VARCHAR(50) NOT NULL,
CONSTRAINT "pk_settings" PRIMARY KEY ("id"),
CONSTRAINT "uq_settings_key" UNIQUE ("key")
);
```
Contributor guide
Research direction
Start by tracing the CREATE TABLE SQL produced by schema.CreateTable and compare the named primary-key and unique-constraint syntax with SQLite's expected form. Inspect the migration.go failure location and the sqlite3 adapter, then add a regression test showing that a table with named constraints migrates successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sqlite
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100