-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
Cannot add nullable TIMESTAMP column #63
Comments
Thank you for your report. While I can fix sqldef's behavior to print the "Expected Generated DDLs", I couldn't reproduce your issue: $ mysql -uroot -e 'create database test;'
$ cat /tmp/a.sql
CREATE TABLE user (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(128) DEFAULT 'konsumer'
) Engine=InnoDB DEFAULT CHARSET=utf8mb4;
$ go run cmd/mysqldef/mysqldef.go -uroot test < /tmp/a.sql
-- Apply --
CREATE TABLE user (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(128) DEFAULT 'konsumer'
) Engine=InnoDB DEFAULT CHARSET=utf8mb4;
$ cat /tmp/b.sql
CREATE TABLE user (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(128) DEFAULT 'konsumer',
created_at DATETIME NULL DEFAULT NULL
) Engine=InnoDB DEFAULT CHARSET=utf8mb4;
$ go run cmd/mysqldef/mysqldef.go -uroot test < /tmp/b.sql
-- Apply --
ALTER TABLE user ADD COLUMN created_at datetime DEFAULT null AFTER name; It feels like the column gets
Is it configured explicitly in your environment as such? I'd like to know how to do that for running tests with the mode. |
@k0kubun I tried to check my environment and didn't see any special settings though, I think you're right that the default behavior should be |
Let me close this issue until the investigation is done. Please feel free to reopen this issue when you finish it or you need the workaround first. |
@k0kubun I think I might need your help for the workaround first 🙏 Thank you! I tried to ask my colleague and confirmed following configurations in our command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_bin
- --general-log-file=/var/log/mysql/query.log
- --general-log=true
- --long-query-time=1
- --slow-query-log-file=/var/log/mysql/slow.log
- --slow-query-log=true
environment:
- LANG=C.UTF-8
- MYSQL_DATABASE=${MYSQL_DATABASE} I can't find any of them can have impact to the |
OK.
but you could reproduce the issue using the docker-compose.yml? If possible, I would appreciate an entire docker-compose.yml which could reproduce the behavior (at least I need to know the Docker image name if public). |
Thank you!
Unfortunately, the docker-compose.yml is in our private repo >_< Btw, I'm using |
oh, wait! because I'm running commands with Edit: With removing the |
@k0kubun gotcha! I finally found we set sql_mode in our Haskell backend service instead of from the docker-compose.yaml :/ which it sets (sorry for that I can't share the exact piece of code here because it's in our private repo 🙏) |
Great, thanks! I'll try reproducing and fixing it. |
Thank you so much! Sorry for that I just report that too quick >_< I found I still can reproduce the error with removing the 2 configs. Let me confirm them properly and report it again! Thank you! |
Oh yeah, neither NO_ZERO_DATE nor NO_ZERO_IN_DATE didn't reproduce it. I tried some other strict modes but it didn't do it either. I tried to look for such other options, but I've failed to find it so far.
Thanks, let me (close this issue for now and) wait for the report first 🙏 |
Thank you! I wish I can report the root cause soon! |
With doing some more investigation, I found I still got the invalid default value error even removing all However, I found I can fix the issue with turning on But, I'm very confused 🤔 With reading the documentation of I feel I don't actually find the root cause though... 😞 Though I'm able to fix the issue with setting |
Sure, it was:
|
Just an additional info:
After seeing that, I tested CREATE TABLE user (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(128) DEFAULT 'konsumer',
+ created_at TIMESTAMP NULL DEFAULT NULL
) Engine=InnoDB DEFAULT CHARSET=utf8mb4; and got an error similar to yours:
and this doesn't happen with |
At this point, I could write a failing test with the default configuration. I can implement the original proposal, because it's not really a workaround but a reasonable fix. |
Aaaaah!! Thanks for catching it!!!! I mis-interpret |
I just changed the issue name and description to match the exact issue! |
Thanks to all your helps, I fixed the issue at 50197f9 and started the release as v0.7.2. |
Thank your so much as well for your patience and quick fix! |
Problem
With adding a new nullable TIMESTAMP column in schema, mysqldef will generate a DDL without specifying NULL or not and result in an error like following
Environment
Test Case
Initial Schema
New Schema
Current Generated DDLs
Expected Generated DDLs
I tried to run the expected one locally and it works fine on MySQL.
The text was updated successfully, but these errors were encountered: