pentacent / keila

Open Source Newsletter Tool.

Home Page:https://keila.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Migration issues when starting container

ObjectivelyAj opened this issue · comments

Hello I'm having an issue when starting this with docker.

I get the following error

keila-keila-1     | 19:21:27.726 [info] == Running 20210816142200 Keila.Repo.Migrations.DefaultContactStatus.change/0 backward
keila-keila-1     | 19:21:27.727 [notice] Application keila exited: exited in: Keila.Application.start(:normal, [])
keila-keila-1     |     ** (EXIT) an exception was raised:
keila-keila-1     |         ** (Ecto.MigrationError) cannot reverse migration command: alter table contacts. You will need to explicitly define up/0 and down/0 in your migration
keila-keila-1     |             (ecto_sql 3.10.1) lib/ecto/migration/runner.ex:213: Ecto.Migration.Runner.execute_in_direction/5
keila-keila-1     |             (ecto_sql 3.10.1) lib/ecto/migration/runner.ex:117: anonymous fn/6 in Ecto.Migration.Runner.flush/0
keila-keila-1     |             (elixir 1.14.5) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
keila-keila-1     |             (ecto_sql 3.10.1) lib/ecto/migration/runner.ex:116: Ecto.Migration.Runner.flush/0
keila-keila-1     |             (ecto_sql 3.10.1) lib/ecto/migration/runner.ex:290: Ecto.Migration.Runner.perform_operation/3
keila-keila-1     |             (stdlib 5.0.2) timer.erl:270: :timer.tc/2
keila-keila-1     |             (ecto_sql 3.10.1) lib/ecto/migration/runner.ex:25: Ecto.Migration.Runner.run/8
keila-keila-1     |             /opt/app/lib/keila-0.12.6/priv/repo/seeds.exs:48: (file)
keila-keila-1     | Kernel pid terminated (application_controller) ({application_start_failure,keila,{bad_return,{{'Elixir.Keila.Application',start,[normal,[]]},{'EXIT',{#{message => <<"cannot reverse migration command: alter table contacts. You will need to explicitly define up/0 and down/0 in your migration">>,'__struct__' => 'Elixir.Ecto.MigrationError','__exception__' => true},[{'Elixir.Ecto.Migration.Runner',execute_in_direction,5,[{file,"lib/ecto/migration/runner.ex"},{line,213}]},{'Elixir.Ecto.Migration.Runner','-flush/0-fun-1-',6,[{file,"lib/ecto/migration/runner.ex"},{line,117}]},{'Elixir.Enum','-reduce/3-lists^foldl/2-0-',3,[{file,"lib/enum.ex"},{line,2468}]},{'Elixir.Ecto.Migration.Runner',flush,0,[{file,"lib/ecto/migration/runner.ex"},{line,116}]},{'Elixir.Ecto.Migration.Runner',perform_operation,3,[{file,"lib/ecto/migration/runner.ex"},{line,290}]},{timer,tc,2,[{file,"timer.erl"},{line,270}]},{'Elixir.Ecto.Migration.Runner',run,8,[{file,"lib/ecto/migration/runner.ex"},{line,25}]},{elixir_eval,'__FILE__',1,[{file,"/

This is my compose file

version: "3"

services:
  keila:
    image: pentacent/keila:0.12
    ports:
      - "4000:4000"
    depends_on:
      - postgres
    environment:
      SECRET_KEY_BASE: "$KEY"
      DB_URL: "postgres://postgres:postgres@postgres/postgres"
      MAILER_SMTP_HOST: "$SMTPHOST"
      MAILER_SMTP_USER: ""
      MAILER_SMTP_PASSWORD: ""
      MAILER_SMTP_PORT: "$SMTP_PORT"
      KEILA_PASSWORD: ""
      KEILA_USER: ""
      URL_HOST: "$HOST"
    volumes:
      - type: volume
        target: /app/data


  postgres:
    image: postgres:13
    ports:
      - "5432:5432"
    environment:
      POSTGRES_PASSWORD: "postgres"
      POSTGRES_USER: "postgres"
      POSTGRES_DB: "postgresi"
    restart: unless-stopped
    volumes:
      - type: volume
        target: /var/lib/postgresql/data

I'm not really sure why I keep getting this migration error

Hey there, thanks for reporting this issue. Is there any reason why you’re trying to rollback this specific migration?

I'm not even trying to roll back this is the error I get when trying to deploy the newest img.

Are you running Keila.ReleaseTasks.init()? Something seems to be broken in your database where there is no Auth Group in your database yet the creation of a new root group and root user fails. Could you share the full logs?

I’m gonna close this for now. If the issue persists, please feel free to reopen the issue.

I managed to simulate the same error. When we try to start any version (I tested from 0.11.0 to 0.14.0) on a clean and recently installed Postgres database (I'm using Docker), the error happens.

After several tests, the error did not occur when I started the database creating the default user as root and later, before starting keila, I created a role called keila in the database with the same password as the default user (root). Only in this scenario did the migrations run successfully on the first startup. 🚀

Did you maybe have data from a previous installation in your database? The CI tests show that the migrations can run without issues from an empty database, so I'm not sure where the issue could be coming from.

Did you maybe have data from a previous installation in your database? The CI tests show that the migrations can run without issues from an empty database, so I'm not sure where the issue could be coming from.

There is no such possibility. In my tests I used Postgres in Docker using a bind mount volume. And I made sure on each attempt to completely delete the folder from the volume and recreate it.

The only explanation I have then that there was an error when Keila was trying to initialize the database. Were you maybe missing some env variables for your system mailer? Could you share the full logs?