Skip to content
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

When I execute the migrate refresh command, it rolls back, but migrate is not re-executed. #4712

Closed
MizukiMatsutani opened this issue Aug 3, 2021 · 5 comments

Comments

@MizukiMatsutani
Copy link

MizukiMatsutani commented Aug 3, 2021

Thank you for providing a great tool!

I'm using the following The Bee version.

| ___ \
| |_/ /  ___   ___
| ___ \ / _ \ / _ \
| |_/ /|  __/|  __/
\____/  \___| \___| v2.0.2

├── Beego     : Beego is not installed. Please do consider installing it first: https://github.com/beego/beego/v2. If you are using go mod, and you don't install the beego under $GOPATH/src/github.com/astaxie, just ignore this.
├── GoVersion : go1.16.5
├── GOOS      : darwin
├── GOARCH    : amd64
├── NumCPU    : 12
├── GOPATH    : /Users/xxxx/.go
├── GOROOT    : /usr/local/go
├── Compiler  : gc
└── Date      : Tuesday, 3 Aug 2021
  • What did you do?
    When I execute the migrate refresh command, it rolls back, but migrate is not re-executed.
    I ran the following steps:
  1. bee generate migration create_users_table Generated and modified the migration file.
  2. bee migrate --conn="dns"
  3. Modify create_users_table file (add field)
  4. bee migrate refresh --conn="dns" Run migrate again.
  5. But the changes do not apply to the database. It will be rolled back and migrate will be skipped.

Upgrade becomes 0 as shown below.

2021/08/03 15:22:52 INFO     ▶ 0013 |> 2021/08/03 15:22:48.290 [I]  total success reset: 1  migration
2021/08/03 15:22:52 INFO     ▶ 0014 |> 2021/08/03 15:22:50.295 [I]  total success upgrade: 0  migration
  • What did you expect to see?
    The migrate refresh command expected that the Up() method of all migration files would be executed after all migration files were rolled back.

I checked the following execution part generated by the refresh command.
https://github.com/beego/bee/blob/457c2f7dc885ea68f0bc97020ff5b7d178c8eaad/cmd/commands/migrate/migrate.go#L395

I expected that the implementation of Upgrade(0) called here was not in the expected state.

func Refresh() error {

I suspect that the cause is that the argument lasttime is not used, but is it correct?

func Upgrade(lasttime int64) error {

Is this a bug?
Is my procedure wrong? (The refresh command is supposed to be executed during local development, not in production.)

@flycash
Copy link
Collaborator

flycash commented Aug 4, 2021

Could you provide a simple demo to reproduce it? Now, I am not sure if it's a BUG.

@MizukiMatsutani
Copy link
Author

@flycash
thank you for your reply.

I created a demo.
The procedure is described in the README.

https://github.com/garcons/beego-migrate-demo

Please let me know if you have any problems.

@Sheep42
Copy link

Sheep42 commented Sep 19, 2021

I am seeing the same behavior.

Bee v2.0.2, Ubuntu 18.04

The basic steps to reproduce are:

bee generate migration task - Creates a migration as expected

bee migrate - Runs my initial migrations without issue

bee migrate refresh - Rolls back, but does not re-run the migrations

After this point, to refresh I need to manually delete my tables and run bee migrate again to run the migrations

@sdlyingyong
Copy link

sdlyingyong commented Nov 2, 2021

I used MizukiMatsutani's case to test it.
After generating the test table, I modified the table build statement in m.SQL again and executed migrate refresh, the newly added fields were not synchronized to the database.
Maybe the create table part checks that the table has already been created?

Version
go1.16
bee v2.0.2

@github-actions
Copy link

github-actions bot commented Jan 2, 2022

This issue is inactive for a long time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants