Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table doesn't exist during db:migrate #72

Open
josephbridgwaterrowe opened this issue Mar 3, 2015 · 8 comments
Open

Table doesn't exist during db:migrate #72

josephbridgwaterrowe opened this issue Mar 3, 2015 · 8 comments

Comments

@josephbridgwaterrowe
Copy link

When using ActiveRecord and "resetting" the database with bundle exec rake db:drop db:create db:migrate RAILS_ENV=test I receive the following error:

ActiveRecord::StatementInvalid: Mysql2::Error: Table 'test_chancellor.contacts' doesn't exist: SHOW FULL FIELDS FROM contacts

I believe that this occurs when lib/promiscuous/publisher/model/active_record.rb checks for the existence of the _v column.

This is my new lib/promiscuous/publisher/model/active_record.rb which allows my migrations:

# lib/promiscuous/publisher/model/active_record.rb
module Promiscuous::Publisher::Model::ActiveRecord
  extend ActiveSupport::Concern
  include Promiscuous::Publisher::Model::Base

  require 'promiscuous/publisher/operation/active_record'

  included do
    next unless self.table_exists?

    if !self.columns.collect(&:name).include?("_v")
      raise <<-help
      #{self} must include a _v column.  Create the following migration:
        change_table :#{self.table_name} do |t|
          t.integer :_v, :limit => 8, :default => 1
        end
      help
    end
  end

  module ClassMethods
    def __promiscuous_missing_record_exception
      ActiveRecord::RecordNotFound
    end

    def belongs_to(*args, &block)
      super.tap do |association|
        fk = if association.is_a?(Hash)
               association.values.first.foreign_key  # ActiveRecord 4x
             else
               association.foreign_key  # ActiveRecord 3x
             end
        publish(fk) if self.in_publish_block?
      end
    end
  end
end
@josephbridgwaterrowe
Copy link
Author

I have made this change to my fork at:

https://github.com/josephbridgwaterrowe/promiscuous/tree/tweaks

These are the projects that I'm trying promiscuous in:

https://github.com/westernmilling/chancellor (publisher)
https://github.com/westernmilling/diplomat (subscriber)

@josephbridgwaterrowe
Copy link
Author

May I suggest that the check for the _v column should not be done here. But instead document the requirement that pub/sub'd models need this column and perhaps include a generator as well.

@kareemk
Copy link
Member

kareemk commented Mar 6, 2015

Thanks @josephbridgwaterrowe. I'll take a look at this soon.

@josephbridgwaterrowe
Copy link
Author

@kareemk, would you be interested in consuming this change through a pull request? And if so, I would value some thoughts on how we could test this behavior.

Thanks.

@kareemk
Copy link
Member

kareemk commented Aug 18, 2015

@josephbridgwaterrowe @michaeldauria maintains promiscuous now, i'll let him comment on this.

@josephbridgwaterrowe
Copy link
Author

@kareemk Thank you.
@michaeldauria I have some other suggestions for potentially improving promiscuous with AR.

@samsongz
Copy link

+1

having this problem as well and @josephbridgwaterrowe 's fix resolves it. @michaeldauria is this something you'd consider merging in?

thank you

@josephbridgwaterrowe
Copy link
Author

@samsongz I have another branch on my own fork over here https://github.com/josephbridgwaterrowe/promiscuous/tree/active_record_migrations that moves these checks into a CLI process, it also includes a fix for some issues I was having with AR 4.2.3 savepoints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants