[英]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? 我怎么做?
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
Move from SQLite to Postgres on your dev environment 在您的开发环境中从SQLite迁移到Postgres
gem 'pg'
to main section of your Gemfile gem 'pg'
添加到Gemfile的主要部分 pgloader ./db/development.sqlite3 postgresql:///[name of postgres dev db]
pgloader ./db/development.sqlite3 postgresql:///[name of postgres dev db]
gem 'sqlite3'
gem 'sqlite3'
rails server
rails server
Setup new app on heroku 在Heroku上设置新应用
Follow these instructions from heroku 遵循heroku的这些指示
Move data to heroku 将数据移至heroku
heroku pg:info
heroku pg:info
heroku pg:reset DATABASE_URL --app [name of app]
heroku pg:reset DATABASE_URL --app [name of app]
heroku pg:push [name of postgres dev db] DATABASE_URL --app [name of app]
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
heroku pg:info
heroku pg:info
heroku maintenance:on --app [name of app]
heroku maintenance:on --app [name of app]
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]
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]
In case you run into issues or edge cases, here are some resources to help. 如果您遇到问题或极端情况,这里有一些资源可以帮助您。
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.