Git Product home page Git Product logo

Comments (6)

solnic avatar solnic commented on August 29, 2024

@paddor I can see that you have a method that creates the table in the relation class - this is probably the culprit because if you load relation classes without tables in the db, then inferring schemas can fail. Try moving this method to a different place. In general do not load relations and finalize rom setup if there are no tables yet. You can have db management tasks (create, drop, migrate etc.) with just rom configuration instantiated - there's no need for a finalized rom container.

from rom-sql.

paddor avatar paddor commented on August 29, 2024

@solnic I'm not sure if I understand correctly. I'm assuming by loading you mean the registration of the class in the config? The table creation is in a class method, called after creating the config and before creating a ROM container.

This is how the config and the container are instanciated:

          def initialize(uri)
            @config = ROM::Configuration.new :sql, uri do |config|
              config.register_relation Relation
              config.default.use_logger log
            end
          end


          def setup
            Relation.create_current_cases_table @config.gateways[:default]

            @container = ::ROM.container @config
            @repo = Repo.new @container
          end

#setup is called after initialization.

Should @config.register_relation Relation be done after creating the table?

from rom-sql.

paddor avatar paddor commented on August 29, 2024

The thing is that this error (failed to infer DB schema and thus methods like #by_path missing) also occured when the table already existed.

from rom-sql.

solnic avatar solnic commented on August 29, 2024

I'm assuming by loading you mean the registration of the class in the config?

Yes

The thing is that this error (failed to infer DB schema and thus methods like #by_path missing) also occured when the table already existed.

OK then disregard what I wrote. This is a tough one especially that there's no reproduction script. Auto-restriction methods are defined in the 'configuration.relations.schema.set' event which is triggered after a relation schema was established - this means there should be a table ready.

Notice that these methods are only defined for indexed columns - are you sure indices are defined in the db?

from rom-sql.

paddor avatar paddor commented on August 29, 2024

This was the DB schema:

sqlite3 current_cases.sqlite3 ".schema"
CREATE TABLE `current_cases` (`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `path` varchar(255) NOT NULL UNIQUE, `object` blob NOT NULL);

Sometimes it worked, sometimes it didn't. The schema did not change.

I don't know if SQLite creates indices for PRIMARY KEY and UNIQUE columns.

from rom-sql.

solnic avatar solnic commented on August 29, 2024

@paddor yes it does. Would it be possible for you to create a reproduction script that mimics your prod setup?

from rom-sql.

Related Issues (20)

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.