Comments (6)
@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.
@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.
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.
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.
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.
@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)
- Legacy schema
- Multi_insert returns more results than expected in some specific conditions HOT 5
- Attribute methods not available *within* a relation, but are *outside* of a relation HOT 4
- create returns nil for custom primary keys HOT 4
- OVER clause lost from row_number functions. HOT 9
- Postgres Upsert command does not support specifying index predicate for partial unique indices
- Translate symbols in a hash applied to `Relation#where` to attributes HOT 1
- "undefined method `stream'" when trying to use the `:pg_streaming` plugin HOT 2
- Multi-Schema database HOT 1
- Relation#multi_insert fails with blob data HOT 4
- Add a custom `Create` command for sqlite
- Use of projection dsl is not available in Relation#exclude
- Support for ANY in condition DSL HOT 5
- Error when attempting to join relations across different databases HOT 3
- [Migration] schema_migrations and schema_info tables error HOT 2
- Support virtual columns in `union` queries
- Problem with :create command and custom types HOT 2
- `by_pk` causes stack overflow when used with single primary key while table define composite primary key
- SQLite doesn't cast 1/0 to true and false HOT 5
- Relation#last removes combines HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rom-sql.