Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation: db:prepare with pre-created databases #45

Closed
pglombardo opened this issue Oct 13, 2024 · 4 comments
Closed

Installation: db:prepare with pre-created databases #45

pglombardo opened this issue Oct 13, 2024 · 4 comments

Comments

@pglombardo
Copy link

pglombardo commented Oct 13, 2024

I just deployed solid_cable (latest) to production and hit a few problems. The largest of which was this this from the README:

Then run db:prepare in production to ensure the database is created and the schema is loaded.

db:prepare will only execute if the database doesn't exist.

Problem

For those who use managed databases, the DB is pre-created and the path forward isn't clear.

So I had an empty solid_cable DB with no tables causing app failures.

Failed Solution

I tried bin/rails db:schema:load:cable which errored out with:

TypeError Invalid type for configuration. Expected Symbol, String, or Hash. Got nil

which I didn't investigate unfortunately.

Solution

Copying db/cable_schema.rb to a migration in db/cable_migrate resolved the issue for me.

I'm not sure if this was the best path to resolution but I wanted to point out the obstacle that likely others will hit.

BTW the same problem scenario exists for solid_cache.

@bellenss
Copy link

confirming I bumped into the same issue - the solution / workaround helped me. Thx.

@smarquezs
Copy link

Confirming I faced the same issue and this workaround worked for me, thanks.

@safeforge
Copy link

I'm experiencing similar issues when setting up solid_cable. Specifically, the command rake db:setup:cable depends on db:test:purge:cable, which fails when a test database is not configured.

In my case, I have only the development environment set up for solid_cable with the following configuration:

development:
  primary:
    <<: *default
    database: myapp_development
  cable:
    <<: *default
    migrations_paths: db/cable_migrate
    database: myapp_development_cable

test:
  primary:
    <<: *default
    database: myapp_test

Attempting to run rails db:schema:load:cable results in:

bin/rails aborted!
TypeError: Invalid type for configuration. Expected Symbol, String, or Hash. Got nil (TypeError)

        raise TypeError, "Invalid type for configuration. Expected Symbol, String, or Hash. Got #{config.inspect}"
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Tasks: TOP => db:schema:load:cable => db:test:purge:cable
(See full trace by running task with --trace)

From what I can see in activerecord-8.0.1/lib/active_record/railties/databases.rake, the db:test:purge:cable task attempts to purge the test database, even when one isn’t explicitly configured.

# desc "Empty the #{name} test database"
namespace :purge do
  task name => %w(load_config check_protected_environments) do
    ActiveRecord::Tasks::DatabaseTasks.with_temporary_pool_for_each(env: "test", name: name) do |pool|
      db_config = pool.db_config
      ActiveRecord::Tasks::DatabaseTasks.purge(db_config)
    end
  end
end

I'm wondering if it's necessary to define test environment entries in database.yml, even when the solid_cable adapter is configured only for development in cable.yml.

development:
  adapter: solid_cable
  connects_to:
    database:
      writing: cable
  polling_interval: 0.5.seconds
  message_retention: 1.day

test:
  adapter: test

Of course, the same behavior occurs across all solid_{cable, cache, queue}.

@npezza93
Copy link
Collaborator

Happy to take any updates to the readme for this but it sounds like a test db wasnt being configured for cable. bin/rails db:schema:load:cable should do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@safeforge @bellenss @pglombardo @npezza93 @smarquezs and others