简体   繁体   English

如何将现有的Rails应用程序移至heroku? (sqlite到postgres)

[英]How do I move my existing rails app onto heroku? (sqlite to postgres)

I have an existing Ruby on Rails app that already has data loaded into it. 我有一个现有的Ruby on Rails应用程序,已经在其中加载了数据。

I used the default SQLite database setup, so that is where all my data is located, but I need all my data to go into my Postgres database on heroku. 我使用了默认的SQLite数据库设置,因此所有数据都位于该数据库中,但是我需要所有数据才能进入heroku上的Postgres数据库。

How do I do that? 我怎么做?

10 Minutes Move from Local SQLite to a Heroku Postgres 10分钟从本地SQLite移至Heroku Postgres

-- updates your local dev to postgres along the way -- -一路将您的本地开发者更新为Postgres-

This is assuming you have a development database in sqlite and you want to move the structure and data to heroku. 假设您在sqlite中拥有一个开发数据库,​​并且想要将结构和数据移至heroku。 You will be first changing your local environment to postgres, then moving it all up. 您将首先将您的本地环境更改为postgres,然后将其全部上移。

Why change? 为什么要改变? You should always have your development environment mirror your production environment. 您应该始终使开发环境与生产环境相同。 Using Postgres is the default on heroku. 在Heroku上,默认使用Postgres。

You will need to install and configure Postgres locally first with a user that has your username 您首先需要使用具有您的用户名的用户在本地安装和配置Postgres


Software needed: postgresql, pgloader, heroku-cli 所需软件:PostgreSQL,pgloader,heroku-cli


Steps 脚步

Move from SQLite to Postgres on your dev environment 在您的开发环境中从SQLite迁移到Postgres

  1. install heroku / pgloader / postgres, and make sure postgresql is running on your system 安装heroku / pgloader / postgres,并确保postgresql在您的系统上运行
  2. backup sqlite - copy development.sql to development_old.sql 备份sqlite-将development.sql复制到development_old.sql
  3. add gem 'pg' to main section of your Gemfile 将gem'pg gem 'pg'添加到Gemfile的主要部分
  4. bundle install 捆绑安装
  5. update config/database.yml (see sample below) 更新config / database.yml(请参见下面的示例)
  6. rake db:setup 耙db:setup
  7. cd [application root] cd [应用程序根目录]
  8. load postgres db with data - pgloader ./db/development.sqlite3 postgresql:///[name of postgres dev db] 用数据加载postgres db- pgloader ./db/development.sqlite3 postgresql:///[name of postgres dev db]
  9. remove gem 'sqlite3' 删除gem 'sqlite3'
  10. bundle install 捆绑安装
  11. start server - rails server 启动服务器rails server
  12. test by visiting app at localhost:3000 通过访问本地主机上的应用程序进行测试:3000

Setup new app on heroku 在Heroku上设置新应用

Follow these instructions from heroku 遵循heroku的这些指示

Move data to heroku 将数据移至heroku

  1. find heroku db info - heroku pg:info 查找heroku数据库信息heroku pg:info
  2. erase and reset remote db - heroku pg:reset DATABASE_URL --app [name of app] 擦除并重置远程heroku pg:reset DATABASE_URL --app [name of app]
  3. push local data to heroku - heroku pg:push [name of postgres dev db] DATABASE_URL --app [name of app] 将本地数据推送到heroku- heroku pg:push [name of postgres dev db] DATABASE_URL --app [name of app]

NOTE: if that database has greater than 10k rows, you will also need to upgrade to a hobby-basic tier on heroku 注意:如果该数据库的行数超过1万,则还需要升级到heroku上的嗜好基础层

Upgrading Heroku to Hobby Tier Basic 将Heroku升级到Hobby Tier Basic

  1. create new tier - `heroku addons:create heroku-postgresql:hobby-basic --app [name of app] 创建新层-`heroku addons:create heroku-postgresql:hobby-basic --app [应用名称]
  2. get the new database url - heroku pg:info 获取新的数据库URL- heroku pg:info
  3. turn on maintenance - heroku maintenance:on --app [name of app] 打开维护heroku maintenance:on --app [name of app]
  4. copy data - heroku pg:copy DATABASE_URL [HEROKU_POSTGRESQL_COLOR_URL] --app [name of app] 复制数据heroku pg:copy DATABASE_URL [HEROKU_POSTGRESQL_COLOR_URL] --app [name of app]
  5. promote new db - heroku pg:promote [HEROKU_POSTGRESQL_COLOR_URL] --app [name of app] heroku pg:promote [HEROKU_POSTGRESQL_COLOR_URL] --app [name of app]新数据库heroku pg:promote [HEROKU_POSTGRESQL_COLOR_URL] --app [name of app]
  6. turn off maintenance 关闭维护
  7. test by visiting heroku app 通过访问heroku应用进行测试

In case you run into issues or edge cases, here are some resources to help. 如果您遇到问题或极端情况,这里有一些资源可以帮助您。

Resources: 资源:

database_sample.yml database_sample.yml

default: &default
  adapter: postgresql
  encoding: unicode
  host: localhost
  port: 5432
  # For details on connection pooling, see Rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: [name of app]_dev

test:
  <<: *default
  database: [name of app]_test

staging:
  <<: *default
  database: [name of app]

production:
  <<: *default
  database: [name of app]

Hey dude you have all you need inside the link below 嘿伙计,您在下面的链接中拥有了所需的一切

How to change from SQLite to PostgreSQL and deploy on heroku 如何从SQLite更改为PostgreSQL并在heroku上进行部署

let me know if you any more doubts regards 让我知道是否还有任何疑问

暂无
暂无

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

相关问题 如何使用PostGres数据库将Rails 5应用程序部署到Heroku? 收到错误消息说我仍然设置了sqlite适配器 - How do I deploy a Rails 5 app to Heroku using a PostGres database? Getting an error saying I still have the sqlite adapter set 如何使用现有的SQL数据库将Rails应用程序部署到Heroku? - How do I deploy my rails app to Heroku using an existing SQL database? 如何将heroku上的现有Web应用程序迁移到Rails? - How do I migrate an existing web app on heroku to rails? 在Heroku上,如何安排Postgres数据库以使其Rails应用程序定期重置? - On Heroku, how can I schedule the postgres database for my Rails app to be periodically reset? 如何在我的Rails 5应用程序和我的Heroku帐户中访问Heroku上载的数据库? - How Do I Access Databases Uploaded in Heroku in my Rails 5 App and my Heroku Account? 如何使用Heroku上的Ruby on Rails项目从开发过渡到生产? - How do I move from development to production with my Ruby on Rails project on Heroku? Sqlite 到 Postgres - 现有的 Rails 项目 - Sqlite to Postgres - existing Rails project 如何为我的应用程序创建Twitter样式的URL-使用现有应用程序或重新设计应用程序-Ruby on Rails - How do I create Twitter style URLs for my app - Using existing application or app redesign - Ruby on Rails 运行Rails应用程序时如何在Heroku中设置环境? - How do I set the environment in Heroku when running my Rails app? 如何在Facebook画布上以不同方式显示我现有的Rails应用程序 - How do I show my existing rails app differently on Facebook canvas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM