Sha256: 2c658a5f72732cff0f9c121c87e3b7850bf7e4db39a0343a6b319009fff1f738

Contents?: true

Size: 1.49 KB

Versions: 9

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

namespace :cloud66 do # rubocop:disable Metrics/BlockLength
  desc 'Post-symlink hook tasks for Cloud66.'
  task after_symlink: %i(environment db:migrate db:seed)

  namespace :robots do
    desc 'Add robots.txt to public'
    task add: :environment do
      origin = Rails.root.join '.cloud66', 'public', 'staging', 'robots.txt'
      target = Rails.root.join 'public'
      FileUtils.cp origin, target
    end

    desc 'Deletes robots.txt from public'
    task remove: :environment do
      path = Rails.root.join 'public', 'robots.txt'
      FileUtils.rm path
    end
  end

  namespace :swap do
    def swap_file
      Rails.root.join 'export-swap.sql'
    end

    desc 'Exports tables to be synced'
    task export: :environment do
      cmd = <<-BASH
        pg_dump -U #{ENV.fetch('POSTGRESQL_USERNAME', nil)} #{ENV.fetch('POSTGRESQL_DATABASE', nil)} \
          --no-owner \
          --table=users \
          --table=access_codes \
          --file=#{swap_file}
      BASH
      system cmd
    end

    desc 'Deletes existing tables and creates new one'
    task import: :environment do
      raise 'No data file. Please execute `cloud66:swap:export` prior loading the data.' unless File.exist?(swap_file)

      cmd = "psql -U #{ENV.fetch('POSTGRESQL_USERNAME', nil)} #{ENV.fetch('POSTGRESQL_DATABASE', nil)}"
      # Drops old tables
      system "#{cmd} -c 'drop table access_codes, users;'"
      # Create new and load the data
      system "#{cmd} < #{swap_file}"
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lcms-engine-0.5.5 lib/tasks/cloud66.rake
lcms-engine-0.5.4 lib/tasks/cloud66.rake
lcms-engine-0.5.3 lib/tasks/cloud66.rake
lcms-engine-0.5.2 lib/tasks/cloud66.rake
lcms-engine-0.5.1 lib/tasks/cloud66.rake
lcms-engine-0.5.0 lib/tasks/cloud66.rake
lcms-engine-0.4.2 lib/tasks/cloud66.rake
lcms-engine-0.4.1 lib/tasks/cloud66.rake
lcms-engine-0.4.0 lib/tasks/cloud66.rake