0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Rails】Herokuにデプロイする方法

Last updated at Posted at 2019-06-28

初回にやるべきこと

git 登録

アプリケーションのディレクトリで

$git int

[~/environment/app_name (master) $] とmasterと表示されればOK

Herokuにアカウントを作成する

Heroku:https://jp.heroku.com/home

image.png

Herokuにログイン

ターミナル.
$heroku login --interactive 

Herokuにアプリケーションを作成する(初回のみ)

ターミナル.
$heroku create 好きなアプリ名

変更の都度やること

Gitを操作

Gitで保存するファイルの選択。-Aは全部

ターミナル.
$git add -A 

git addしたファイルの保存の確定

$git commit -m "first commit" 

Herokuにデプロイ

Herokuにログイン

ターミナル.
$heroku login --interactive 

Herokuにデプロイ

ターミナル.
$git push heroku master

マイグレーションの実行

ターミナル.
$ heroku run rake db:migrate

GitHub

ソースコードをプッシュ

$ git push origin master
Username for 'https://github.com':accountname 
Password for 'https://accountname@github.com':password 

sqliteからデータをcsvファイルに書き出す

postgresqlのインストール(初回のみ)

$ sudo yum install postgresql postgresql-server postgresql-devel postgresql-contrib

ローカルのテーブルからcsvで吐き出しを行う

rails dbconsole
.headers on
.mode csv
.output hoge.csv
select * from shops;

Herokuのpostgresqlに接続してcsvをshopsテーブルにインポート

Herokuに接続する

サーバー上のテーブルレコードを削除する場合

アプリケーションのルートに[del_shops.sql]を用意しておく

del_shops.sql
delete from shops;
ターミナル.
$ heroku login --interactive
$ heroku pg:psql
$ \i del_shops.sql

csvをpostgresqlにインポート

ターミナル.
\copy shops from 'hoge.csv' CSV header;

切断

ターミナル.
\q
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?