Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primary key assigned to a wrong column #237

Closed
remy-sl opened this issue Aug 6, 2020 · 2 comments · Fixed by #241
Closed

Primary key assigned to a wrong column #237

remy-sl opened this issue Aug 6, 2020 · 2 comments · Fixed by #241
Labels
Milestone

Comments

@remy-sl
Copy link

remy-sl commented Aug 6, 2020

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.

@AlekSi
Copy link
Member

AlekSi commented Aug 19, 2020

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

@AlekSi AlekSi added the bug label Aug 19, 2020
@AlekSi AlekSi added this to the v1.4.1 milestone Aug 19, 2020
@AlekSi
Copy link
Member

AlekSi commented Aug 30, 2020

It will be fixed tomorrow in 1.4.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants