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

Running bin/setup fails after generating a new app #1224

Open
stevepolitodesign opened this issue Aug 16, 2024 · 3 comments
Open

Running bin/setup fails after generating a new app #1224

stevepolitodesign opened this issue Aug 16, 2024 · 3 comments
Labels

Comments

@stevepolitodesign
Copy link
Contributor

When I run bin/setup in a newly generated app, I get the following error:

       rails  db:prepare
Created database 'fail_development'
Created database 'fail_test'

Congratulations! You just pulled our suspenders.

~/Sites via 💎 v3.3.0 on ☁️    took 3m59s
❯ v

~/Sites via 💎 v3.3.0 on ☁️    took 2s
❯ cd fail

fail on  main [?] via  v22.1.0 via 💎 v3.3.0 on ☁️
❯ bin/setup
== Installing dependencies ==
The Gemfile's dependencies are satisfied
yarn install v1.22.17
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning " > @thoughtbot/[email protected]" has unmet peer dependency "jest@>= 25.0.0".
warning " > @thoughtbot/[email protected]" has unmet peer dependency "typescript@>= 4.0.0".
warning "@thoughtbot/eslint-config > @typescript-eslint/eslint-plugin > [email protected]" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[4/4] 🔨  Building fresh packages...
✨  Done in 0.88s.

== Preparing database and adding development seed data ==
Database 'fail_development' already exists
Database 'fail_test' already exists
/Users/polito/Sites/fail/db/schema.rb doesn't exist yet. Run `bin/rails db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter /Users/polito/Sites/fail/config/application.rb to limit the frameworks that will be loaded.
bin/setup:9:in `system': Command failed with exit 1: bin/rails (RuntimeError)
        from bin/setup:9:in `system!'
        from bin/setup:24:in `block in <main>'
        from /Users/polito/.asdf/installs/ruby/3.3.0/lib/ruby/3.3.0/fileutils.rb:240:in `chdir'
        from /Users/polito/.asdf/installs/ruby/3.3.0/lib/ruby/3.3.0/fileutils.rb:240:in `cd'
        from bin/setup:16:in `<main>'

About your application's environment
Rails version             7.2.0
Ruby version              ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
RubyGems version          3.5.6
Rack version              3.1.7
Middleware                ActionDispatch::HostAuthorization, Rack::Sendfile, ActionDispatch::Static, ActionDispatch::Executor, ActionDispatch::ServerTiming, ActiveSupport::Cache::Strategy::LocalCache::Middleware, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, ActionDispatch::RemoteIp, Sprockets::Rails::QuietAssets, Rails::Rack::Logger, ActionDispatch::ShowExceptions, WebConsole::Middleware, ActionDispatch::DebugExceptions, ActionDispatch::ActionableExceptions, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ContentSecurityPolicy::Middleware, ActionDispatch::PermissionsPolicy::Middleware, Rack::Head, Rack::ConditionalGet, Rack::ETag, Rack::TempfileReaper
Application root          /Users/polito/Sites/fail
Environment               development
Database adapter          postgresql
Database schema version   0
@stevepolitodesign
Copy link
Contributor Author

stevepolitodesign commented Aug 16, 2024

Our application template invokes bin/rails db:prepare, which is what the Rails does in its bin/setup script.

Even invoking bin/rails db:prepare again within the newly generated application has no affect.

Running bin/rails db:migrate did the trick.

@stevepolitodesign
Copy link
Contributor Author

I wonder if we need to remove rails_command "db:prepare" from the application template and instead add it to our custom setup script?

@stevepolitodesign stevepolitodesign changed the title Running bin/setup files after generating a new app Running bin/setup fails after generating a new app Aug 16, 2024
@stevepolitodesign
Copy link
Contributor Author

For context, this is what bin/setup looks like for a new Rails application.

#!/usr/bin/env ruby
require "fileutils"

APP_ROOT = File.expand_path("..", __dir__)
APP_NAME = "setup-script"

def system!(*args)
  system(*args, exception: true)
end

FileUtils.chdir APP_ROOT do
  # This script is a way to set up or update your development environment automatically.
  # This script is idempotent, so that you can run it at any time and get an expectable outcome.
  # Add necessary setup steps to this file.

  puts "== Installing dependencies =="
  system! "gem install bundler --conservative"
  system("bundle check") || system!("bundle install")

  # puts "\n== Copying sample files =="
  # unless File.exist?("config/database.yml")
  #   FileUtils.cp "config/database.yml.sample", "config/database.yml"
  # end

  puts "\n== Preparing database =="
  system! "bin/rails db:prepare"

  puts "\n== Removing old logs and tempfiles =="
  system! "bin/rails log:clear tmp:clear"

  puts "\n== Restarting application server =="
  system! "bin/rails restart"

  # puts "\n== Configuring puma-dev =="
  # system "ln -nfs #{APP_ROOT} ~/.puma-dev/#{APP_NAME}"
  # system "curl -Is https://#{APP_NAME}.test/up | head -n 1"
end

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

No branches or pull requests

1 participant