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

support autoIncColumnChange #2240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

feitianbubu
Copy link

No description provided.

@a8m
Copy link
Member

a8m commented Oct 31, 2023

Thanks for the contribution, @feitianbubu.

The AUTO_INCREMENT clause is a table attribute (not a column attribute) and it’s already implemented here: https://github.com/ariga/atlas/blob/master/sql/mysql/diff.go#L394. Do you have any issues with it?

@feitianbubu
Copy link
Author

feitianbubu commented Nov 2, 2023

Thank you for your reply. @a8m
The autoIncChange func only effect where the autoincrement value is modified. However, when the user adds or removes the autoincrement attribute on a field, it does not take effect. The autoIncColumnChange I added will solves this issue.

example, when user change a AUTO_INCREMENT on id filed

`CREATE TABLE `account` (
  `id` bigint NOT NULL AUTO_INCREMENT,  // will not be change
  PRIMARY KEY (`id`)
) AUTO_INCREMENT=2;` //  will change by autoIncChange

@a8m
Copy link
Member

a8m commented Nov 2, 2023

Thanks for the response, @feitianbubu. Can you please describe the use case with "before" and "after" schemas? Do you try to add it to an existing column? Note that adding the AUTO_INCREMENT to a table without adding it to a column is ignored.

@feitianbubu
Copy link
Author

feitianbubu commented Nov 3, 2023

Thanks for the response, @a8m ,
This is a example:

  1. before hcl:
table "account" {
  schema = schema.test
  column "id" {
    null = false
    type = bigint
  }
  primary_key {
    columns = [column.id]
  }
}
  1. after hcl:
table "account" {
  schema = schema.test
  column "id" {
    null           = false
    type           = bigint
    auto_increment = true
  }
  primary_key {
    columns = [column.id]
  }
}
  1. current atlas schema diff result:
    Schemas are synced, no changes to be made.
  2. need result:
-- Modify "account" table
ALTER TABLE `account` MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT;

@feitianbubu
Copy link
Author

feitianbubu commented Nov 14, 2023

current atlas schema diff result:
Schemas are synced, no changes to be made.

commit pr will gen:

-- Modify "account" table
ALTER TABLE `account` MODIFY COLUMN `id` bigint NOT NULL AUTO_INCREMENT;

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

Successfully merging this pull request may close these issues.

2 participants