Skip to content

ALTER TABLE MODIFY enum not respected #1503

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

Closed
ken2057 opened this issue Mar 22, 2022 · 0 comments · Fixed by #2680
Closed

ALTER TABLE MODIFY enum not respected #1503

ken2057 opened this issue Mar 22, 2022 · 0 comments · Fixed by #2680

Comments

@ken2057
Copy link

ken2057 commented Mar 22, 2022

Version

1.12.0

What happened?

When I modify a enum field with ALTER command, the generated models not added a new enum value, and it change the data type of field in struct as string instead of the "type ...Status string".

Relevant log output

No response

Database schema

CREATE TABLE authors (
  id   bigint primary key,
  status enum("ok", "init") default "init" not null
);

-- remove this alter to see the change in models.go
ALTER TABLE authors MODIFY status enum('init', 'done', 'canceled', 'processing', 'waiting') default "init" not null;

SQL queries

-- name: ListAuthors :many
select * from authors;

Configuration

No response

Playground URL

https://play.sqlc.dev/p/67134f04f43f5f6161fb11737e860c99c5db8a82b63d9f0a22e0f5707c500d57

What operating system are you using?

Linux

What database engines are you using?

MySQL

What type of code are you generating?

Go

@ken2057 ken2057 added bug Something isn't working triage New issues that hasn't been reviewed labels Mar 22, 2022
@kyleconroy kyleconroy removed the triage New issues that hasn't been reviewed label Aug 29, 2022
@kyleconroy kyleconroy changed the title Sqlc unable to update enum in models when using ALTER ALTER TABLE MODIFY enum not respected Sep 22, 2023
@andrewmbenton andrewmbenton added ddl and removed analyzer labels Oct 5, 2023
@kyleconroy kyleconroy added this to the 1.23.0 milestone Oct 13, 2023
kyleconroy pushed a commit that referenced this issue Oct 13, 2023
I got in a case similar to #1503. This PR will fix #1503.

I found one discrepancy between column definition between create table and alter definition. I fix it by defining a common sub function.

On generic engine update part, it was missing to create enum on alter table statement compared to create. I added an argument to the func createEnum to override previous definition when needed.

I added two tests to cover the two ALTER case MODIFY and CHANGE.

I only know very few part of the codebase so let me know If I need to change anything to make this merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants