【发布时间】:2021-07-25 21:12:16
【问题描述】:
我用的是this鹅味。我希望我的迁移脚本在出现错误时回滚。将我的陈述包含在 -- +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...。
鹅可以做到这一点吗?还是我只需要在一个迁移文件中编写一个查询?
【问题讨论】:
-
认为每对开始/结束语句应该只有一个 sql 语句。但是,这似乎并没有像您认为的那样github.com/steinbacher/goose/blob/… 这更像是一种解决方法,因为 sql 语法很难。
-
I want my migration script to roll back when there is an error.你试过了吗? -
你可以在这里阅读引擎盖上发生了什么github.com/steinbacher/goose/blob/…
-
最后,这一切都与你的数据库引擎密切相关stackoverflow.com/a/4736346/4466350