Module: Capistrano::DSL::Craft
- Defined in:
- lib/capistrano/dsl/craft.rb
Instance Method Summary collapse
-
#backup_file_name ⇒ Object
Database.
- #confirm(question) ⇒ Object
- #craft_app_path ⇒ Object
- #craft_console(command, params = '') ⇒ Object
- #craft_console_path ⇒ Object
- #database_config(env) ⇒ Object
- #database_dump(env, input) ⇒ Object
- #database_restore(env, input) ⇒ Object
- #mysql_dump(env, output) ⇒ Object
- #mysql_restore(env, input) ⇒ Object
- #postgres_dump(env, config, output) ⇒ Object
- #postgres_restore(env, config, input) ⇒ Object
Instance Method Details
#backup_file_name ⇒ Object
Database
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/capistrano/dsl/craft.rb', line 38 def backup_file_name now = Time.now backup_date = [now.year, now.strftime("%m"), now.strftime("%d")] backup_time = [now.strftime("%H"), now.strftime("%M"), now.strftime("%S")] unless Dir.exist?(fetch(:craft_local_backups)) Dir.mkdir(fetch(:craft_local_backups)) end File.join(fetch(:craft_local_backups), "#{backup_date.join('-')}_#{backup_time.join('-')}.sql") end |
#confirm(question) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/capistrano/dsl/craft.rb', line 18 def confirm(question) set :confirmed, proc { puts <<-EOF ************************** WARNING *************************** #{question} ************************************************************** EOF ask :answer, "y/N" if fetch(:answer).strip == 'y' then true else false end }.call unless fetch(:confirmed) exit end end |
#craft_app_path ⇒ Object
4 5 6 |
# File 'lib/capistrano/dsl/craft.rb', line 4 def craft_app_path release_path.join(fetch(:app_path)) end |
#craft_console(command, params = '') ⇒ Object
12 13 14 15 16 |
# File 'lib/capistrano/dsl/craft.rb', line 12 def craft_console(command, params = '') on release_roles(fetch(:craft_deploy_roles)) do execute fetch(:php), craft_console_path, command, params, fetch(:craft_console_flags) end end |
#craft_console_path ⇒ Object
8 9 10 |
# File 'lib/capistrano/dsl/craft.rb', line 8 def craft_console_path release_path.join(fetch(:craft_console_path)) end |
#database_config(env) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/capistrano/dsl/craft.rb', line 72 def database_config(env) config = capture SSHKit::Command.new <<-EOCOMMAND source "#{env}" echo "$DB_DSN,$DB_DRIVER,$DB_SERVER,$DB_PORT,$DB_DATABASE" EOCOMMAND params = config.split(",") parsed = {} if params[0].length > 0 # Using the newer style DB_DSN config style dsn = params[0].split(":") # Split in config chunks eg. host=<host> database = dsn[1].split(";").map { |str| tuple = str.split("=") [tuple[0], tuple[1]] }.to_h parsed = { driver: dsn[0], host: database["host"], port: database["port"], database: database["dbname"] } else # Using the older style config style parsed = { driver: params[1], host: params[2], port: params[3], database: params[4] } end case parsed[:driver].strip when "pgsql" then parsed[:driver] = :pgsql when "mysql" then parsed[:driver] = :mysql else raise "Unable to determine database driver: \"#{parsed[:driver].strip}\"" end return parsed end |
#database_dump(env, input) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/capistrano/dsl/craft.rb', line 117 def database_dump(env, input) config = database_config(env) if config[:driver] == :pgsql postgres_dump(env, config, input) else mysql_dump(env, config, input) end end |
#database_restore(env, input) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/capistrano/dsl/craft.rb', line 126 def database_restore(env, input) config = database_config(env) if config[:driver] == :pgsql postgres_restore(env, config, input) else mysql_restore(env, config, input) end end |
#mysql_dump(env, output) ⇒ Object
57 58 |
# File 'lib/capistrano/dsl/craft.rb', line 57 def mysql_dump(env, output) end |
#mysql_restore(env, input) ⇒ Object
69 70 |
# File 'lib/capistrano/dsl/craft.rb', line 69 def mysql_restore(env, input) end |
#postgres_dump(env, config, output) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/capistrano/dsl/craft.rb', line 50 def postgres_dump(env, config, output) execute SSHKit::Command.new <<-EOCOMMAND source "#{env}" PGPASSWORD=$DB_PASSWORD pg_dump -U $DB_USER -h #{config[:host]} -p #{config[:port]} -F p --no-owner #{config[:database]} > #{output} EOCOMMAND end |
#postgres_restore(env, config, input) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/capistrano/dsl/craft.rb', line 60 def postgres_restore(env, config, input) execute SSHKit::Command.new <<-EOCOMMAND source "#{env}" PGPASSWORD=$DB_PASSWORD dropdb -U $DB_USER -h #{config[:host]} -p #{config[:port]} #{config[:database]} PGPASSWORD=$DB_PASSWORD createdb -U $DB_USER -h #{config[:host]} -p #{config[:port]} #{config[:database]} PGPASSWORD=$DB_PASSWORD psql -U $DB_USER -d #{config[:database]} -h #{config[:host]} -p #{config[:port]} -q < "#{input}" EOCOMMAND end |