Project

General

Profile

Bug #1706

db:migrate fail on in bookmark.rb

Added by Ky Zh almost 7 years ago. Updated almost 7 years ago.

Status:
Duplicate
Priority:
Normal
Assignee:
-
Category:
DB migrations
Target version:
-
Difficulty:
trivial
Triaged:
No
Bugzilla link:
Pull request:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

I edited app/models/bookmark.rb, and removed the condition "unless"
It seems to work. I still think that this is fixing the symptom not the problem.

[foreman@ms1 foreman]$ diff u /tmp/bookmark.rb.old /tmp/bookmark.rb
--
/tmp/bookmark.rb 2012-06-25 21:10:59.740785531 0100
+
+ /tmp/bookmark.rb.old 2012-06-25 21:10:43.277432124 +0100
@ -2,7 +2,7 @
belongs_to :owner, :polymorphic => true
attr_accessible :name, :controller, :query, :public

- validates_uniqueness_of :name, :unless => Proc.new{|b| Bookmark.my_bookmarks(:conditions => {:name => b.name}).empty?}
+ validates_uniqueness_of :name
validates_presence_of :name
validates_format_of :controller, :with => /\A(\S+)\Z/, :message => "can't be blank or contain white spaces."
validates_presence_of :query

I used "allow_blank: true" with success (https://github.com/rails/rails/issues/5853)
But as i'm not sure it's the intended, best practice, i leave it for a more knowledgeable person to tell.

I installed from git (59be369d36) today.
The db is sqlite from scratch.
I also found 2 pastie with the same problem [1] [2]

Here is thre trace with ":unless"

[foreman@ms1 foreman]$ RAILS_ENV=production rake db:migrate --trace
Libvirt binding are missing - hypervisor management is disabled
/opt/foreman/.gem/ruby/1.9.1/gems/ruby_parser-2.3.1/lib/ruby_parser_extras.rb:10: warning: already initialized constant ENC_NONE
/opt/foreman/.gem/ruby/1.9.1/gems/ruby_parser-2.3.1/lib/ruby_parser_extras.rb:11: warning: already initialized constant ENC_EUC
/opt/foreman/.gem/ruby/1.9.1/gems/ruby_parser-2.3.1/lib/ruby_parser_extras.rb:12: warning: already initialized constant ENC_SJIS
/opt/foreman/.gem/ruby/1.9.1/gems/ruby_parser-2.3.1/lib/ruby_parser_extras.rb:13: warning: already initialized constant ENC_UTF8
  • Invoke db:migrate (first_time)
  • Invoke environment (first_time)
  • Execute environment
  • Execute db:migrate
    AddTableBookmarks: migrating ============================================
    -- create_table(:bookmarks, {:force=>true})
    > 0.0030s
    -
    add_index(:bookmarks, :name)
    > 0.0006s
    -
    add_index(:bookmarks, :controller)
    > 0.0008s
    -
    add_index(:bookmarks, [:owner_id, :owner_type])
    -> 0.0008s
    rake aborted!
    An error has occurred, this and all later migrations canceled:

wrong number of arguments (1 for 0)
/opt/foreman/foreman/app/models/bookmark.rb:13:in `block in <class:Bookmark>'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/named_scope.rb:107:in `call'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/named_scope.rb:107:in `block in scope'
/opt/foreman/foreman/app/models/bookmark.rb:5:in `block in <class:Bookmark>'
/opt/foreman/.gem/ruby/1.9.1/gems/activesupport-3.0.15/lib/active_support/callbacks.rb:414:in `_run_validate_callbacks'
/opt/foreman/.gem/ruby/1.9.1/gems/activemodel-3.0.15/lib/active_model/validations.rb:212:in `run_validations!'
/opt/foreman/.gem/ruby/1.9.1/gems/activemodel-3.0.15/lib/active_model/validations/callbacks.rb:67:in `block in run_validations!'
/opt/foreman/.gem/ruby/1.9.1/gems/activesupport-3.0.15/lib/active_support/callbacks.rb:419:in `_run_validation_callbacks'
/opt/foreman/.gem/ruby/1.9.1/gems/activemodel-3.0.15/lib/active_model/validations/callbacks.rb:67:in `run_validations!'
/opt/foreman/.gem/ruby/1.9.1/gems/activemodel-3.0.15/lib/active_model/validations.rb:179:in `valid?'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/validations.rb:55:in `valid?'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/validations.rb:75:in `perform_validations'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/validations.rb:43:in `save'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/attribute_methods/dirty.rb:21:in `save'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:240:in `block (2 levels) in save'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:292:in `block in with_transaction_returning_status'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:207:in `transaction'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:240:in `block in save'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:251:in `rollback_active_record_state!'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:239:in `save'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/relation/finder_methods.rb:273:in `find_or_instantiator_by_attributes'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/base.rb:995:in `method_missing'
/opt/foreman/foreman/db/migrate/20110417102947_add_table_bookmarks.rb:17:in `up'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:314:in `block in migrate'
/usr/lib/ruby/1.9.1/benchmark.rb:280:in `measure'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:314:in `migrate'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:397:in `migrate'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:539:in `block (2 levels) in migrate'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:613:in `call'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:613:in `block in ddl_transaction'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/transactions.rb:207:in `transaction'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:613:in `ddl_transaction'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:538:in `block in migrate'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:525:in `each'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:525:in `migrate'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:435:in `up'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/migration.rb:417:in `migrate'
/opt/foreman/.gem/ruby/1.9.1/gems/activerecord-3.0.15/lib/active_record/railties/databases.rake:151:in `block (2 levels) in <top (required)>'
/usr/lib/ruby/1.9.1/rake/task.rb:205:in `call'
/usr/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
/usr/lib/ruby/1.9.1/rake/task.rb:200:in `each'
/usr/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
/usr/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
/usr/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
/usr/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'
/usr/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level'
/usr/lib/ruby/1.9.1/rake/application.rb:94:in `each'
/usr/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
/usr/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/usr/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
/usr/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
/usr/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/usr/lib/ruby/1.9.1/rake/application.rb:63:in `run'
/usr/bin/rake:32:in `<main>'
Tasks: TOP => db:migrate

Here is the trace without the "unless" and a clean db:

[foreman@ms1 foreman]$ RAILS_ENV=production rake db:migrate --trace
Libvirt binding are missing - hypervisor management is disabled
/opt/foreman/.gem/ruby/1.9.1/gems/ruby_parser-2.3.1/lib/ruby_parser_extras.rb:10: warning: already initialized constant ENC_NONE
/opt/foreman/.gem/ruby/1.9.1/gems/ruby_parser-2.3.1/lib/ruby_parser_extras.rb:11: warning: already initialized constant ENC_EUC
/opt/foreman/.gem/ruby/1.9.1/gems/ruby_parser-2.3.1/lib/ruby_parser_extras.rb:12: warning: already initialized constant ENC_SJIS
/opt/foreman/.gem/ruby/1.9.1/gems/ruby_parser-2.3.1/lib/ruby_parser_extras.rb:13: warning: already initialized constant ENC_UTF8
  • Invoke db:migrate (first_time)
  • Invoke environment (first_time)
  • Execute environment
  • Execute db:migrate
    AddTableBookmarks: migrating ============================================
    -- create_table(:bookmarks, {:force=>true})
    > 0.0031s
    -
    add_index(:bookmarks, :name)
    > 0.0007s
    -
    add_index(:bookmarks, :controller)
    > 0.0007s
    -
    add_index(:bookmarks, [:owner_id, :owner_type])
    -> 0.0008s
    AddTableBookmarks: migrated (0.1409s) ===================================
AddSolarisTemplates: migrating ==========================================
AddSolarisTemplates: migrated (0.3475s) ================================= AddSolarisDisks: migrating ==============================================
AddSolarisDisks: migrated (0.0452s) ===================================== AddLookUpKeyIdToPuppetClass: migrating ==================================
-- add_column(:lookup_keys, :puppetclass_id, :integer)
> 0.0019s
-
add_index(:lookup_keys, :puppetclass_id)
> 0.0015s
-
add_column(:lookup_keys, :default_value, :string)
> 0.0011s
-
add_column(:lookup_keys, :path, :string)
> 0.0010s
-
add_index(:lookup_keys, :path)
> 0.0014s
-
add_column(:lookup_keys, :description, :string)
> 0.0010s
-
add_column(:lookup_keys, :validator_type, :string)
> 0.0010s
-
add_column(:lookup_keys, :validator_rule, :string)
> 0.0010s
-
rename_column(:lookup_values, :priority, :match)
> 0.0110s
-
add_index(:lookup_values, :match)
-> 0.0007s
AddLookUpKeyIdToPuppetClass: migrated (0.0233s) ========================= AddSparcInfoToModel: migrating ==========================================
-- add_column(:models, :vendor_class, :string, {:limit=>32})
> 0.0015s
-
add_column(:models, :hardware_model, :string, {:limit=>16})
-> 0.0008s
AddSparcInfoToModel: migrated (0.0028s) ================================= AddAncestryToHostgroup: migrating =======================================
-- add_column(:hostgroups, :ancestry, :string)
> 0.0018s
-
add_index(:hostgroups, :ancestry)
-> 0.0011s
AddAncestryToHostgroup: migrated (0.0034s) ============================== CreateSettings: migrating ===============================================
-- create_table(:settings)
> 0.0038s
-
add_index(:settings, :name, {:unique=>true})
-> 0.0013s
CreateSettings: migrated (0.0057s) ====================================== UpdateAuditsTable: migrating ============================================
UpdateAuditsTable: migrated (0.0018s) =================================== CreateHostClass: migrating ==============================================
-- rename_table(:hosts_puppetclasses, :host_classes)
> 0.0017s
-
add_column(:host_classes, :id, :primary_key)
-> 0.0840s
CreateHostClass: migrated (0.0862s) ===================================== AddSuseTemplates: migrating =============================================
AddSuseTemplates: migrated (0.0681s) ==================================== AddVmDefaultsToHostgroup: migrating =====================================
-- add_column(:hostgroups, :vm_defaults, :text)
-> 0.0018s
AddVmDefaultsToHostgroup: migrated (0.0020s) ============================ AddSubnetAndDomainToHostGroups: migrating ===============================
-- add_column(:hostgroups, :subnet_id, :integer)
> 0.0013s
-
add_column(:hostgroups, :domain_id, :integer)
-> 0.0012s
AddSubnetAndDomainToHostGroups: migrated (0.0029s) ====================== RenameChangesToAuditedChanges: migrating ================================
-- rename_column(:audits, :changes, :audited_changes)
-> 0.0237s
RenameChangesToAuditedChanges: migrated (0.0240s) ======================= AddRemoteAddressToAudits: migrating =====================================
-- add_column(:audits, :remote_address, :string)
-> 0.0020s
AddRemoteAddressToAudits: migrated (0.0023s) ============================ RenameParentToAssociation: migrating ====================================
-- rename_column(:audits, :auditable_parent_id, :association_id)
> 0.0241s
-
rename_column(:audits, :auditable_parent_type, :association_type)
-> 0.0216s
RenameParentToAssociation: migrated (0.0461s) =========================== AddGatewayAndDnsToSubnets: migrating ====================================
-- add_column(:subnets, :gateway, :string)
> 0.0018s
-
add_column(:subnets, :dns_primary, :string)
> 0.0011s
-
add_column(:subnets, :dns_secondary, :string)
-> 0.0010s
AddGatewayAndDnsToSubnets: migrated (0.0047s) =========================== EnsureAllHostnamesAreLowercase: migrating ===============================
-- execute("UPDATE hosts SET name=LOWER")
-> 0.0006s
EnsureAllHostnamesAreLowercase: migrated (0.0007s) ====================== AddFromAndToRangesToSubnets: migrating ==================================
-- add_column(:subnets, :from, :string)
> 0.0013s
-
add_column(:subnets, :to, :string)
> 0.0010s
-
remove_column(:subnets, :ranges)
-> 0.0145s
AddFromAndToRangesToSubnets: migrated (0.0173s) ========================= CreateSubnetDomain: migrating ===========================================
-- create_table(:subnet_domains)
> 0.0032s
-
remove_column(:subnets, :domain_id)
-> 0.0120s
CreateSubnetDomain: migrated (0.0507s) ================================== CreateComputeResources: migrating =======================================
-- create_table(:compute_resources)
-> 0.0042s
CreateComputeResources: migrated (0.0044s) ============================== AddUuidAndComputeIdToHost: migrating ====================================
-- add_column(:hosts, :uuid, :string)
> 0.0024s
-
add_column(:hosts, :compute_resource_id, :integer)
-> 0.0011s
AddUuidAndComputeIdToHost: migrated (0.0040s) =========================== AddWindowsTemplates: migrating ==========================================
AddWindowsTemplates: migrated (0.0526s) ================================= AddPuppetMasterProxyToHostAndHostGroup: migrating =======================
-- rename_column(:hosts, :puppetproxy_id, :puppet_ca_proxy_id)
> 0.0920s
-
add_column(:hosts, :puppet_proxy_id, :integer)
> 0.0010s
-
rename_column(:hostgroups, :puppetproxy_id, :puppet_ca_proxy_id)
> 0.0158s
-
add_column(:hostgroups, :puppet_proxy_id, :integer)
> 0.0007s
-
remove_column(:hosts, :puppetmaster_name)
> 0.0875s
-
remove_column(:hostgroups, :puppetmaster_name)
-> 0.0155s
AddPuppetMasterProxyToHostAndHostGroup: migrated (0.3897s) ============== UpdateReportFieldToLargeInt: migrating ==================================
-- change_column(:reports, :status, :bigint)
> 0.0204s
-
change_column(:hosts, :puppet_status, :bigint)
-> 0.1813s
UpdateReportFieldToLargeInt: migrated (0.2021s) ========================= CreateImages: migrating =================================================
-- create_table(:images)
-> 0.0040s
CreateImages: migrated (0.0043s) ======================================== AddCertNameToHost: migrating ============================================
-- add_column(:hosts, :certname, :string)
> 0.0025s
-
add_index("hosts", :certname)
-> 0.0039s
AddCertNameToHost: migrated (0.0069s) =================================== CreateKeyPairs: migrating ===============================================
-- create_table(:key_pairs)
-> 0.0033s
CreateKeyPairs: migrated (0.0036s) ====================================== AddDnsIdToSubnet: migrating =============================================
-- add_column(:subnets, :dns_id, :integer)
-> 0.0019s
AddDnsIdToSubnet: migrated (0.0022s) ==================================== AddImageIdToHost: migrating =============================================
-- add_column(:hosts, :image_id, :integer)
-> 0.0025s
AddImageIdToHost: migrated (0.0028s) ==================================== AddUserComputeResources: migrating ======================================
-- create_table(:user_compute_resources, {:id=>false})
-> 0.0020s
AddUserComputeResources: migrated (0.0023s) ============================= AddComputeResourcesBooleanToUser: migrating =============================
-- add_column(:users, :compute_resources_andor, :string, {:limit=>3, :default=>"or"})
-> 0.0020s
AddComputeResourcesBooleanToUser: migrated (0.0024s) ==================== AddEpelSnippets: migrating ==============================================
AddEpelSnippets: migrated (0.0087s) ===================================== ConvertParamsToText: migrating ==========================================
-- change_column("parameters", :value, :text, {:limit=>false})
> 0.0165s
-
change_column("lookup_values", :value, :text, {:limit=>false})
-> 0.0104s
ConvertParamsToText: migrated (0.0274s) ================================= ChangeBookmarkColumnToText: migrating ===================================
-- change_column("bookmarks", :query, :text, {:limit=>false})
-> 0.0188s
ChangeBookmarkColumnToText: migrated (0.0191s) ========================== RenameAssociationToAssociated: migrating ================================
-- index_exists?(:audits, [:association_id, :association_type], {:name=>"association_index"})
> 0.0019s
-
rename_column(:audits, :association_id, :associated_id)
> 0.0259s
-
rename_column(:audits, :association_type, :associated_type)
> 0.1075s
-
add_index(:audits, [:associated_id, :associated_type], {:name=>"associated_index"})
-> 0.0014s
RenameAssociationToAssociated: migrated (0.1376s) ======================= FixAuditableType: migrating =============================================
-- execute("UPDATE audits SET auditable_type='Host' WHERE auditable_type='Puppet::Rails::Host'")
-> 0.0007s
FixAuditableType: migrated (0.0010s) ==================================== FixAssociatedType: migrating ============================================
-- execute("UPDATE audits SET associated_type='Host' WHERE associated_type='Puppet::Rails::Host'")
-> 0.0007s
FixAssociatedType: migrated (0.0010s) =================================== AddOsFamilyToMedia: migrating ===========================================
-- add_column(:media, :os_family, :string)
-> 0.0019s
AddOsFamilyToMedia: migrated (0.0211s) ================================== AddOsFamilyToPtable: migrating ==========================================
-- add_column(:ptables, :os_family, :string)
> 0.0018s
-
remove_column(:ptables, :operatingsystem_id)
-> 0.0116s
AddOsFamilyToPtable: migrated (0.0330s) =================================
  • Invoke db:schema:dump (first_time)
  • Invoke environment
  • Execute db:schema:dump

I used bundler, and he gems are in $HOME (gem: --user-install in the gemrc)

[foreman@ms1 foreman]$ gem list --local

  • LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.15)
actionpack (3.0.15)
activemodel (3.0.15)
activerecord (3.0.15)
activeresource (3.0.15)
activesupport (3.0.15)
ancestry (1.2.5)
archive-tar-minitar (0.5.2)
arel (2.0.10)
audited (3.0.0.rc1)
audited-activerecord (3.0.0.rc1)
awesome_print (1.0.2)
bigdecimal (1.1.0)
builder (2.1.2)
bundle (0.0.1)
bundler (1.1.4)
columnize (0.3.6)
erubis (2.6.6)
excon (0.14.1)
formatador (0.2.3)
hirb (0.6.2)
hirb-unicode (0.0.5)
i18n (0.5.0)
io-console (0.3)
jquery-rails (1.0.19)
json (1.7.3, 1.5.4)
linecache19 (0.5.12)
mail (2.2.19)
metaclass (0.0.1)
mime-types (1.19)
minitest (2.5.1)
mocha (0.11.4)
multi_json (1.3.6)
mysql (2.8.1)
mysql2 (0.2.18)
net-ldap (0.3.1)
net-scp (1.0.4)
net-ssh (2.5.2)
nokogiri (1.5.5)
pg (0.14.0)
polyglot (0.3.3)
rack (1.2.5)
rack-mount (0.6.14)
rack-test (0.5.7)
rails (3.0.15)
railties (3.0.15)
rake (0.9.2.2)
rbovirt (0.0.12)
rbvmomi (1.5.1)
rdoc (3.12, 3.9.4)
rest-client (1.6.7)
rr (1.0.4)
ruby-debug-base19 (0.11.25)
ruby-debug19 (0.11.6)
ruby-hmac (0.4.0)
ruby2ruby (1.3.1)
ruby_core_source (0.1.5)
ruby_parser (2.3.1)
rubygems-update (1.8.24)
safemode (1.0.1)
scoped_search (2.3.7)
sexp_processor (3.2.0)
shoulda (3.0.1)
shoulda-context (1.0.0)
shoulda-matchers (1.0.0)
sqlite3 (1.3.6)
thor (0.14.6)
treetop (1.4.10)
trollop (1.16.2)
tzinfo (0.3.33)
unicode-display_width (0.1.1)
uuidtools (2.1.2)
will_paginate (3.0.3)
wirb (0.4.2)

[1] http://pastie.org/pastes/3540977
[2] http://www.pastie.org/pastes/3810833


Related issues

Is duplicate of Foreman - Bug #1707: db:migrate fail on in bookmark.rb with ruby1.9Closed2012-06-25

History

#1 Updated by Ohad Levy almost 7 years ago

  • Status changed from New to Duplicate

Also available in: Atom PDF