Closed iSerganov closed 1 year ago
Hey @iSerganov, thanks for raising this. Unfortunately, I was not able to reproduce this. I couldn't apply your given migration with the following error: Error 1294 (HY000): Invalid ON UPDATE clause for 'updated_at' column
. This is because CURRENT_TIMESTAMP
can only be used on TIMESTAMP
fields.
In addition, the key length issue is known from MySQL version 5.6 and before. It was raised to ~3000 bytes with MySQL 5.7 and later. So can you please check again, if you are indeed running version 5.7.12 and not something older?
Also, please note that MySQL 5.7 will reach EOL in the next month. If possible, please consider to update your database to be on the safe side. However, regardless of what you devide, I will be happy to assist with your above issue.
Hey @masseelch! Thank you for your fast reply!
Yeah, I am pretty sure that I have 5.7.12 version.
As well I am am sure that I can use CURRENT_TIMESTAMP
with both TIMESTAMP
and DATETIME
fields - see MySQL 5.7 docs
Also, please note that MySQL 5.7 will reach EOL in the next month. - though that is a good remark - we will consider updating. Thank you! However until we do that, it would be very helpful if you could help me to apply migrations to MySQL 5.7 DB using Atlas.
Another point that makes me think that the issue comes from out of my SQL migration script is the error message I get - it states an error while creating atlas_schema_revisions
table.
Hey @iSerganov.
Are you by any chance able to provide a repository, that shows the bug in action? I tried again to reproduce the issue without success.
Unfortunately no, I work in the private repository. But I am sure it should be quite easy to reproduce.
I have the latest atlas version 0.14
installed on MacOS using brew.
To reproduce you just need to perform the following steps against MySQL 5.7.12 DB:
gorm
model.atlas migrate diff $(MIGRATION_NAME) --env gorm --dev-url <your-db-url>
- note it will generate awesome SQL statement that is perfectly working if you run it against the same DB using mysql
cli.atlas migrate apply
Here is my atlas.hcl
file content:
data "external_schema" "gorm" {
program = [
"go",
"run",
"-mod=mod",
"ariga.io/atlas-provider-gorm",
"load",
"--path", "./pkg/database/model",
"--dialect", "mysql"
]
}
env "gorm" {
src = data.external_schema.gorm.url
migration {
dir = "file://pkg/database/migrations"
}
format {
migrate {
diff = "{{ sql . \" \" }}"
}
}
}
As the result I always see Error: sql/schema: create "atlas_schema_revisions" table: Error 1071 (42000): Specified key was too long; max key length is 767 bytes
Hey @iSerganov, I tried once again to reproduce the issue without success. Please find below the steps I took. It all works as expected. You can see the migration is applied and the atlas_schema_revisions
table is created.
As long as I am not able to re-create the issue you are facing, I am unable to help :crying_cat_face:. If possible, please try to create an example repository that shows the issue. It does not need to have any of your private code there.
Also, if you want and can, I am willing to sign a NDA to have a look at the real example you are facing. Contact me on Discord privately, if you want to.
Hey @masseelch ! Thank you very much for your efforts! The data you have provided made me trying the same steps with the local MySQL instance (in docker) against MySQL 8.0.34 and it works like a charm!
Most likely there is an issue particularly with AWS Aurora MySQL 5.7.12 instance. I will do my best to upgrade it this week and let you know if the issue is gone.
Thank you very much for your assistance once again!
After updating DB engine to MySQL 8.0 - migration apply works smoothly. Thank you for your assistance gentlemen, closing the issue.
When running
atlas migrate apply
against MySQL 5.7.12 server, the following error occurs:Error: sql/schema: create "atlas_schema_revisions" table: Error 1071 (42000): Specified key was too long; max key length is 767 bytes
Generated migration file: