On Wednesday, February 25, 2015 at 9:17:42 AM UTC-8, Janko Marohnić wrote: > > Hello, > > In ActiveRecord migrations I often need to move data due to schema > refactoring. Using ActiveRecord for that is ugly, because I have to > redefine subset of models inside of migration files, and shit gets really > crazy when you have STI or polymorphic associations. I realized Sequel > would be perfect for this task. > > There is just one problem: all ActiveRecord migrations are run inside a > transaction, which means that a Sequel::Postgres::Database instance, which > holds a separate database connection, can't execute queries. Sequel is > waiting for the transaction to finish, while ActiveRecord will finish the > transaction only when the migration finishes, resulting in a deadlock. > > I was thinking that it would be great if I could somehow pass the same > connection to Sequel. I was looking in the source code, and I saw > Sequel::Postgres::Adapter is inheriting from PG::Connection. Could it maybe > be implemented in a way that it uses composition, delegating everything to > a PG::Connection instance? I would like to be able to write something like: > > connection = ActiveRecord::Base.connection.raw_connection > #=> #<PG::Connection:0x007fc77aae5f08 ...> > DB = Sequel::Postgres::Adapter.new(connection) >
No, it can't. Even if the postgres adapter could be changed to not subclass PG::Connection, your code wouldn't work as Sequel uses a connection pool, not a single connection, and it creates the connection, you don't pass the connection in. Some people have had some luck making ActiveRecord use connections from Sequel's connection pool, maybe they can chime in with details. A better strategy might be to use Sequel's migrator for migrations, instead of ActiveRecord's. That's probably easier and more robust than trying to make Sequel and ActiveRecord share connections. Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
