Rails 8, sqlite3, rails db:reset

I’m checking out Fly and wow. Pretty great for deploying one off disposable apps - that I can get into ‘prod’. UI is great too. Really great.

I can launch/deploy my app, but then when I need to reset the db, I get this error:

> fly ssh console -C "bundle exec rails db:reset"                                     
> Connecting to fdaa:a:6a0f:a7b:9f67:5464:fbf4:2... complete
> bin/rails aborted!
> ActiveRecord::ProtectedEnvironmentError: You are attempting to run a destructive action against your 'production' database. (ActiveRecord::ProtectedEnvironmentError)
> If you are sure you want to continue, run the same command with the environment variable:
> DISABLE_DATABASE_ENVIRONMENT_CHECK=1

Makes since, try that:

fly ssh console -C "DISABLE_DATABASE_ENVIRONMENT_CHECK=1; bundle exec rails db:reset"
Error: ssh shell: wait: remote command exited without exit status or exit signal

I can destroy and launch again, no worries! But I guess I’d like to know what is wrong as I move forward.

Hi… This is because the above is shell syntax, whereas -C is only a low-level process launch. The following should work—except possibly in really stripped down images:

$ fly ssh console -C "env DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bundle exec rails db:reset"

(No semicolon.)

More generally, you can use a nested, explicit shell invocation, -C "bash -c 'shell syntax here'", in cases in which you do want something more complicated (e.g., && chains, redirections, or pipelines).

Hope this helps!

2 Likes

Added flyctl

Worked great, many many thanks.

1 Like

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