Giter Site home page Giter Site logo

dm-constraints's People

Contributors

balinterdi avatar bernerdschaefer avatar dbussink avatar dkubb avatar emmanuel avatar gcampbell avatar gix avatar michaelklishin avatar myabc avatar namelessjon avatar paul avatar shingara avatar snusnu avatar solnic avatar somebee avatar tillsc avatar xaviershay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dm-constraints's Issues

Quoting of name on mysql

I'm currently running MySQL 5.1.41 and I'm having problems using this gem.

I'm no expert but I'm guessing it has to do with the way names are quoted.
For example here is a debug output of the first query that fails with mysql complaining about the syntax.

SELECT COUNT(*) FROM "information_schema"."table_constraints" WHERE "constraint_type" = 'FOREIGN KEY' AND "table_schema" = 'ultra_dev' AND "table_name" = 'subscriptions' AND "constraint_name" = 'subscriptions_account_fk'

As you can see the names are quoted using normal double quotes and when they are replaced by ` the query runs ok.

Example that works
SELECT COUNT(*) FROM information_schema.table_constraints WHERE constraint_type = 'FOREIGN KEY' AND table_schema = 'ultra_dev' AND table_name = 'subscriptions' AND constraint_name = 'subscriptions_account_fk'

This is probably why dm-mysql-adapter has some special code to handle this.
http://github.com/datamapper/dm-mysql-adapter/blob/master/lib/dm-mysql-adapter/adapter.rb#L34-36

Is this something that could be fixed on this end or do I have something configured wrong?

dm-constraints does not load models correct to infer key

I don't really know how to describe this bug, except in code:

require 'rubygems'
require 'dm-core'
require 'dm-migrations'
require 'dm-constraints'

DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'postgres://localhost/test') # createdb test

class Post
  include DataMapper::Resource

  property :id, Serial
  belongs_to :author
end

class User
  include DataMapper::Resource

  property :id, Serial
end

class Author
  include DataMapper::Resource

  belongs_to :user, :key => true, :child_key => [:id]

  has n, :posts
end


DataMapper.finalize
DataMapper.auto_migrate!

Fails with:

 ~ (0.000255) ALTER TABLE "posts" ADD CONSTRAINT "posts_author_fk" FOREIGN KEY () REFERENCES "authors" () ON DELETE NO ACTION ON UPDATE NO ACTION
 ~ ERROR:  syntax error at or near ")"
LINE 1: ...ts" ADD CONSTRAINT "posts_author_fk" FOREIGN KEY () REFERENC...
                                                             ^
 (code: 16801924, sql state: 42601, query: ALTER TABLE "posts" ADD CONSTRAINT "posts_author_fk" FOREIGN KEY () REFERENCES "authors" () ON DELETE NO ACTION ON UPDATE NO ACTION, uri: postgres://localhost/test)
/Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:63:in `execute_non_query': ERROR:  syntax error at or near ")" (DataObjects::SyntaxError)
LINE 1: ...ts" ADD CONSTRAINT "posts_author_fk" FOREIGN KEY () REFERENC...
                                                             ^
    from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:63:in `block in execute'
    from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:260:in `with_connection'
    from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:61:in `execute'
    from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-constraints-1.0.2/lib/dm-constraints/adapters/dm-do-adapter.rb:64:in `create_relationship_constraint'
    from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-constraints-1.0.2/lib/dm-constraints/migrations.rb:51:in `block in execute_each_relationship'
    from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-constraints-1.0.2/lib/dm-constraints/migrations.rb:50:in `each_value'
    from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-constraints-1.0.2/lib/dm-constraints/migrations.rb:50:in `execute_each_relationship'
    from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-constraints-1.0.2/lib/dm-constraints/migrations.rb:43:in `auto_migrate_up_constraints!'
    from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-migrations-1.0.2/lib/dm-migrations/auto_migration.rb:45:in `block in repository_execute'
    from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-core-1.0.2/lib/dm-core/support/descendant_set.rb:68:in `block in each'
    from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-core-1.0.2/lib/dm-core/support/descendant_set.rb:67:in `each'
    from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-core-1.0.2/lib/dm-core/support/descendant_set.rb:67:in `each'
    from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-migrations-1.0.2/lib/dm-migrations/auto_migration.rb:44:in `repository_execute'
    from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-constraints-1.0.2/lib/dm-constraints/migrations.rb:12:in `auto_migrate!'
    from dm-load-order.rb:32:in `<main>'

The work around is to move the Post definition below the Author definition (or if using autoloading and rails, add a reference to Author at the top of the post.rb file to force it to be loaded before the rest of the file is run)


Created by Xavier Shay - 2010-12-16 02:58:14 UTC

Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1457

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.