aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2017-12-26 19:46:56 +0100
committerHarald Eilertsen <haraldei@anduin.net>2017-12-26 19:51:40 +0100
commit2cb29eb625786458c89ab32829fbfb6215b6f89c (patch)
tree74a6bfa4ae5d93592d969f92befdbba8edc475d3
parent42e4eaa01504dadd3ff37fce49119ae3f156b23e (diff)
downloadhmnoweb-2cb29eb625786458c89ab32829fbfb6215b6f89c.tar.gz
hmnoweb-2cb29eb625786458c89ab32829fbfb6215b6f89c.tar.bz2
hmnoweb-2cb29eb625786458c89ab32829fbfb6215b6f89c.zip
Capistrano task for cold deploys.
Run this for first time deploy (after setting up the database.) It loads the checked in schema instead of running through all the migrations to rebuild the database schema. The task will be skipped if the database schema already exists, and let the migrations run as normally.
-rw-r--r--lib/capistrano/tasks/deploy_cold.rake42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/capistrano/tasks/deploy_cold.rake b/lib/capistrano/tasks/deploy_cold.rake
new file mode 100644
index 0000000..f91ede6
--- /dev/null
+++ b/lib/capistrano/tasks/deploy_cold.rake
@@ -0,0 +1,42 @@
+# Capistrano task for cold deploys
+#
+# Taken from: https://stackoverflow.com/a/28001351/270280
+# Licensed under cc by-sa 3.0
+#
+# Generalized and fixed running with the correct environment
+# by Harald Eilertsen
+#
+namespace :deploy do
+
+ #
+ # Run this for first time deploy (after setting up the database.) It
+ # loads the checked in schema instead of running through all the
+ # migrations to rebuild the database schema.
+ #
+ # The task will be skipped if the database schema already exists, and
+ # let the migrations run as normally.
+ #
+
+ desc "deploy app for the first time (expects pre-created but empty DB)"
+ task :cold do
+ before 'deploy:migrate', 'deploy:initdb'
+ invoke 'deploy'
+ end
+
+ desc "initialize a brand-new database (db:schema:load, db:seed)"
+ task :initdb => [ :set_rails_env ] do
+ on primary :db do |host|
+ within release_path do
+ if test(:psql, %Q{#{fetch(:pg_database)} -U #{fetch(:pg_user)} -c "SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE';"|grep schema_migrations})
+ puts '*** THE PRODUCTION DATABASE IS ALREADY INITIALIZED, YOU IDIOT! ***'
+ else
+ with rails_env: fetch(:rails_env) do
+ execute :rake, 'db:schema:load'
+ execute :rake, 'db:seed'
+ end
+ end
+ end
+ end
+ end
+
+end