Sha256: f86d26efbdc074e0cebacebb3505ea95f83fc212d1acef0eec025aa1cce655b8

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

module PgSync
  class Init
    include Utils

    def perform(opts)
      # needed for config_file method
      @options = opts.to_hash

      file = db_config_file(opts.arguments[0]) || config_file || ".pgsync.yml"

      if File.exist?(file)
        raise Error, "#{file} exists."
      else
        exclude =
          if rails?
            <<~EOS
              exclude:
                - schema_migrations
                - ar_internal_metadata
            EOS
          else
            <<~EOS
              # exclude:
              #   - table1
              #   - table2
            EOS
          end

        # create file
        contents = File.read(__dir__ + "/../../config.yml")
        contents.sub!("$(some_command)", "$(heroku config:get DATABASE_URL)") if heroku?
        File.write(file, contents % {exclude: exclude})

        log "#{file} created. Add your database credentials."
      end
    end

    def heroku?
      `git remote -v 2>&1`.include?("git.heroku.com") rescue false
    end

    def rails?
      File.exist?("bin/rails")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pgsync-0.5.5 lib/pgsync/init.rb
pgsync-0.5.4 lib/pgsync/init.rb
pgsync-0.5.3 lib/pgsync/init.rb