Class: LeanCms::SyncHelper
- Inherits:
-
Object
- Object
- LeanCms::SyncHelper
- Defined in:
- lib/lean_cms/sync_helper.rb
Class Method Summary collapse
Class Method Details
.config ⇒ Object
4 5 6 |
# File 'lib/lean_cms/sync_helper.rb', line 4 def config @config ||= load_config end |
.pull_from_production ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/lean_cms/sync_helper.rb', line 8 def pull_from_production puts "Pulling production database..." validate_config! ensure_local_dir_exists # Stop the container to ensure clean database state puts " Stopping production container..." run_ssh("docker stop $(docker ps -q --filter name=#{config[:service]}-web) 2>/dev/null || true") # Pull the database file puts " Downloading production.sqlite3..." run_local("scp #{config[:ssh_user]}@#{config[:server]}:#{config[:remote_storage_path]}/production.sqlite3 #{local_db_path}") # Also pull Active Storage files if they exist puts " Downloading Active Storage files..." run_local("scp -r #{config[:ssh_user]}@#{config[:server]}:#{config[:remote_storage_path]}/ #{local_storage_path}/ 2>/dev/null || true") # Restart the container puts " Restarting production container..." run_ssh("docker start $(docker ps -aq --filter name=#{config[:service]}-web) 2>/dev/null || true") # Clean up WAL files locally (they're from production) cleanup_wal_files(local_db_path) puts "\nDatabase pulled successfully!" puts " Local path: #{local_db_path}" puts "\nYou can now make changes locally using:" puts " RAILS_ENV=production_local bin/rails console" end |
.push_to_production ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/lean_cms/sync_helper.rb', line 39 def push_to_production puts "Pushing local database to production..." validate_config! validate_local_db_exists! # Checkpoint the local database (flush WAL to main file) checkpoint_database(local_db_path) # Stop the container puts " Stopping production container..." run_ssh("docker stop $(docker ps -q --filter name=#{config[:service]}-web) 2>/dev/null || true") # Backup production database first = Time.now.strftime('%Y%m%d_%H%M%S') puts " Backing up production database..." run_ssh("cp #{config[:remote_storage_path]}/production.sqlite3 #{config[:remote_storage_path]}/production.sqlite3.backup.#{} 2>/dev/null || true") # Push the database file puts " Uploading production.sqlite3..." run_local("scp #{local_db_path} #{config[:ssh_user]}@#{config[:server]}:#{config[:remote_storage_path]}/production.sqlite3") # Push Active Storage files puts " Uploading Active Storage files..." run_local("scp -r #{local_storage_path}/* #{config[:ssh_user]}@#{config[:server]}:#{config[:remote_storage_path]}/ 2>/dev/null || true") # Clean up WAL files on server puts " Cleaning up WAL files..." run_ssh("rm -f #{config[:remote_storage_path]}/production.sqlite3-shm #{config[:remote_storage_path]}/production.sqlite3-wal") # Restart the container puts " Restarting production container..." run_ssh("docker start $(docker ps -aq --filter name=#{config[:service]}-web) 2>/dev/null || true") puts "\nDatabase pushed successfully!" puts " Backup saved as: production.sqlite3.backup.#{}" clear_production_cache warm_cache end |