Clear and populate the database with fresh data:
rake db:populate
Clear the database:
rake db:clean
Clear and populate the database with fresh data:
rake db:populate
Clear the database:
rake db:clean
| namespace :db do | |
| desc "Fill the database with new data" | |
| task fill: :environment do | |
| # Populate records via FactoryBot | |
| puts 'Populate Records Complete' | |
| end | |
| desc 'Clean the database and elasticsearch' | |
| task clean: :environment do | |
| next if ENV['ENVIRONMENT'] == 'production' | |
| require 'database_cleaner' | |
| DatabaseCleaner.strategy = :truncation | |
| puts 'Cleaning database' | |
| DatabaseCleaner.clean | |
| puts 'Cleaning elasticsearch' | |
| UserEvent.__elasticsearch__.client.indices.delete index: UserEvent.index_name rescue nil | |
| UserContact.__elasticsearch__.client.indices.delete index: UserContact.index_name rescue nil | |
| UserEvent.__elasticsearch__.client.indices.create \ | |
| index: UserEvent.index_name, | |
| body: { settings: UserEvent.settings.to_hash, mappings: UserEvent.mappings.to_hash } | |
| UserContact.__elasticsearch__.client.indices.create \ | |
| index: UserContact.index_name, | |
| body: { settings: UserContact.settings.to_hash, mappings: UserContact.mappings.to_hash } | |
| puts 'Database clean' | |
| end | |
| desc 'Populate the database with fresh data' | |
| task populate: ['db:clean', 'db:fill'] | |
| end |