golang-migrate / migrate

Database migrations. CLI and Golang library.
Other
15.13k stars 1.39k forks source link

downmigration with container not possible due to instantly rejected promp #684

Closed rosariop closed 2 years ago

rosariop commented 2 years ago

Describe the Bug When using the docker container it's not possible to migrate down because the "Are you sure you want to apply all down migrations? [y/N]" is instantly answered (with no) and therefore it is not applying downmigrations.

Piping "y" into the command does not work either.

echo "y" | docker run --network host migrator -path=/migrations/ -database "mysql://DBUSER:DBPASS@tcp(localhost:3306)/appdb" down

prompts the same

Steps to Reproduce Steps to reproduce the behavior:

  1. Building a custom Container:
    
    FROM migrate/migrate

COPY /migrations /migrations

2. My migrations look like:
 1_create_category.up.sql
 ```sql
 CREATE TABLE category(
    category_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY UNIQUE,
    category_name VARCHAR(128) UNIQUE NOT NULL
);

1_create_category.down.sql

CREATE TABLE category;
  1. I used the container using following command: docker run --network host migrator -path=/migrations/ -database "mysql://DBUSER:DBPASS@tcp(localhost:3306)/appdb" down
  2. See error rpolito@Polito-PC:~/GoProjects/src/git.rosibert.de/rpolito/minimal-shop/migrator$ docker run --network host migrator -path=/migrations/ -database "mysql://DBUSER:DBPASS@tcp(localhost:3306)/appdb" down Are you sure you want to apply all down migrations? [y/N] Not applying all down migrations

the Are you sure you want to apply all down migrations? [y/N] prompt is instantly answered with N! Expected Behavior Waiting for me to answer the promp

Migrate Version the latest provided by docker

Loaded Database Drivers mysql / mariadb

Go Version go1.17.5 linux/amd64

tyagip966 commented 2 years ago

Hey @rosariop,

Could you please try after putting -all in the end of the migrate down command? e.g echo "y" | docker run --network host migrator -path=/migrations/ -database "mysql://DBUSER:DBPASS@tcp(localhost:3306)/appdb" down -all

Thanks