about summary refs log tree commit diff
path: root/lib/tasks/db.rake
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tasks/db.rake')
-rw-r--r--lib/tasks/db.rake16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake
new file mode 100644
index 000000000..a1211f097
--- /dev/null
+++ b/lib/tasks/db.rake
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+namespace :db do
+  namespace :migrate do
+    desc 'Setup the db or migrate depending on state of db'
+    task setup: :environment do
+      begin
+        ActiveRecord::Base.connection
+      rescue ActiveRecord::NoDatabaseError
+        Rake::Task['db:setup'].invoke
+      else
+        Rake::Task['db:migrate'].invoke
+      end
+    end
+  end
+end