Launch and deploy success but database seems empty, may need help with seeding

Hi, hi! I’m a new user of fly and I’m having trouble with deploying my school projects. I was trying to navigate errors with launching. After updating Ruby and Rails and manually attaching the PostgreSQL database, I was able to launch and was optimistic about the next steps.
However, when I click the deployment hostname, I notice my site isn’t loading like expected.
This is what it currently looks like…



…even though this is what I’m aiming for and what I get while running on localhost.



At first, I thought it had to do with the s3 buckets, but then even the pink bubbles would be affected as they depend on links to the s3 bucket images. I think the database is not seeding, so I tried changing line 13 in fly.rake from db:migrate to db:prepare so that it would create, seed from seeds.rb, and migrate in one line. However, when deleting Dockerfile, fly.toml, and fly. rake and redoing the launch steps, the site still has the same problem.
Does anyone know if I’m missing some steps?



Here is also my Gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.0.4'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.0'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

gem "aws-sdk-s3"

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'

# need to be on toplevel or will not be accessible to production
gem 'jquery-rails'

# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  gem 'pry-rails'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of chromedriver to run system tests with Chrome
  gem 'chromedriver-helper'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

…my fly.rake file…

# commands used to deploy a Rails application
namespace :fly do
  # BUILD step:
  #  - changes to the filesystem made here DO get deployed
  #  - NO access to secrets, volumes, databases
  #  - Failures here prevent deployment
  task :build => 'assets:precompile'

  # RELEASE step:
  #  - changes to the filesystem made here are DISCARDED
  #  - full access to secrets, databases
  #  - failures here prevent deployment
  task :release => 'db:prepare'

  # SERVER step:
  #  - changes to the filesystem made here are deployed
  #  - full access to secrets, databases
  #  - failures here result in VM being stated, shutdown, and rolled back
  #    to last successful deploy (if any).
  task :server => :swapfile do
    sh 'bin/rails server'
  end

  # optional SWAPFILE task:
  #  - adjust fallocate size as needed
  #  - performance critical applications should scale memory to the
  #    point where swap is rarely used.  'fly scale help' for details.
  #  - disable by removing dependency on the :server task, thus:
  #        task :server do
  task :swapfile do
    sh 'fallocate -l 512M /swapfile'
    sh 'chmod 0600 /swapfile'
    sh 'mkswap /swapfile'
    sh 'echo 10 > /proc/sys/vm/swappiness'
    sh 'swapon /swapfile'
  end
end

…my Dockerfile

# commands used to deploy a Rails application
namespace :fly do
  # BUILD step:
  #  - changes to the filesystem made here DO get deployed
  #  - NO access to secrets, volumes, databases
  #  - Failures here prevent deployment
  task :build => 'assets:precompile'

  # RELEASE step:
  #  - changes to the filesystem made here are DISCARDED
  #  - full access to secrets, databases
  #  - failures here prevent deployment
  task :release => 'db:prepare'

  # SERVER step:
  #  - changes to the filesystem made here are deployed
  #  - full access to secrets, databases
  #  - failures here result in VM being stated, shutdown, and rolled back
  #    to last successful deploy (if any).
  task :server => :swapfile do
    sh 'bin/rails server'
  end

  # optional SWAPFILE task:
  #  - adjust fallocate size as needed
  #  - performance critical applications should scale memory to the
  #    point where swap is rarely used.  'fly scale help' for details.
  #  - disable by removing dependency on the :server task, thus:
  #        task :server do
  task :swapfile do
    sh 'fallocate -l 512M /swapfile'
    sh 'chmod 0600 /swapfile'
    sh 'mkswap /swapfile'
    sh 'echo 10 > /proc/sys/vm/swappiness'
    sh 'swapon /swapfile'
  end
end

…and fly.toml.

# fly.toml file generated for mooguri-00 on 2022-10-20T20:56:44-07:00

app = "mooguri-00"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  [build.args]
    BUILD_COMMAND = "bin/rails fly:build"
    SERVER_COMMAND = "bin/rails fly:server"

[deploy]
  seed_command = "bin/rails fly:seed"
  release_command = "bin/rails fly:release"

[env]
  PORT = "8080"

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 8080
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

[[statics]]
  guest_path = "/app/public"
  url_prefix = "/"

Two commands that are helpful exploring your database:

flyctl ssh console -C '/app/bin/rails console'
flyctl ssh console -C '/app/bin/rails dbconsole'
1 Like

Thank you for these commands! I’ll definitely add these to my notes for checking the database.
When I run this first command and try to list all the instances of some of the tables, I notice they are empty arrays:

irb(main):001:0> User.all
D, [2022-10-30T03:15:25.098136 #618] DEBUG -- :   User Load (0.8ms)  SELECT "users".* FROM "users"
=> []
irb(main):002:0> Product.all
D, [2022-10-30T03:15:29.668513 #618] DEBUG -- :   Product Load (1.2ms)  SELECT "products".* FROM "products"
=> []
irb(main):003:0> Cart.all
D, [2022-10-30T03:15:32.101821 #618] DEBUG -- :   Cart Load (1.2ms)  SELECT "carts".* FROM "carts"
=> []

And, when I run the second command, I notice I’m able to list out the tables but I don’t think I’m getting anything back when making a query.

psql (11.17 (Debian 11.17-0+deb10u1), server 14.4 (Debian 14.4-1.pgdg110+1))
WARNING: psql major version 11, server major version 14.
         Some psql features might not work.
Type "help" for help.

mooguri_00=# \d
                         List of relations
 Schema |               Name                |   Type   |   Owner    
--------+-----------------------------------+----------+------------
 public | active_storage_attachments        | table    | mooguri_00
 public | active_storage_attachments_id_seq | sequence | mooguri_00
 public | active_storage_blobs              | table    | mooguri_00
 public | active_storage_blobs_id_seq       | sequence | mooguri_00
 public | ar_internal_metadata              | table    | mooguri_00
 public | carts                             | table    | mooguri_00
 public | carts_id_seq                      | sequence | mooguri_00
 public | products                          | table    | mooguri_00
 public | products_id_seq                   | sequence | mooguri_00
 public | reviews                           | table    | mooguri_00
 public | reviews_id_seq                    | sequence | mooguri_00
 public | schema_migrations                 | table    | mooguri_00
 public | users                             | table    | mooguri_00
 public | users_id_seq                      | sequence | mooguri_00
(14 rows)

mooguri_00=# SELECT * FROM users
mooguri_00-# SELECT * FROM carts
mooguri_00-# SELECT * FROM products
mooguri_00-# 

UPDATE: After learning to run the first command of flyctl ssh console -C '/app/bin/rails console', I ran Rails.application.load_seed in the rails console and it seemed to seed the database except it is not complete:

There are supposed to be about 40-60 instances of products but only one shows up. And, it seems it has now affected the pink bubbles on the splash page:

Does running db:seed by itself produce any errors? Run the following commands in two separate windows:

flyctl logs
flyctl ssh console -C '/app/bin/rails db:seed'
1 Like

Oh dang! I noticed an error that repeats when running flyctl logs: ActionView::Template::Error (to_model delegated to attachment, but attachment is nil):

And it led me to think that it did have to relate to the s3 buckets. I made them public and edited the bucket policy, ran flyctl deploy, opened the link to check, and it works now!
And, it still works after blocking public access and making the policy private again :sweat_smile:

Thank you for teaching me those commands! :handshake: