Skip to content

Commit

Permalink
ローカル環境でデータベースをリストアするためのRakeタスクを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
shimbaco committed Apr 9, 2024
1 parent 741e9ff commit eedbc40
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/tasks/dev.rake
@@ -0,0 +1,25 @@
# frozen_string_literal: true

namespace :dev do
# データベースをリストアする
# 使用例:
# docker compose exec -e ANNICT_POSTGRES_DUMP_PATH=tmp/db.dump app bin/rails dev:restore_db
task restore_db: :environment do
sql = "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
ActiveRecord::Base.connection.execute(sql)

system "
pg_restore \
--verbose \
--clean \
--no-acl \
--no-owner \
--jobs 4 \
-h #{ENV.fetch("ANNICT_POSTGRES_HOST")} \
-U #{ENV.fetch("ANNICT_POSTGRES_USERNAME")} \
-d annict_development \
-p #{ENV.fetch("ANNICT_POSTGRES_PORT")} \
#{ENV.fetch("ANNICT_POSTGRES_DUMP_PATH")}
"
end
end

0 comments on commit eedbc40

Please sign in to comment.