kubitron / redmine_git_hosting

A ChiliProject/Redmine plugin which makes configuring your own git hosting easy.
78 stars 15 forks source link

Fixes mostly related to initial migration #80

Closed xdissent closed 12 years ago

xdissent commented 12 years ago

The majority of these changes are there to handle the initial db:migrate when the plugin is already installed. The observers are disabled when migrating and neither the routes nor the settings observer assume any database tables exist. Also, two presumed typos are fixed.

kubitron commented 12 years ago

On 10/15/2012 7:51 AM, Greg Thornton wrote:

The majority of these changes are there to handle the initial |db:migrate| when the plugin is already installed. The observers are disabled when migrating and neither the routes nor the settings observer assume any database tables exist. Also, two presumed typos are fixed. Hey, Greg!

Now that I've looked at your changes more closely, I'm curious: were all of the fixes in the first 4 commits because of migration issues? The commits after that were (1) a typo when I factored code for Redmine 1.4 (thanks!) and (2) the Ruby 1.9.x problem. I've already exported commits addressing these to head of master (I had to make the CachedShellRedirector fix in another place that you missed).

As for the first 4 commits, I ask, because I am assuming that the original code should work after migration, right? (i.e. you should be able to pull from master and things should work). Were the Settings not working at some point during migration? I haven't heard this problem from folks doing a fresh install, so just curious about the circumstances.

--KUBI--

Professor John Kubiatowicz 673 Soda Hall Berkeley, CA 94720-1776

xdissent commented 12 years ago

I suspect people are doing a fresh install by first installing redmine, running migrations, and then installing the plugin. Whenever the observers or urls are loaded, they try to query the settings table, which won't exist if you haven't already run the initial redmine migration. Here's what happens when I try to run db:migrate for the first time, after installing the plugin:

Crow:Code xdissent$ git clone -b 1.4.4 https://github.com/redmine/redmine.git
Cloning into 'redmine'...
remote: Counting objects: 89544, done.
remote: Compressing objects: 100% (17206/17206), done.
remote: Total 89544 (delta 71217), reused 89083 (delta 70890)
Receiving objects: 100% (89544/89544), 20.00 MiB | 469 KiB/s, done.
Resolving deltas: 100% (71217/71217), done.
Note: checking out '9c691fe1297d5be5f22541fbcde05d09446a6ec5'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

Crow:Code xdissent$ cd redmine/
Crow:redmine xdissent$ cd vendor/plugins/ &&  git clone https://github.com/kubitron/redmine_git_hosting.git
Cloning into 'redmine_git_hosting'...
remote: Counting objects: 6128, done.
remote: Compressing objects: 100% (2156/2156), done.
-eceiving objects:   2% (123/6128), 28.00 KiB | 20 KiB/s     
remote: Total 6128 (delta 3778), reused 5949 (delta 3646)
Receiving objects: 100% (6128/6128), 939.84 KiB | 57 KiB/s, done.
Resolving deltas: 100% (3778/3778), done.
Crow:plugins xdissent$ cd -
/Users/xdissent/Code/redmine
Crow:redmine xdissent$ rvm use @redmine --create
Using /Users/xdissent/.rvm/gems/ruby-1.9.3-p194 with gemset redmine
Crow:redmine xdissent$ bundle install --without mysql mysql2 postgresql rmagick
Fetching gem metadata from http://rubygems.org/......
Fetching gem metadata from http://rubygems.org/......
Using rake (0.9.2.2) 
Installing activesupport (2.3.14) 
Installing rack (1.1.3) 
Installing actionpack (2.3.14) 
Installing actionmailer (2.3.14) 
Installing activerecord (2.3.14) 
Installing activeresource (2.3.14) 
Installing coderay (1.0.8) 
Installing edavis10-object_daddy (0.4.3) 
Installing i18n (0.4.2) 
Installing inifile (0.4.1) 
Installing json (1.7.5) with native extensions 
Installing lockfile (1.4.3) 
Installing metaclass (0.0.1) 
Installing mocha (0.12.7) 
Installing net-ldap (0.3.1) 
Installing net-ssh (2.1.4) 
Installing rails (2.3.14) 
Installing rdoc (3.12) 
Installing ruby-openid (2.1.8) 
Installing shoulda (2.10.3) 
Installing sqlite3 (1.3.6) with native extensions 
Installing tzinfo (0.3.33) 
Using bundler (1.2.1) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Crow:redmine xdissent$ cat > config/database.yml <<EOF
> production:
>   adapter: sqlite3
>   database: db/production.sqlite3
> EOF
Crow:redmine xdissent$ rake generate_session_store
DEPRECATION WARNING: Rake tasks in vendor/plugins/redmine_git_hosting/tasks, vendor/plugins/redmine_git_hosting/tasks, and vendor/plugins/redmine_git_hosting/tasks are deprecated. Use lib/tasks instead. (called from <top (required)> at /Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/rails-2.3.14/lib/tasks/rails.rb:10)
Crow:redmine xdissent$ RAILS_ENV=production rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Could not find table 'settings'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activerecord-2.3.14/lib/active_record/connection_adapters/sqlite3_adapter.rb:29:in `block in table_structure'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activerecord-2.3.14/lib/active_record/connection_adapters/sqlite3_adapter.rb:28:in `tap'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activerecord-2.3.14/lib/active_record/connection_adapters/sqlite3_adapter.rb:28:in `table_structure'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activerecord-2.3.14/lib/active_record/connection_adapters/sqlite_adapter.rb:228:in `columns'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activerecord-2.3.14/lib/active_record/base.rb:1305:in `columns'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activerecord-2.3.14/lib/active_record/base.rb:1318:in `column_names'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activerecord-2.3.14/lib/active_record/base.rb:1331:in `column_methods_hash'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activerecord-2.3.14/lib/active_record/base.rb:2025:in `block in all_attributes_exists?'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activerecord-2.3.14/lib/active_record/base.rb:2025:in `each'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activerecord-2.3.14/lib/active_record/base.rb:2025:in `all?'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activerecord-2.3.14/lib/active_record/base.rb:2025:in `all_attributes_exists?'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activerecord-2.3.14/lib/active_record/base.rb:1876:in `method_missing'
/Users/xdissent/Code/redmine/app/models/setting.rb:171:in `find_or_default'
/Users/xdissent/Code/redmine/app/models/setting.rb:108:in `[]'
/Users/xdissent/Code/redmine/app/models/setting.rb:137:in `plugin_redmine_git_hosting'
/Users/xdissent/Code/redmine/vendor/plugins/redmine_git_hosting/app/models/git_hosting_settings_observer.rb:4:in `<class:GitHostingSettingsObserver>'
/Users/xdissent/Code/redmine/vendor/plugins/redmine_git_hosting/app/models/git_hosting_settings_observer.rb:1:in `<top (required)>'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:184:in `require'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:184:in `require'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:291:in `require_or_load'
/Users/xdissent/Code/redmine/vendor/plugins/engines/lib/engines/rails_extensions/dependencies.rb:132:in `require_or_load_with_engine_additions'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:451:in `load_missing_constant'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:106:in `const_missing_with_dependencies'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:118:in `const_missing'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:463:in `load_missing_constant'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:106:in `const_missing_with_dependencies'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:463:in `load_missing_constant'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:122:in `const_missing'
/Users/xdissent/Code/redmine/vendor/plugins/redmine_git_hosting/init.rb:95:in `block (2 levels) in evaluate_init_rb'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/rails-2.3.14/lib/initializer.rb:614:in `call'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/rails-2.3.14/lib/initializer.rb:614:in `block in after_initialize'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/rails-2.3.14/lib/initializer.rb:613:in `each'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/rails-2.3.14/lib/initializer.rb:613:in `after_initialize'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/rails-2.3.14/lib/initializer.rb:179:in `process'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/rails-2.3.14/lib/initializer.rb:113:in `run'
/Users/xdissent/Code/redmine/config/environment.rb:21:in `<top (required)>'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `require'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `block in require'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:547:in `new_constants_in'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `require'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@redmine/gems/rails-2.3.14/lib/tasks/misc.rake:4:in `block in <top (required)>'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/xdissent/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/xdissent/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `load'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `<main>'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/bin/ruby_noexec_wrapper:14:in `eval'
/Users/xdissent/.rvm/gems/ruby-1.9.3-p194@global/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate => environment

So that's the settings observer trying to access the settings table, which hasn't been created. That's what the @@old_valuehash patch I sent attempts to fix - it delays the loading of the settings until after the table exists. Unfortunately, the observer will also be triggered for updates during the db:migrate, which will try to operate on other tables that don't yet exists. So it really needs to be disabled altogether while db:migrate is running.

Even with the observer completely unloaded during db:migrate, the routes will still be loaded and will also attempt to hit the settings table to find the git prefix and the same exception is thrown. (2nd & 3rd commit)

kubitron commented 12 years ago

So -- does the init patch remove the need for the git_hosting_observer commit (#1)?

xdissent commented 12 years ago

Hmm, if the class is loaded at all then the first commit is still necessary. I'm not sure if it is loaded before that point in init.rb but I figured better safe than sorry.

kubitron commented 12 years ago

Ok. Mind if I do these patches a bit more compactly?

xdissent commented 12 years ago

Of course not! Go to town! Thanks

kubitron commented 12 years ago

Ok. Can you pull from my 'testing' branch? It should be the equivalent of your patches (the last commit has fixes that should hopefully allow migration from scratch as you are doing). If you are curious about them, do a git diff -w since there were some whitespace changes that are inconsequential.

xdissent commented 12 years ago

Testing branch works great! Feel free to do what you wish with this PR now. Thanks a lot!

kubitron commented 12 years ago

Ok. Glad that it works.

kubitron commented 12 years ago

Found another bug related to use of Ruby 1.9.x and post-receive hook. You probably want to pull from master to get the patch (will see that cached repository link is never updated when commits pushed to gitolite).