jigarius / toggl2redmine

Import time from Toggl 2 Redmine.
GNU General Public License v3.0
26 stars 6 forks source link

Toggle2Redmine db migrations fail without preexisting db #54

Closed WuCris closed 4 years ago

WuCris commented 4 years ago

Bug summary

Toggle2Redmine doesn't understand how to run database migrations without any preexisting database.

When installing toggle2redmine on a clean Redmine 3.x install it fails on database migrations and prevents redmine from starting. Other unrelated plugins do not cause Redmine to exit with error.

To Reproduce

  1. Docker official redmine:3.4.13-passenger
  2. Clone toggle2redmine to a plugins directory mounted on the host.
  3. Start Redmine with a connected MySQL database.
  4. Check docker logs <name of container>

Error log

redmine          | Migrating toggl2redmine (Toggl 2 Redmine)...
redmine          | I, [2020-04-04T05:46:22.151622 #103]  INFO -- : Migrating to CreateTogglApiKeyField (1)
redmine          | -- [](4.2)
redmine          | -- [](4.2)
redmine exited with code 1
jigarius commented 4 years ago

I did some quick searches, but I couldn't find anything similar. I'm not sure if it's safe to assume that the Redmine database will be up-to-date while installing a plugin. At least Redmine core's database migrations should be executed before the plugin can be installed because the plugin uses UserCustomField.

I'd recommend you to try this on a fresh installation of Redmine:

Let me know if that helps.

WuCris commented 4 years ago

I've give you more context as to what this bug is so you can reproduce it.

Create an empty directory with a docker-compose.yml that looks like this:

version: '3'
services:

  redmine:
      image:          redmine:3.4.13-passenger
      ports:
        - "8080:3000"
      environment:
        REDMINE_DB_MYSQL:    mysql
        REDMINE_DB_USERNAME: redmine
        REDMINE_DB_PASSWORD: password
        REDMINE_DB_DATABASE: redmine
        REDMINE_PLUGINS_MIGRATE: 1
      volumes:
        - ./plugins:/usr/src/redmine/plugins
  mysql:
      image: mysql:5.7
      environment:
        MYSQL_ROOT_PASSWORD: root
        MYSQL_DATABASE:      redmine
        MYSQL_USER:          redmine
        MYSQL_PASSWORD:      password
      volumes:
        - mysql:/var/lib/mysql

volumes:
  mysql: {}

You can now bring up the environment (we need a short sleep so MySQL initialized it's self).

docker-compose up -d mysql
sleep 1m; docker-compose up -d

This means:

Everything is brought up seamlessly without an issue. I can add a number of third party plugins included in the codebase by copying them into the data directory. I then test this with a clean (deleting the database to reinitialize it) install and it works.

docker-compose down -v
docker-compose up -d mysql
sleep 1m; docker-compose up -d

However should I do this with toggle2redmine being one of these plugins the Redmine container exists with error saying this (when I look at docker-compose logs redmine) the following:

redmine_1  | Migrating redmine_recent_wiki_pages (Redmine Recent Wiki Pages)...
redmine_1  | Migrating redmine_search_archived_projects (Redmine Search Archived Projects)...
redmine_1  | Migrating redmine_thumbnails (Embeded Thumbnail Plugin)...
redmine_1  | Migrating redmine_timesheet_log_user (Redmine Timesheet Log User)...
redmine_1  | Migrating redmine_user_specific_theme (Redmine User-Specific Theme Plugin)...
redmine_1  | Migrating redmine_wiki_issue_details (Redmine Wiki Issue Details plugin)...
redmine_1  | Migrating toggl2redmine (Toggl 2 Redmine)...
redmine_1  | I, [2020-04-08T20:52:26.779009 #122]  INFO -- : Migrating to CreateTogglApiKeyField (1)
redmine_1  | -- [](4.2)
redmine_1  | -- [](4.2)
redminetest_redmine_1 exited with code 1

For other plugins Migrating doesn't give any errors or appear to do anything, however for toggle2redmine it throws and error and the container does not start and exits with error.

jigarius commented 4 years ago

Ok. It appears that you're using the 3.x version of the plugin with Redmine 3.x. Can you try it again with the 3.x version of the plugin?

Since the latest version of Redmine is 4.x, most of the plugin updates and new features happen on the 4.x version of the plugin which you seem to be using.

In any case, I'll do some research to see if I can make the migrations work for both versions of Redmine without making many changes.

jigarius commented 4 years ago

I'm marking this as closed. Please feel free to reopen it if my answer above doesn't solve the problem for you.