lib/hanzo/modules/deploy.rb in hanzo-0.4.3 vs lib/hanzo/modules/deploy.rb in hanzo-0.4.4

- old
+ new

@@ -1,10 +1,17 @@ module Hanzo class Deploy < Base + # Classes UnknownEnvironment = Class.new(StandardError) UninstalledEnvironment = Class.new(StandardError) + # Constants + MIGRATION_COMMANDS = { + 'db/migrate' => 'rake db:migrate', + 'priv/repo/migrations' => 'mix ecto.migrate' + } + protected def initialize_variables @env = extract_argument(1) @env ||= Hanzo::Installers::Remotes.environments.keys.first @@ -40,22 +47,30 @@ Hanzo.run "git push -f #{@env} #{branch}:master" end def run_migrations - return unless Dir.exist?('db/migrate') - return unless Hanzo.agree('Run migrations?') + return if migration_directory.nil? + return unless Hanzo.agree('Run database migrations?') - Hanzo.run "heroku run rake db:migrate --remote #{@env}" + Hanzo.run "heroku run #{migration_command} --remote #{@env}" Hanzo.run "heroku ps:restart --remote #{@env}" end def validate_environment_existence! raise UnknownEnvironment unless fetcher.exist? raise UninstalledEnvironment unless fetcher.installed? end def fetcher @fetcher ||= Hanzo::Fetchers::Environment.new(@env) + end + + def migration_directory + MIGRATION_COMMANDS.keys.find { |directory| Dir.exist?(directory) } + end + + def migration_command + MIGRATION_COMMANDS[migration_directory] end end end