From 77f93aa1737df2646ddbff988c5b999f5c13f918 Mon Sep 17 00:00:00 2001 From: Javier Torres Date: Fri, 22 Mar 2019 16:16:14 +0100 Subject: [PATCH] Fix db:create rake --- NEWS.md | 1 + Rakefile | 1 + lib/tasks/setup.rake | 15 +++++++++++++++ 3 files changed, 17 insertions(+) diff --git a/NEWS.md b/NEWS.md index 44f60e1eb0..784c373442 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,6 +20,7 @@ Development - New Dashboard documentation ([#14712](https://github.com/CartoDB/cartodb/pull/14712)) - Bolt now can: retry with timeout, execute a rerun function for retry. The importer now uses bolt for the register phase in order to avoid multiple ghost table calls in the future[#14736](https://github.com/CartoDB/cartodb/pull/14736) +- Fix `db:create` rake (#14766) - Design review changes ([CartoDB/product#272](https://github.com/CartoDB/product/issues/272)) - Invite User menu missing go back icon ([#14739](https://github.com/CartoDB/cartodb/issues/14739)) - Fix error when duplicating shared dataset in dashboard ([#14750](https://github.com/CartoDB/cartodb/issues/14750)) diff --git a/Rakefile b/Rakefile index d85d168741..f20c5f9c0d 100644 --- a/Rakefile +++ b/Rakefile @@ -20,6 +20,7 @@ rake_tasks.delete('default') # Remove ActiveRecord tasks and replace with Sequel versions rake_tasks.select { |k, _| k.starts_with?('sequel') }.each { |k, v| rake_tasks[k.sub('sequel:', 'db:')] = v } +rake_tasks.select { |k, _| k.starts_with?('cartodb:db') }.each { |k, v| rake_tasks[k.sub('cartodb:db:', 'db:')] = v } if Rails.env.test? namespace :spec do diff --git a/lib/tasks/setup.rake b/lib/tasks/setup.rake index 1c419036d3..961a214cf3 100644 --- a/lib/tasks/setup.rake +++ b/lib/tasks/setup.rake @@ -1,4 +1,19 @@ namespace :cartodb do + namespace :db do + task :create, [:env] do |_t, args| + # When the db:create task runs, there is no prior database. Since we use models in our initializers, we need to + # skip the :environment dependency or Sequel will error out when trying to load the schema for the model table. + # This task overrides the default Sequel task, loading the bare minimum (db config) instead of all initializers + args.with_defaults(:env => Rails.env) + + config = SequelRails::Configuration.for(Rails.root, Carto::Conf.new.db_config) + + unless SequelRails::Storage.create_environment(config.environment_for(args.env)) + abort "Could not create database for #{args.env}." + end + end + end + namespace :test do task :prepare do if (ENV['RAILS_ENV'] == "test")