简体   繁体   English

Ruby-on-Rails Capistrano部署-数据库位置

[英]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 . 在服务器上,它最终位于: 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: 为了消除这种情况,我将数据库文件夹添加到:linked_dirs列表中,因此deploy.rb中的行变为:

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. 对新部署进行故障排除表明,新链接的db文件夹中缺少文件“ seeds.rb,schema.rb和迁移(文件夹)”。

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 . Cap日志显示,首先克隆了存储库(将丢失的文件放置在project / current / db目录中,然后将该目录删除,并替换为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 并从linked_dirs数组中删除db

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. Seeds.rb,schema.rb和migration文件夹不得位于project / shared文件夹中,因为这将阻止后续部署更新数据库。

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 我通过将“ db / shared”添加到:linked_dirs列表中,并更改了database.yml以在db / shared / production.sqlite3中显示数据库,解决了此问题。

Database is at: project/shared/db/shared/production.sqlite3 数据库位于: 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. 种子,模式和迁移全部位于原始位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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