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

Can't add columns to a table with an AUTO_INCREMENT column that isn't primary key #2587

Closed
sergeycherepanov opened this issue Jan 8, 2022 · 6 comments
Assignees
Labels
bug Something isn't working sql Issue with SQL

Comments

@sergeycherepanov
Copy link

sergeycherepanov commented Jan 8, 2022

The following schema works fine in the mysql, but not in the dolt db.

CREATE TABLE `about` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `uuid` char(36) NOT NULL,
  `status` varchar(255) NOT NULL DEFAULT 'draft',
  `date_created` timestamp NULL DEFAULT NULL,
  `date_updated` timestamp NULL DEFAULT NULL,
  `url_key` varchar(255) NOT NULL,
  UNIQUE KEY `id` (`id`),
  UNIQUE KEY `about_url_key_unique` (`url_key`),
  PRIMARY KEY (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

I need the numeric id field in the table to support legacy code, but the primary key which we use is uuid.

@zachmu
Copy link
Member

zachmu commented Jan 14, 2022

I believe dolt currently requires that the auto increment column is a primary key column, but it shouldn't be that tricky to fix.

Is this blocking you getting dolt into production?

@sergeycherepanov
Copy link
Author

@zachmu no, I am not blocked

I just interested to use Dolt for a local development and generate the diff file to apply by migrations tool on production servers that runs mariadb/mysql.

@VinaiRachakonda VinaiRachakonda added 1hr and removed 1hr labels Mar 7, 2022
@fulghum
Copy link
Contributor

fulghum commented Mar 31, 2022

Closing this one as a duplicate of: #2981

@jcor11599 just started looking at #2981 today and will have updates on that issue as we make progress.

@fulghum fulghum closed this as completed Mar 31, 2022
@sergeycherepanov
Copy link
Author

Hi @fulghum, @zachmu,
Unfortunately the issue still exists, but appear only in case when I try to alter table

To reproduce it just run following query:

CREATE TABLE `about` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `uuid` char(36) NOT NULL,
  `status` varchar(255) NOT NULL DEFAULT 'draft',
  `date_created` timestamp NULL DEFAULT NULL,
  `date_updated` timestamp NULL DEFAULT NULL,
  `url_key` varchar(255) NOT NULL,
  UNIQUE KEY `id` (`id`),
  UNIQUE KEY `about_url_key_unique` (`url_key`),
  PRIMARY KEY (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

ALTER TABLE `about` ADD `background_color` varchar(255) DEFAULT NULL;

@fulghum
Copy link
Contributor

fulghum commented May 23, 2022

Thanks for reopening @sergeycherepanov. I was able to repro the error – it looks like there's a bug in the validation logic that won't let us add more columns to a table with non-pk auto_increment column.

@jcor11599 – Could you please take a look at this and see what's going on, since you recently looked at the fix for expanding usage of auto_increment columns?

@fulghum fulghum reopened this May 23, 2022
@fulghum fulghum added the bug Something isn't working label May 23, 2022
@timsehn timsehn changed the title There can be only one auto_increment column and it must be defined as a key Can Aug 30, 2022
@timsehn timsehn changed the title Can Can't add columns to a table with an AUTO_INCREMENT column that isn't primary key Aug 30, 2022
@timsehn timsehn added the sql Issue with SQL label Aug 30, 2022
@jycor
Copy link
Contributor

jycor commented Sep 29, 2022

Hey @sergeycherepanov, the fix for this should be in our latest release

@jycor jycor closed this as completed Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sql Issue with SQL
Projects
None yet
Development

No branches or pull requests

6 participants