Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Use in production? #4

Closed
Tuckie opened this issue Nov 24, 2015 · 2 comments
Closed

Use in production? #4

Tuckie opened this issue Nov 24, 2015 · 2 comments

Comments

@Tuckie
Copy link

Tuckie commented Nov 24, 2015

Is there any way to use this in production or in development mode? I would like to use this as a lightweight memory cache (while also not having to rework a ton of gems that expect ActiveRecord)

The error:

rails s
=> Booting WEBrick
=> Rails 4.2.4 application starting in development on ******
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Creating sqlite :memory: database
== 20151120220154 CreateEmails: migrating =====================================
-- create_table(:emails)
   -> 0.0013s
== 20151120220154 CreateEmails: migrated (0.0014s) ============================

== 20151121201244 CreateAttachments: migrating ================================
-- create_table(:attachments)
   -> 0.0012s
== 20151121201244 CreateAttachments: migrated (0.0012s) =======================

== 20151124191325 AddDocumentToAttachment: migrating ==========================
-- add_column(:attachments, :identifier, :string)
   -> 0.0004s
-- add_column(:attachments, :original_filename, :string)
   -> 0.0004s
-- add_column(:attachments, :content_type, :string)
   -> 0.0003s
-- add_column(:attachments, :size, :integer)
   -> 0.0003s
-- add_column(:attachments, :data, :binary)
   -> 0.0004s
== 20151124191325 AddDocumentToAttachment: migrated (0.0022s) =================

[2015-11-24 16:24:03] INFO  WEBrick 1.3.1
[2015-11-24 16:24:03] INFO  ruby 2.2.3 (2015-08-18) [x86_64-linux]
[2015-11-24 16:24:03] INFO  WEBrick::HTTPServer#start: pid=7568 port=3000

Started GET "/emails/new" for 10.4.2.117 at 2015-11-24 16:25:14 -0500

ActiveRecord::PendingMigrationError (

Migrations are pending. To resolve this issue, run:

        bin/rake db:migrate RAILS_ENV=development

):
...

I am currently using:

    rails (4.2.4)
    spring (1.4.4)
    memory_test_fix (1.3.0)

database.yml:

default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000
  database: ":memory:"
  migrate: true

development:
  <<: *default
  #database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  #database: db/test.sqlite3

production:
  <<: *default
  #database: db/production.sqlite3
@mvz
Copy link
Owner

mvz commented Nov 26, 2015

That's an interesting use case, but one that isn't provided for explicitly.

One problem may be that Rails tries to open several connections to the same database. Each connection gets a fresh database that will have to have its schema initialized. I think this is why you get the PendingMigrationError. In test mode, there are already some cases where a new connection is established, e.g., when Spring forks off a test runner. Memory_test_fix takes care of initializing the schema in those cases.

You would probably need to hook in to ActiveRecord::Base.establish_connection and call MemoryTestFix::SchemaLoader.init_schema there. This is currently done only for Rails 4.0 as it is not needed for the testing environment in later versions of Rails. Please be aware that each connection will have its own set of data; I'm not sure this is what you want.

@mvz
Copy link
Owner

mvz commented Feb 23, 2016

I moved this Q&A to the Wiki.

@mvz mvz closed this as completed Feb 23, 2016
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

2 participants