【问题标题】:Rollback when doing a database migration with goose使用 goose 进行数据库迁移时回滚
【发布时间】: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...

鹅可以做到这一点吗?还是我只需要在一个迁移文件中编写一个查询?

【问题讨论】:

标签: go goose


【解决方案1】:

根据MySQL 5.7 documentation,大多数 DDL 查询不能作为事务执行。

因此,这应该无法通过任何解决方法来完成,因为它与底层数据库类型和版本相关联。

@mh-cbon谢谢你指出这一点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-17
    • 2017-02-10
    • 2019-12-02
    • 2018-05-08
    • 2015-06-30
    • 2020-04-21
    相关资源
    最近更新 更多