-
Notifications
You must be signed in to change notification settings - Fork 28
/
push_tasks.rb
45 lines (43 loc) · 1.51 KB
/
push_tasks.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
dep 'schema up to date.push', :ref, :remote, :env do
def db_name
YAML.load_file('config/database.yml'.p)[env.to_s]['database']
end
def dump_schema_cmd
pg_dump = "pg_dump #{db_name} --no-privileges --no-owner"
# Dump the schema, and then the schema_migrations table including its contents.
"#{pg_dump} --schema-only -T schema_migrations && #{pg_dump} -t schema_migrations"
end
def fetch_schema
shell "ssh #{remote_host} '#{dump_schema_cmd}' > db/schema.sql.tmp"
end
def move_schema_into_place
shell "mv db/schema.sql.tmp db/schema.sql"
end
setup {
# We fetch to a temporary file first and move it into place on ssh
# success, because a failed connection can result in an empty file.
fetch_schema and move_schema_into_place
}
met? {
Babushka::GitRepo.new('.').clean?
}
meet {
shell "git add db/schema.sql && git commit db/schema.sql -m 'Update DB schema after deploying #{shell("git rev-parse --short #{ref}")}.'"
}
end
dep 'marked on newrelic.task', :ref, :env do
requires 'app bundled'.with('.', 'development')
run {
if 'config/newrelic.yml'.p.exists?
shell "bundle exec newrelic deployments -e #{env} -r #{shell("git rev-parse --short #{ref}")}"
end
}
end
dep 'marked on bugsnag.task', :ref, :env do
requires 'app bundled'.with('.', 'development')
run {
if 'config/initializers/bugsnag.rb'.p.exists?
log_shell "Notifying bugsnag", "bundle exec rake bugsnag:deploy BUGSNAG_REVISION=#{shell("git rev-parse --short #{ref}")}"
end
}
end