go-reform/reform

Primary key assigned to a wrong column

remy-sl opened this issue · 2 comments

Describe the bug
reform-db init assigns primary key to a wrong column

To Reproduce

  1. Given database schema
    CREATE TABLE `builds` (
      `i` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `id` varchar(32) NOT NULL,
      `name` text NOT NULL,
      PRIMARY KEY (`i`),
      UNIQUE KEY `id` (`id`)
    );
  2. Run reform-db -db-driver MySQL -db-source ... init /package/path
  3. Resulting model:
    type Builds struct {
    	I    int64  `reform:"i"`
    	ID   string `reform:"id,pk"`
    	Name string `reform:"name"`
    }

Expected behavior
Expected model is:

type Builds struct {
	I    int64  `reform:"i,pk"`
	ID   string `reform:"id"`
	Name string `reform:"name"`
}

Additional context
I don't know what happened here. I am new to go so I actually don't want to dig deeper in the source code but I assume primary key recognition relies on a column name being id rather than actual PRIMARY KEY constraint.

No, it should rely on PRIMARY KEY. Sounds like a bug.

It will be fixed tomorrow in 1.4.1