Project

General

Profile

Plugin Migration issue - problem with version numbers

Added by Anonymous over 13 years ago

Greetings all.

My apologies if this has been posted before, but I was unable to search for this issue, hence I'm posting it here now.

I'm trying to create my first Redmine plugin (am also fairly new to Rails - about a month or so of experience), and created two simple migration files, and following the tutorial, renamed them to 001_create_table_a.rb and 002_create_table_b.rb. When I ran rake db:migrate_plugins, I get this error:

rake aborted!
Multiple migrations have the version number 1

Googling around, I renamed my numbers from 001_ and 002_ to something higher, (so that it follows sequentially after redmine's own migrations), but I still got the same error. Removing the numbers entirely will give the same error as well.

I'm not very sure how to resolve this issue, much appreciation and thanks in advance to whoever is able to assist me here.


Replies (10)

RE: Plugin Migration issue - problem with version numbers - Added by Felix Schäfer over 13 years ago

You can't change migration numbers after having applied them, that confuses rails because it stores the migrations it has already applied based on these numbers. What does your schema_migrations table look like?

RE: Plugin Migration issue - problem with version numbers - Added by Anonymous over 13 years ago

Hi Felix,

A select count(version) on my

schema_migrations
table returns 171.

I've also tried to rename my file as 172_table_a.rb, I still got the same issue. Am I doing anything wrong here?

RE: Plugin Migration issue - problem with version numbers - Added by Anonymous over 13 years ago

Hi Felix,

It looks like this (truncated in the middle):

redmine=# select * from schema_migrations;
    version     
----------------
 1
 2
 3
 4
 5
...
...
...
 20091227112908
 20100221100219
 20100313132032
 20100313171051
 20100705164950
 20100819172912
(171 rows)

A select count(version) on my schema_migrations table returns 171.

I've also tried to rename my file as 172_table_a.rb, I still got the same issue. Am I doing anything wrong here?

RE: Plugin Migration issue - problem with version numbers - Added by Felix Schäfer over 13 years ago

Jinny Wong wrote:

I've also tried to rename my file as 172_table_a.rb, I still got the same issue. Am I doing anything wrong here?

The point is not how many are in there, but which are already in there, in theory rails only checks if a migration has been applied already or not, independently of the numbering scheme or if a migration number is "bigger" than the other.

Plugin migrations are also namespaced, example: 1-redmine_doodles. I suggest taking a clean install of redmine and trying again there, I think you have something very funny/broken in your current install.

RE: Plugin Migration issue - problem with version numbers - Added by Anonymous over 13 years ago

I actually started a fresh, clean install of Redmine specifically for development of this plugin... it was when I was trying to to migrate_plugins for the first time, that I hit this problem.

In any case, I dropped the db, re-created and re-ran the migrations, same issue again.

Here's how my migration files looks like:

db/
   migrate/
          001_create_budget.rb
          002_create_budget_items.rb

And the stack trace when I run the plugin migrations is attached below, if it helps.

trace.txt (3.59 KB) trace.txt

RE: Plugin Migration issue - problem with version numbers - Added by Felix Schäfer over 13 years ago

What's the full path from the top redmine directory?

RE: Plugin Migration issue - problem with version numbers - Added by Anonymous over 13 years ago

The full path is

redmine/vendor/plugins/redmine_budget/db/

RE: Plugin Migration issue - problem with version numbers - Added by Felix Schäfer over 13 years ago

Well, my migrations are named 20100922201050_create_events.rb for example, but that shouldn't make a difference. Did you already have a plugin called redmine_budget installed? Other than that, I'm out of ideas, sorry.

RE: Plugin Migration issue - problem with version numbers - Added by Anonymous over 13 years ago

I've re-generated my migration files with timestamps instead this time - the migrations work successfully now. Thanks a lot for your guidance!

That being said, perhaps may I suggest someone update the Plugin Tutorial wiki at this page: http://www.redmine.org/wiki/redmine/Plugin_Tutorial as the wording of the tutorial in the section about migrations can be read as advising against timestamped migrations.

RE: Plugin Migration issue - problem with version numbers - Added by Felix Schäfer over 13 years ago

Jinny Wong wrote:

That being said, perhaps may I suggest someone update the Plugin Tutorial wiki at this page: http://www.redmine.org/wiki/redmine/Plugin_Tutorial as the wording of the tutorial in the section about migrations can be read as advising against timestamped migrations.

Feel free to edit the tutorial, or maybe even better discuss this with Eric Davis (edavis10) on IRC if he's present.

    (1-10/10)