sea-schema
sea-schema copied to clipboard
Fail to distinguish MySQL default expression / value
thread 'main' panicked at 'assertion failed: `(left == right)`
Diff < left / right > :
<"CREATE TABLE `order` ( `id` int NOT NULL AUTO_INCREMENT, `total` decimal(19, 4), `bakery_id` int NOT NULL, `customer_id` int NOT NULL, `placed_at` datetime NOT NULL DEFAULT '2021-11-05 00:00:00', KEY `FK_order_bakery` (`bakery_id`), KEY `FK_order_customer` (`customer_id`), PRIMARY KEY (`id`), CONSTRAINT `FK_order_bakery` FOREIGN KEY (`bakery_id`) REFERENCES `bakery` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `FK_order_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"
>"CREATE TABLE `order` ( `id` int NOT NULL AUTO_INCREMENT, `total` decimal(19, 4), `bakery_id` int NOT NULL, `customer_id` int NOT NULL, `placed_at` datetime NOT NULL DEFAULT 2021-11-05 00:00:00, KEY `FK_order_bakery` (`bakery_id`), KEY `FK_order_customer` (`customer_id`), PRIMARY KEY (`id`), CONSTRAINT `FK_order_bakery` FOREIGN KEY (`bakery_id`) REFERENCES `bakery` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `FK_order_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"
', tests/live/mysql/src/main.rs:56:9
Is it fixed now?
Not yet fixed
I was about to take on this issue as a first issue in the Rust world specifically, however, I have not been able to reproduce the issue.
This is what I've done:
Updated code
Added a .default()
to the placed_at
column of the order
table with value "2021-11-05 00:00:00"
Snippet
.col(
ColumnDef::new(Alias::new("placed_at"))
.date_time()
.not_null()
.default("2021-11-05 00:00:00"), // <------------
)
Result
The test exited with code 0, and below is the order table comparison.
Expected SQL:
CREATE TABLE `order` ( `id` int NOT NULL AUTO_INCREMENT, `total` decimal(19, 4) UNSIGNED, `bakery_id` int NOT NULL, `customer_id` int NOT NULL, `placed_at` datetime NOT NULL DEFAULT '2021-11-05 00:00:00', KEY `FK_order_bakery` (`bakery_id`), KEY `FK_order_customer` (`customer_id`), PRIMARY KEY (`id`), CONSTRAINT `FK_order_bakery` FOREIGN KEY (`bakery_id`) REFERENCES `bakery` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `FK_order_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
Generated SQL:
CREATE TABLE `order` ( `id` int NOT NULL AUTO_INCREMENT, `total` decimal(19, 4) UNSIGNED, `bakery_id` int NOT NULL, `customer_id` int NOT NULL, `placed_at` datetime NOT NULL DEFAULT '2021-11-05 00:00:00', KEY `FK_order_bakery` (`bakery_id`), KEY `FK_order_customer` (`customer_id`), PRIMARY KEY (`id`), CONSTRAINT `FK_order_bakery` FOREIGN KEY (`bakery_id`) REFERENCES `bakery` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `FK_order_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
Please let me know if the above steps validate that this issue no longer exists 😃
Hey @assemmarwan, thanks for the initiative! How about the other way round? A default expression.
.col(
ColumnDef::new(Alias::new("placed_at"))
.date_time()
.not_null()
.default(Expr::current_timestamp()), // <------------
)
the same issue, in mysql table a column has a default value "hello".
// want
`field1` varchar(64) NOT NULL DEFAULT "hello" COMMENT 'the field',
// but got
`field1` varchar(64) NOT NULL DEFAULT hello COMMENT 'the field',
@tests/write/mysql/src/main.rs
I find may be crate sea-query
@src/backend/table_builder.rs:97
cause this.
@thinkgos Can you submit a reproducible example?
In particular, is the discovery result correct, or is the bug inside the writer?
Ping! I just created a PR, please check
- https://github.com/SeaQL/sea-schema/pull/110