Rails Cheats

Set current version of ruby

rvm --default use 2.1.1

Use migrate from named origin / dest in database.yml

-C Begin the output with a command to create the database itself and reconnect to the created database.

If –clean is also specified, the script drops and recreates the target database before reconnecting to it.

-h hostname

-U username

def getEnvironmentConfig(env = Rails.env)
        return Rails.configuration.database_configuration[env]
    end

    # Use migrate from named origin / dest in database.yml
    def migrateDbEnv(originStr, destStr)
        origin = getEnvironmentConfig(originStr)
        dest = getEnvironmentConfig(destStr)
        system "pg_dump -C -h #{origin["host"]} -U #{origin["username"]} #{origin["database"]} | psql #{dest["host"]} -U #{dest["username"]} #{dest["database"]}"
    end

http://blog.bigbinary.com/2012/10/18/backtick-system-exec-in-ruby.html

Leave a Reply

Your email address will not be published. Required fields are marked *