From 444d5a787e04b3c44c17d020423b753bd89159c6 Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Mon, 14 Dec 2020 19:10:45 -0800 Subject: [PATCH] feature: db:migrate:reset:with_data Usually when resetting a database there is no data, but we use data migrations to create table partitions so we need to make sure they run. (Having them as schema migrations adds spurious changes to the schema every month). --- README.md | 1 + tasks/databases.rake | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index d57aa687..26465e79 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ You can generate a data migration as you would a schema migration: rake db:forward:with_data # Pushes the schema to the next version (specify steps w/ STEP=n) rake db:migrate:down:with_data # Runs the "down" for a given migration VERSION rake db:migrate:redo:with_data # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x) + rake db:migrate:reset:with_data # Drops and creates a fresh database and runs all migrations. rake db:migrate:status:with_data # Display status of data and schema migrations rake db:migrate:up:with_data # Runs the "up" for a given migration VERSION rake db:migrate:with_data # Migrate the database data and schema (options: VERSION=x, VERBOSE=false) diff --git a/tasks/databases.rake b/tasks/databases.rake index 7f23a142..24620a01 100644 --- a/tasks/databases.rake +++ b/tasks/databases.rake @@ -63,6 +63,11 @@ namespace :db do Rake::Task["data:dump"].invoke end + namespace :reset do + desc 'Drops and creates a fresh database and runs all migrations.' + task with_data: ["db:drop", "db:create", "db:migrate:with_data"] + end + namespace :redo do desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).' task :with_data => :environment do