はじめに
Flutter × Supabaseのアプリ開発を進める中で、なぜか微妙にローカルで作業したものをリモートに反映するのに苦戦をしてしまったのでコマンドのメモを残します。
Supabaseドキュメント
今回このページを見つけるのに苦労をしてしまいました。
結論から言うと、以下のコマンドで解決です
# プロジェクトとリンク
supabase link
# ローカルの状態からマイグレーションファイルを生成
supabase db diff --use-migra -f {任意の名前}
# (例) supabase db diff --use-migra -f create_users_table
# リモートに反映する
supabase db push
忘れてはいけないSupabaseのAI機能
supabaseはプロジェクトのサイドバーの一番下に検索アイコンがあります。
この機能をすっかり忘れていました。
まず、手元のターミナルでsupabase db --help
をしたところ以下が表示されました。
% supabase db --help
Manage Postgres databases
Usage:
supabase db [command]
Available Commands:
diff Diffs the local database for schema changes
dump Dumps data or schemas from the remote database
lint Checks local database for typing error
pull Pull schema from the remote database
push Push new migrations to the remote database
reset Resets the local database to current migrations
start Starts local Postgres database
Flags:
-h, --help help for db
Global Flags:
--create-ticket create a support ticket for any CLI error
--debug output debug logs to stderr
--dns-resolver [ native | https ] lookup domain names using the specified resolver (default native)
--experimental enable experimental features
--workdir string path to a Supabase project directory
Use "supabase db [command] --help" for more information about a command.
記載の通り、diffコマンドで実現できそうです。
diff Diffs the local database for schema changes
と、そこまでわかったら検索するのですが、Supabaseの検索はAI検索のため類似情報をいくつかピックアップしてくれます。しかし、今回は一番先頭にありました(そこまで見抜かれてる...?)
そして冒頭のドキュメントに到達できて無事ローカルからリモートへ反映ができました。
以上、小ネタの備忘録でした。
追記
ローカルのレコードをsqlとして出力する
supabase db dump --local --data-only -f seed.sql