Ruby-on-rails 如何在终端中查看 Heroku 应用程序的当前数据库架构?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15953390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:48:26  来源:igfitidea点击:

How to view current database schema for Heroku app in Terminal?

ruby-on-railsherokuterminalschema

提问by vich

I am trying to view my Heroku app's schema in Terminal (Mac OS X Lion) and stumbled upon a command that does just that. In Terminal, I run heroku run more db/schema.rbbut it seems to display an older schema version. I just migrated the Heroku db and I noticed that none of the new columns are listed.

我正在尝试在终端(Mac OS X Lion)中查看我的 Heroku 应用程序的架构,并偶然发现了一个执行此操作的命令。在终端中,我运行heroku run more db/schema.rb但它似乎显示较旧的架构版本。我刚刚迁移了 Heroku 数据库,我注意到没有列出任何新列。

I can't seem to find anything helpful in Heroku's documentation. Does anyone know a command to view the current database schema for a Heroku app?

我似乎在 Heroku 的文档中找不到任何有用的东西。有谁知道查看 Heroku 应用程序当前数据库架构的命令?

By the way, I inherited the code for the app and for some reason all of the migration files are commented out (there are probably 40+ files) so I can't just run rake db:migratelocally to update the schema; hence, I'd like to see the Heroku app's schema directly.

顺便说一下,我继承了应用程序的代码,出于某种原因,所有迁移文件都被注释掉了(可能有 40 多个文件),所以我不能只在rake db:migrate本地运行来更新架构;因此,我想直接查看 Heroku 应用程序的架构。

Any suggestions?

有什么建议?

回答by Chowlett

You could run heroku pg:psqlto fire up a Postgres console, then issue \dto see all tables, and \d tablenameto see details for a particular table.

您可以运行heroku pg:psql以启动 Postgres 控制台,然后发出\d以查看所有表,并\d tablename查看特定表的详细信息。

回答by kch

For a rails schema, try:

对于 rails 架构,请尝试:

$ heroku run "bundle exec rake db:schema:dump && cat db/schema.rb"

回答by kartouch

You can use rateaux:

您可以使用rateaux

rake db:view:schema