Last active
August 29, 2015 14:02
-
-
Save jmmastey/9d945954f379a2462999 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddLondisteExtension < ActiveRecord::Migration | |
def up | |
load_postgres_extension("londiste") do | |
verify "pgq" | |
verify "pgq_node" | |
verify "londiste" | |
end | |
end | |
def down | |
unload_postgres_extension("londiste") | |
end | |
end | |
## elsewhere in the universe! | |
class UnableToInstallError < RuntimeError; end | |
module PostgresExtensionLoader | |
def load_postgres_extension(extension, &block) | |
ext = PostgresExtension.new(extension) | |
ext.install or raise UnableToInstallError | |
ext.instance_eval(&block) | |
end | |
def unload_postgres_extension(extension) | |
PostgresExtension.new(extension).uninstall | |
end | |
class PostgresExtension | |
attr_accessor :extension | |
def initialize(extension) | |
@extension = extension | |
end | |
def install | |
# when in prod, make sure it's already built or raise. | |
# when in dev or test, do this: | |
exec("cleanup") && | |
exec("download") && | |
exec("make") && | |
exec("build") | |
end | |
def verify(lib) | |
# check that system includes lib | |
raise unless lib_installed(lib) | |
end | |
def uninstall | |
# remove everything | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment