Unable to Reset DB Deployed on Fly.io.

Hello Everyone,
I’m facing an issue with a Rails project deployed on Fly.io. I’m trying to seed initial data into the project, but I’m encountering some challenges.

Steps I’ve Taken:

The following steps were taken to deploy to Fly.io.

  1. Deleted the app and DB from the Fly.io dashboard.
  2. Removed local Dockerfile and fly.toml.
  3. Ran the fly launch command.
  4. Executed the fly deploy command.
  5. Restarted the stopped apps:
❯ fly apps restart  outdoor-heart-sutra-backend
Restarting machine 4d89446c254387
No health checks found
Machine 4d89446c254387 restarted successfully!
Restarting machine 5683d3d3a11778
No health checks found
Machine 5683d3d3a11778 restarted successfully!
  1. Attempted to seed initial data with db:seed:
❯  flyctl ssh console -a outdoor-heart-sutra-backend
Connecting to fdaa:1:d5f8:a7b:db52:9e04:167c:2... complete
root@4d89446c254387:/rails# bin/rails db:seed RAILS_ENV=production
  1. However, only half of the initial data was seeded.
  2. Tried db:reset, but encountered an error (as shown in the provided logs).
❯  flyctl ssh console -a outdoor-heart-sutra-backend
Connecting to fdaa:1:d5f8:a7b:ff:827f:1f30:2... complete
root@5683d3d3a11778:/rails# bin/rails db:reset RAILS_ENV=production
rails aborted!
ActiveRecord::ProtectedEnvironmentError: You are attempting to run a destructive action against your 'production' database.
If you are sure you want to continue, run the same command with the environment variable:
DISABLE_DATABASE_ENVIRONMENT_CHECK=1
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:69:in `check_protected_environments!'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/railties/databases.rake:18:in `block (2 levels) in <main>'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
/rails/vendor/bundle/ruby/3.2.0/gems/sentry-ruby-5.10.0/lib/sentry/rake.rb:26:in `execute'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/command.rb:51:in `invoke'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/commands.rb:18:in `<main>'
/rails/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
Tasks: TOP => db:reset => db:drop => db:check_protected_environments
(See full trace by running task with --trace)
root@5683d3d3a11778:/rails#
  1. Attempted again using the DISABLE_DATABASE_ENVIRONMENT_CHECK=1 flag:
❯  flyctl ssh console -a outdoor-heart-sutra-backend
Connecting to fdaa:1:d5f8:a7b:ff:827f:1f30:2... complete
root@5683d3d3a11778:/rails# DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bin/rails db:reset RAILS_ENV=production
  1. Upon checking the production environment, the initial data submission still did not proceed as expected.

  2. I tried using db:drop to delete the data, but the data was not removed.

❯  flyctl ssh console -a outdoor-heart-sutra-backend
Connecting to fdaa:1:d5f8:a7b:db52:9e04:167c:2... complete
root@4d89446c254387:/rails# DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bin/rails db:drop RAILS_ENV=production
PG::ObjectInUse: ERROR:  database "outdoor_heart_sutra_backend" is being accessed by other users
DETAIL:  There is 1 other session using the database.
Couldn't drop database 'outdoor_heart_sutra_backend'
rails aborted!
ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR:  database "outdoor_heart_sutra_backend" is being accessed by other users
DETAIL:  There is 1 other session using the database.
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:in `exec'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:in `block (2 levels) in execute'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/dependencies/interlock.rb:41:in `permit_concurrent_loads'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:47:in `block in execute'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/abstract_adapter.rb:769:in `block in log'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/abstract_adapter.rb:760:in `log'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:46:in `execute'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/postgresql/schema_statements.rb:54:in `drop_database'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/postgresql_database_tasks.rb:32:in `drop'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:224:in `drop'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:239:in `block in drop_current'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:557:in `block (2 levels) in each_current_configuration'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:554:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:554:in `block in each_current_configuration'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:553:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:553:in `each_current_configuration'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:239:in `drop_current'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/railties/databases.rake:68:in `block (2 levels) in <main>'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
/rails/vendor/bundle/ruby/3.2.0/gems/sentry-ruby-5.10.0/lib/sentry/rake.rb:26:in `execute'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/railties/databases.rake:64:in `block (2 levels) in <main>'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
/rails/vendor/bundle/ruby/3.2.0/gems/sentry-ruby-5.10.0/lib/sentry/rake.rb:26:in `execute'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/command.rb:51:in `invoke'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/commands.rb:18:in `<main>'
/rails/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'

Caused by:
PG::ObjectInUse: ERROR:  database "outdoor_heart_sutra_backend" is being accessed by other users
DETAIL:  There is 1 other session using the database.
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:in `exec'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:in `block (2 levels) in execute'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/dependencies/interlock.rb:41:in `permit_concurrent_loads'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:47:in `block in execute'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/abstract_adapter.rb:769:in `block in log'
/rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/abstract_adapter.rb:760:in `log'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:46:in `execute'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/connection_adapters/postgresql/schema_statements.rb:54:in `drop_database'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/postgresql_database_tasks.rb:32:in `drop'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:224:in `drop'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:239:in `block in drop_current'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:557:in `block (2 levels) in each_current_configuration'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:554:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:554:in `block in each_current_configuration'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:553:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:553:in `each_current_configuration'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/tasks/database_tasks.rb:239:in `drop_current'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/railties/databases.rake:68:in `block (2 levels) in <main>'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
/rails/vendor/bundle/ruby/3.2.0/gems/sentry-ruby-5.10.0/lib/sentry/rake.rb:26:in `execute'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
/rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.6/lib/active_record/railties/databases.rake:64:in `block (2 levels) in <main>'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
/rails/vendor/bundle/ruby/3.2.0/gems/sentry-ruby-5.10.0/lib/sentry/rake.rb:26:in `execute'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
/rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/command.rb:51:in `invoke'
/rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.6/lib/rails/commands.rb:18:in `<main>'
/rails/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
Tasks: TOP => db:drop:_unsafe
(See full trace by running task with --trace)

What I’d Like to Know:

  1. How can I successfully execute db:reset?
  2. I want to use Rails’ db:seed to seed the initial data present in the backend/db/seeds.rb file. How can I achieve this?

Development Environment:

  • React: 18.2.0
  • Next.js: 13.4.6
  • Ruby: 3.2.1
  • Rails API Mode: 7.0.4

When you did this, your fly.toml should contain the following lines:

[deploy]
  release_command = "./bin/rails db:prepare"

db:prepare was added in rails 6 and runs db:seed for you. You shouldn’t need to run it a second time using the shell.

I see.
However, even after initializing Fly.io and trying again, I still can’t execute a correct rails db:seed.
I also can’t perform db:reset.

From the information provided, I don’t know why your db:seed isn’t running as expected.

If for some reason you would rather db:seed not be run during the release process you could change db:prepare to db:migrate in your release task.

Running db:reset may be more involved. You can run fly machines list and then stop all of the outdoor-heart-sutra-backend machines, remove (or comment out) the console_command line in your fly.toml, and then run fly console (no ssh) to get a new ephemeral machine where you can run rails commands.

I initialized Fly.io again and tried again.
I got the following error, does it affect this case?

Error creating Postgresql database. Be warned that this may affect deploys

❯ fly launch
Creating app in /Users/shiro/own/outdoor-heart-sutra/backend
Scanning source code
Detected a Rails app
? Choose an app name (leave blank to generate one): outdoor-heart-sutra-backend
automatically selected personal organization: **** ****
Some regions require a paid plan (bom, fra, maa).
See https://fly.io/plans to set up a plan.

? Choose a region for deployment: Tokyo, Japan (nrt)
App will use 'nrt' region as primary

Created app 'outdoor-heart-sutra-backend' in organization 'personal'
Admin URL: https://fly.io/apps/outdoor-heart-sutra-backend
Hostname: outdoor-heart-sutra-backend.fly.dev
Set secrets on outdoor-heart-sutra-backend: RAILS_MASTER_KEY
? Would you like to set up a Postgresql database now? Yes
For pricing information visit: https://fly.io/docs/about/pricing/#postgresql-clu
? Select configuration: Development - Single node, 1x shared CPU, 256MB RAM, 1GB disk
? Scale single node pg to zero after one hour? No
Creating postgres cluster in organization personal
Creating app...
Setting secrets on app outdoor-heart-sutra-backend-db...
Provisioning 1 of 1 machines with image flyio/postgres-flex:15.3@sha256:02be8dc60aea4fd67587597a44af32af477df92c1e20bd050af2b3bf254fd88e
Failed creating the Postgres cluster outdoor-heart-sutra-backend-db: failed to launch VM: aborted: could not reserve resource for machine: insufficient memory available to fulfill request
Error creating Postgresql database. Be warned that this may affect deploys
? Would you like to set up an Upstash Redis database now? No
      create  Dockerfile
   identical  .dockerignore
    conflict  bin/docker-entrypoint
Overwrite /Users/shiro/own/outdoor-heart-sutra/backend/bin/docker-entrypoint? (enter "h" for help) [Ynaqdhm]
       force  bin/docker-entrypoint
   identical  config/dockerfile.yml
Wrote config file fly.toml
Validating /Users/shiro/own/outdoor-heart-sutra/backend/fly.toml
Platform: machines
✓ Configuration is valid

Your Rails app is prepared for deployment.

Before proceeding, please review the posted Rails FAQ:
https://fly.io/docs/rails/getting-started/dockerfiles/.

Once ready: run 'fly deploy' to deploy your Rails app.

I’m not in operations so somebody else would need to chime in, but this surprises me as from what I can see nrt is not at capacity.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.