简体   繁体   中英

Ruby-on-Rails Capistrano deployment — database location

Up to now I have been test-deploying my application with the database folder in it's standard location. On the server it ends up located at: project/current/db . The obvious issue is that the database gets over-written each time the app is deployed. To eliminate this I added the database folder to the list of :linked_dirs , so the line in deploy.rb becomes:

append :linked_dirs, "db", "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"

After deploying with this setting, the app does not run, issuing the error:

Showing /home/deploy/gps_monitor/releases/20190824124626/app/views/gps_messages/index.html.erb where line #14 raised:

SQLite3::SQLException: no such table: gps_messages

Troubleshooting the new deployment showed that the files "seeds.rb, schema.rb and migrate (folder)" were missing in the newly linked db folder.

The Cap logs show that the repository is first cloned (placing the missing files in the project/current/db directory, then that directory is deleted and replaced with the link to project/shared/db .

I suppose I could figure out some kind of workaround, but I would think there would be a standard method for preventing this issue. The sequence should be

1) clone the repo
2) create the project/shared/db folder
3) cp project/current/db/*  project/shared/db
4) rm project/current/db
5) create symlink

Surely I'm not the only one to experience this, what is the conventional solution?

Capistrano Version: 3.11.0 (Rake Version: 12.3.3)
Rails 6.0.0.beta3
ruby 2.6.2p47 (2019-03-13 revision 67232) [armv7l-linux-eabihf]

Thanks for any help.

Try linking the files you need and not the whole dir:

set :linked_files, fetch(:linked_files, [])+%W{db/somefile.yml db/another_file.sqlite}

and remove db from the linked_dirs array

My original 'sequence' above will not work. Seeds.rb, schema.rb and the migrate folder must NOT be in the project/shared folder, as it would prevent subsequent deployments from updating the database.

I resolved this issue by adding "db/shared" to the :linked_dirs list, and changing database.yml to show the database at db/shared/production.sqlite3

Database is at: project/shared/db/shared/production.sqlite3

Link is: project/current/db/shared -> project/shared/db/shared

Seeds, schema and migrate are all where originally placed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM