LoginSignup
0
0

More than 3 years have passed since last update.

Swift Vapor + Herokuで登録しているデータベースにmigrateやrevertを行う

Last updated at Posted at 2020-03-18

Swiftのvaporを利用し始め、herokuにデプロイしてアプリを動かせるようになりました!
今日は、HerokuでDBのrevertとmigrateをしたのでそれのメモを書きます。
(3分で書いて、2秒で読み終わる代物になっており、オチもありません)

参考文献

What is Heroku
How to REVERT a migration in Vapor 3 with fluent

基本

以下のような感じでコマンドを打つのが基本スタイル。
~~ の部分にvaporのコマンドが入ります。

heroku run Run ~~ 

Run がローカルで実行するvaporのrunコマンドに相当するみたいです。
ちなみに、~~の部分ではvaporのcommand機能で実装した自作のコマンドも指定&実行させれます

事前に・・・

configure.swiftにはFluentのコマンドが実行できるように設定しておきましょう。
これを忘れるとFluent系のコマンドはvaporのアプリで利用できません。

configure.swift
var commands = CommandConfig.default()
commands.useFluentCommands()
services.register(commands)

Herokuでのvaporサンプルのデータベースmigrate

heroku run Run migrate

Herokuでのvaporサンプルのデータベースrevert

--all のオプションでこれまでの全てをrevertできます。

heroku run Run revert

おまけ

ちなみに、ステージング環境と本番環境をHerokuのアプリで分けてる方は、--remoteや--appのコマンドで環境別にコマンド実行させれます。

--remoteにstagingとproductionが登録されており、stagingにのみmigrateしたい場合

heroku run Run migrate --remote staging

同一のソースをHerokuのhello-worldとnew-worldというアプリにそれぞれ登録されており、new-worldにのみrevertしたい場合

heroku run Run revert --app new-world
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