我用的是this goose口味。我希望我的迁移脚本在出现错误时回滚。在-- +goose StatementStart和-- +goose StatementEnd中包装我的语句对我不起作用。
-- +goose Up
-- SQL in section 'Up' is executed when this migration is applied
-- +goose StatementBegin
ALTER TABLE books
ADD COLUMN author VARCHAR(10) NOT NULL AFTER name;
UPDATE books
SET author = created_by
WHERE created > '2021-01-05';
-- +goose StatementEnd
-- +goose Down
-- SQL section 'Down' is executed when this migration is rolled back
-- +goose StatementBegin
ALTER TABLE books
DROP COLUMN author;
-- +goose StatementEnd这将导致Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE...。
goose可以做到这一点吗?或者我只需要在一个迁移文件中编写一个查询?
发布于 2021-07-25 21:12:16
根据MySQL 5.7 documentation,大多数动态链接库查询不能作为事务执行。
因此,这应该不可能使用任何解决方法来完成,因为它与底层数据库类型和版本相关。
@mh-cbon谢谢你指出这一点。
https://stackoverflow.com/questions/68507360
复制相似问题