Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

DataObjects error when using two repositories #20

Open
jvalrog opened this issue Jan 4, 2012 · 6 comments
Open

DataObjects error when using two repositories #20

jvalrog opened this issue Jan 4, 2012 · 6 comments

Comments

@jvalrog
Copy link

jvalrog commented Jan 4, 2012

I have this simple code using two sqlite stores:

require "data_mapper"

class Foo
    include DataMapper::Resource

    property :id, Serial
    property :name, String
end

DataMapper.finalize

DataMapper.setup(:default, "sqlite:foo.sqlite")
DataMapper.setup(:lite, "sqlite:foo2.sqlite")

DataMapper.repository(:default).auto_migrate!
DataMapper.repository(:lite).auto_migrate!

# :default repo
Foo.create(:name => "foo")

# :lite repo
DataMapper.repository(:lite) { Foo.create(:name => "bar") }

Default repository works, but Lite repository throws this error:

/usr/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:114:in `execute_non_query': no such table: foos (DataObjects::SyntaxError)
    from /usr/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:114:in `block (2 levels) in create'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:276:in `with_connection'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:113:in `block in create'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:85:in `each'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:85:in `create'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/repository.rb:146:in `create'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/resource/persistence_state/transient.rb:61:in `create_resource'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/resource/persistence_state/transient.rb:25:in `commit'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/resource.rb:956:in `_persist'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/resource.rb:970:in `block in create_with_hooks'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/resource.rb:967:in `catch'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/resource.rb:967:in `create_with_hooks'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/resource.rb:1021:in `save_self'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-validations-1.2.0/lib/dm-validations.rb:54:in `save_self'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/resource.rb:1006:in `block in _save'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/resource.rb:1222:in `run_once'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/resource.rb:1005:in `_save'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/resource.rb:405:in `save'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-validations-1.2.0/lib/dm-validations.rb:40:in `block in save'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-validations-1.2.0/lib/dm-validations/context.rb:16:in `in_context'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-validations-1.2.0/lib/dm-validations.rb:40:in `save'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-validations-1.2.0/lib/dm-validations.rb:130:in `create'
    from foo.rb:22:in `block in <main>'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core.rb:263:in `block in repository'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/repository.rb:114:in `scope'
    from /usr/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core.rb:263:in `repository'
    from foo.rb:22:in `<main>'

Is this a bug?

I'm using recently updated gems:

data_objects (0.10.7)
datamapper (1.2.0)
dm-aggregates (1.2.0)
dm-constraints (1.2.0)
dm-core (1.2.0)
dm-do-adapter (1.2.0)
dm-migrations (1.2.0)
dm-mysql-adapter (1.2.0)
dm-serializer (1.2.1)
dm-sqlite-adapter (1.2.0)
dm-timestamps (1.2.0)
dm-transactions (1.2.0)
dm-types (1.2.1)
dm-validations (1.2.0)
do_mysql (0.10.7)
do_sqlite3 (0.10.7)

and my ruby version:

ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
@tcwinn
Copy link

tcwinn commented Jul 15, 2012

I'm also observing this issue (see below error). The same code worked under dm 1.0.2.

Here are my gem list:
[root@mimic-scale rack]# gem list

*** LOCAL GEMS ***

addressable (2.2.8)
bcrypt-ruby (3.0.1)
daemon_controller (1.0.0)
data_mapper (1.2.0)
data_objects (0.10.8)
dm-aggregates (1.2.0)
dm-constraints (1.2.0)
dm-core (1.2.0)
dm-do-adapter (1.2.0)
dm-migrations (1.2.0)
dm-mysql-adapter (1.2.0)
dm-serializer (1.2.1)
dm-timestamps (1.2.0)
dm-transactions (1.2.0)
dm-types (1.2.1)
dm-validations (1.2.0)
do_mysql (0.10.8)
fastercsv (1.5.5)
fastthread (1.0.7)
json (1.6.7)
json_pure (1.6.7)
multi_json (1.0.4)
nokogiri (1.5.5)
passenger (3.0.13)
rack (1.4.1)
rake (0.9.2.2)
stringex (1.3.3)
uuidtools (2.1.2)

/opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:114:in execute_non_query': Table 'cl_1.nodes' doesn't exist (DataObjects::SyntaxError) from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:114:increate'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:276:in with_connection' from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:113:increate'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:85:in each' from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:85:increate'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/repository.rb:146:in create' from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/resource/persistence_state/transient.rb:61:increate_resource'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/resource/persistence_state/transient.rb:25:in commit' from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/resource.rb:956:in_persist'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/resource.rb:970:in create_with_hooks' from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/resource.rb:967:incatch'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/resource.rb:967:in create_with_hooks' from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/resource.rb:1021:insave_self'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/resource.rb:1006:in _save' from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/resource.rb:1222:inrun_once'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/resource.rb:1005:in _save' from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/resource.rb:405:insave'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/model.rb:717:in __send__' from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/model.rb:717:in _create'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/model.rb:457:increate' from dm_create.rb:46 from dm_create.rb:44:in each'
from dm_create.rb:44
from dm_create.rb:42:inopen' from dm_create.rb:42 from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core.rb:263:in repository'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/repository.rb:114:inscope' from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core.rb:263:in repository'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/dm-core-1.2.0/lib/dm-core/core_ext/kernel.rb:20:inrepository' from dm_create.rb:39 from dm_create.rb:37:in each'
from dm_create.rb:37

@jonasschneider
Copy link

Same problem here as well. Anybody have an idea what could be the cause?

@dbussink
Copy link
Contributor

You are probably creating two in memory connection which isn't supported. You probably need to use a full path in the URL, if Sqlite can't open the file specified, it will fallback to an in memory connection.

Does this work properly if you use a full path in the url to a file for the database?

@fwolfst
Copy link

fwolfst commented Jul 15, 2014

At least it does not work for me (with dm-core 1.2.1).

The changes to use full path look like:

DataMapper.setup(:default, "sqlite://#{Dir.pwd}/foo.sqlite")
DataMapper.setup(:lite, "sqlite://#{Dir.pwd}/foo2.sqlite")

@fwolfst
Copy link

fwolfst commented Jul 15, 2014

It works if I auto_migrate the model in the repository block like this:

DataMapper.repository(:lite) {
  Foo.auto_migrate!
  Foo.create(:name => "bar")
}

@danielmoralesp
Copy link

thanks @fwolfst works for me!

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

No branches or pull requests

6 participants