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

mysql: do not use SERIAL alias in goose_db_version table creation #816

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

JuozasVainauskas
Copy link
Contributor

@JuozasVainauskas JuozasVainauskas commented Aug 27, 2024

We are using goose to run migrations on Vitess with MySQL setup. Unfortunately, Vitess does not support SERIAL keyword. Right now our work-around is to create goose_db_version table manually without using SERIAL keyword. We can solve this problem by NOT using SERIAL keyword and explicitly define the type of the column.

This change is backwards-compatible

As stated in the MySQL documentation:

SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE.

After table is created with SERIAL keyword, it automatically resolves to bigint(20) unsigned NOT NULL AUTO_INCREMENT:

mysql> create table mytable (id serial primary key);

mysql> show create table mytable\G
*************************** 1. row ***************************
       Table: mytable
Create Table: CREATE TABLE `mytable` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`) -- this one is superfluous
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

@JuozasVainauskas JuozasVainauskas marked this pull request as ready for review August 27, 2024 13:22
@mfridman
Copy link
Collaborator

I think this sounds reasonable, will try to get to it tonight. Why bigint(20) ?

@JuozasVainauskas
Copy link
Contributor Author

I think this sounds reasonable, will try to get to it tonight. Why bigint(20) ?

20 is a default display width (it has nothing to do with storage). It is equal to the number of characters in the largest negative BIGINT (-9223372036854775808). Official documentation: https://dev.mysql.com/doc/refman/8.4/en/numeric-type-attributes.html. I like to define it for a better readability of mysql table schemas.

Explanation: https://stackoverflow.com/questions/22014869/mysql-difference-between-bigint-and-bigint20

@mfridman mfridman merged commit 3802b0a into pressly:master Aug 27, 2024
4 checks passed
@JuozasVainauskas
Copy link
Contributor Author

JuozasVainauskas commented Sep 2, 2024

Hi, thank You for merging the PR. When are You planning to release this? @mfridman

@mfridman
Copy link
Collaborator

mfridman commented Sep 3, 2024

Can do a release within the next few days.

@mfridman
Copy link
Collaborator

mfridman commented Sep 3, 2024

Cut a release this morning

https://github.com/pressly/goose/releases/tag/v3.22.0

@JuozasVainauskas
Copy link
Contributor Author

Cut a release this morning

https://github.com/pressly/goose/releases/tag/v3.22.0

Thank You very much!

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