drailties 0.4.3 → 0.5.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +6 -14
  2. data/bin/drails +4 -42
  3. data/lib/drails/app_drails_loader.rb +62 -0
  4. data/lib/drails/cli.rb +11 -0
  5. data/lib/drails/commands/application.rb +43 -0
  6. data/lib/drails/commands/destroy.rb +12 -0
  7. data/lib/drails/commands/domainserver.rb +6 -0
  8. data/lib/drails/commands/generate.rb +12 -0
  9. data/lib/drails/commands/projectionserver.rb +9 -0
  10. data/lib/drails/commands/server.rb +22 -0
  11. data/lib/drails/commands.rb +70 -0
  12. data/lib/drails/generators.rb +48 -0
  13. data/lib/drails/server/domain_server.rb +4 -1
  14. data/lib/drails/server/projection_servers.rb +5 -2
  15. data/lib/generators/drails/app/USAGE +12 -12
  16. data/lib/generators/drails/app/app_generator.rb +134 -52
  17. data/lib/generators/drails/app/templates/{event_source_controller.rb → app/controllers/event_source_controller.rb} +15 -15
  18. data/lib/generators/drails/app/templates/bin/drails +3 -0
  19. data/lib/generators/drails/app/templates/config/disco.yml +27 -0
  20. data/lib/generators/drails/app/templates/{build_validations_registry.rb → config/initializers/build_validations_registry.rb} +18 -18
  21. data/lib/generators/drails/app/templates/{create_domain.rb → config/initializers/create_domain.rb} +4 -4
  22. data/lib/generators/drails/app/templates/db/seeds.rb +14 -0
  23. data/lib/generators/drails/command/USAGE +11 -11
  24. data/lib/generators/drails/command/command_generator.rb +68 -40
  25. data/lib/generators/drails/command/templates/command.rb +24 -6
  26. data/lib/generators/drails/command/templates/event.rb +11 -10
  27. data/lib/generators/drails/command_processor/USAGE +1 -1
  28. data/lib/generators/drails/command_processor/command_processor_generator.rb +22 -15
  29. data/lib/generators/drails/command_processor/templates/command_processor.rb +5 -5
  30. data/lib/generators/drails/domain.rb +18 -18
  31. data/lib/generators/drails/event_name.rb +51 -51
  32. data/lib/generators/drails/migration/USAGE +41 -1
  33. data/lib/generators/drails/migration/migration_generator.rb +27 -28
  34. data/lib/generators/drails/migration/templates/create_table_migration.rb +19 -19
  35. data/lib/generators/drails/model/USAGE +17 -17
  36. data/lib/generators/drails/model/model_generator.rb +29 -23
  37. data/lib/generators/drails/model/templates/domain_model.rb +5 -5
  38. data/lib/generators/drails/model/templates/model.rb +4 -4
  39. data/lib/generators/drails/processor_name.rb +47 -47
  40. data/lib/generators/drails/projection/projection_generator.rb +3 -3
  41. data/lib/generators/drails/projection/templates/domain_projection.rb +9 -9
  42. data/lib/generators/drails/projection/templates/domain_projection_test.rb +6 -6
  43. data/lib/generators/drails/projection/templates/projection.rb +9 -9
  44. data/lib/generators/drails/projection/templates/projection_test.rb +6 -6
  45. data/lib/generators/drails/scaffold/USAGE +26 -26
  46. data/lib/generators/drails/scaffold/scaffold_generator.rb +91 -89
  47. data/lib/generators/drails/scaffold/templates/_eventstream.js.erb +15 -15
  48. data/lib/generators/drails/{controller → scaffold_controller}/USAGE +1 -1
  49. data/lib/generators/drails/{controller/controller_generator.rb → scaffold_controller/scaffold_controller_generator.rb} +27 -26
  50. data/lib/generators/drails/scaffold_controller/templates/controller.rb +68 -0
  51. data/lib/generators/drails/{controller → scaffold_controller}/templates/controller_test.rb +45 -45
  52. data/lib/generators/drails/use_domain_option.rb +53 -53
  53. data/lib/rails-disco/version.rb +3 -3
  54. data/lib/tasks/db.rake +187 -88
  55. metadata +33 -27
  56. data/lib/drails/application.rb +0 -8
  57. data/lib/drails/domainserver.rb +0 -5
  58. data/lib/drails/generate.rb +0 -21
  59. data/lib/drails/projectionserver.rb +0 -8
  60. data/lib/drails/server.rb +0 -18
  61. data/lib/generators/drails/app/templates/disco.yml +0 -54
  62. data/lib/generators/drails/controller/templates/controller.rb +0 -67
@@ -0,0 +1,68 @@
1
+ <% if namespaced? -%>
2
+ require_dependency '<%= namespaced_file_path %>/application_controller'
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= controller_class_name %>Controller < ApplicationController
7
+ before_action :set_event_id, only: [:index, :show]
8
+
9
+ def index
10
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
11
+ end
12
+
13
+ def show
14
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, 'params[:id]') %>
15
+ end
16
+
17
+ def new
18
+ @<%= singular_table_name %> = <%= command_class_name('create') %>Command.new
19
+ end
20
+
21
+ def edit
22
+ @<%= singular_table_name %> = <%= command_class_name('update') %>Command.new <%= orm_class.find(class_name, 'params[:id]') %>.attributes
23
+ end
24
+
25
+ def create
26
+ @<%= singular_table_name %> = <%= command_class_name('create') %>Command.new <%= singular_table_name %>_params
27
+ if @<%= singular_table_name %>.valid? && (session[:tmp_event_id] = Domain.run_command(@<%= singular_table_name %>))
28
+ redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %>
29
+ else
30
+ render action: 'new'
31
+ end
32
+ end
33
+
34
+ def update
35
+ @<%= singular_table_name %> = <%= command_class_name('update') %>Command.new <%= singular_table_name %>_params.merge(id: params[:id])
36
+ if @<%= singular_table_name %>.valid? && (session[:tmp_event_id] = Domain.run_command(@<%= singular_table_name %>))
37
+ redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %>
38
+ else
39
+ render action: 'edit'
40
+ end
41
+ end
42
+
43
+ def destroy
44
+ delete_<%= singular_table_name %> = <%= command_class_name('delete') %>Command.new(id: params[:id])
45
+ session[:tmp_event_id] = event_id = Domain.run_command(delete_<%= singular_table_name %>)
46
+ if event_id
47
+ redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %>
48
+ else
49
+ redirect_to <%= singular_table_name %>_url(id: params[:id]), error: <%= "'#{human_name} could not be deleted.'" %>
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def <%= "#{singular_table_name}_params" %>
56
+ <%- if attributes_names.empty? -%>
57
+ params[<%= ":#{singular_table_name}" %>]
58
+ <%- else -%>
59
+ params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
60
+ <%- end -%>
61
+ end
62
+
63
+ def set_event_id
64
+ @event_id = session[:tmp_event_id]
65
+ session[:tmp_event_id] = nil
66
+ end
67
+ end
68
+ <% end -%>
@@ -1,45 +1,45 @@
1
- require 'test_helper'
2
-
3
- <% module_namespacing do -%>
4
- class <%= controller_class_name %>ControllerTest < ActionController::TestCase
5
- setup do
6
- @<%= singular_table_name %> = <%= table_name %>(:one)
7
- end
8
-
9
- test "should get index" do
10
- get :index
11
- assert_response :success
12
- assert_not_nil assigns(:<%= table_name %>)
13
- end
14
-
15
- test "should get new" do
16
- get :new
17
- assert_response :success
18
- end
19
-
20
- #test "should create <%= singular_table_name %>" do
21
- # #removed for now, because there is no reason to test the post here, cause the projection creates it
22
- # #maybe we could test something else here instead
23
- #end
24
-
25
- test "should show <%= singular_table_name %>" do
26
- get :show, id: <%= "@#{singular_table_name}" %>
27
- assert_response :success
28
- end
29
-
30
- test "should get edit" do
31
- get :edit, id: <%= "@#{singular_table_name}" %>
32
- assert_response :success
33
- end
34
-
35
- #test "should update <%= singular_table_name %>" do
36
- # #removed for now, because there is no reason to test the update here, cause the projection updates it
37
- # #maybe we could test something else here instead
38
- #end
39
-
40
- #test "should destroy <%= singular_table_name %>" do
41
- # #removed for now, because there is no reason to test the destroy here, cause the projection destroys it
42
- # #maybe we could test something else here instead
43
- #end
44
- end
45
- <% end -%>
1
+ require 'test_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
5
+ setup do
6
+ @<%= singular_table_name %> = <%= table_name %>(:one)
7
+ end
8
+
9
+ test "should get index" do
10
+ get :index
11
+ assert_response :success
12
+ assert_not_nil assigns(:<%= table_name %>)
13
+ end
14
+
15
+ test "should get new" do
16
+ get :new
17
+ assert_response :success
18
+ end
19
+
20
+ #test "should create <%= singular_table_name %>" do
21
+ # #removed for now, because there is no reason to test the post here, cause the projection creates it
22
+ # #maybe we could test something else here instead
23
+ #end
24
+
25
+ test "should show <%= singular_table_name %>" do
26
+ get :show, id: <%= "@#{singular_table_name}" %>
27
+ assert_response :success
28
+ end
29
+
30
+ test "should get edit" do
31
+ get :edit, id: <%= "@#{singular_table_name}" %>
32
+ assert_response :success
33
+ end
34
+
35
+ #test "should update <%= singular_table_name %>" do
36
+ # #removed for now, because there is no reason to test the update here, cause the projection updates it
37
+ # #maybe we could test something else here instead
38
+ #end
39
+
40
+ #test "should destroy <%= singular_table_name %>" do
41
+ # #removed for now, because there is no reason to test the destroy here, cause the projection destroys it
42
+ # #maybe we could test something else here instead
43
+ #end
44
+ end
45
+ <% end -%>
@@ -1,54 +1,54 @@
1
- require 'active_support/concern'
2
- require 'generators/drails/domain.rb'
3
-
4
- module Drails
5
- module Generators
6
- module UseDomainOption
7
- extend ActiveSupport::Concern
8
-
9
- include Domain
10
-
11
- included do
12
- class_option :domain, type: :boolean, default: false, desc: "generate for the domain"
13
- end
14
-
15
- protected
16
-
17
- def use_domain?
18
- options[:domain]
19
- end
20
-
21
- def use_domain(file_name)
22
- if use_domain?
23
- "domain_#{file_name}"
24
- else
25
- file_name
26
- end
27
- end
28
-
29
- def use_domain_class_path
30
- if use_domain?
31
- domain_class_path
32
- else
33
- class_path
34
- end
35
- end
36
-
37
- def use_domain_base_path
38
- if use_domain?
39
- 'domain'
40
- else
41
- 'app'
42
- end
43
- end
44
-
45
- def use_domain_class_file_path(type, file_name)
46
- File.join use_domain_base_path, type, use_domain_class_path, file_name
47
- end
48
-
49
- def use_domain_param
50
- '--domain' if use_domain?
51
- end
52
- end
53
- end
1
+ require 'active_support/concern'
2
+ require 'generators/drails/domain.rb'
3
+
4
+ module Drails
5
+ module Generators
6
+ module UseDomainOption
7
+ extend ActiveSupport::Concern
8
+
9
+ include Domain
10
+
11
+ included do
12
+ class_option :domain, type: :boolean, default: false, desc: "generate for the domain"
13
+ end
14
+
15
+ protected
16
+
17
+ def use_domain?
18
+ options[:domain]
19
+ end
20
+
21
+ def use_domain(file_name)
22
+ if use_domain?
23
+ "domain_#{file_name}"
24
+ else
25
+ file_name
26
+ end
27
+ end
28
+
29
+ def use_domain_class_path
30
+ if use_domain?
31
+ domain_class_path
32
+ else
33
+ class_path
34
+ end
35
+ end
36
+
37
+ def use_domain_base_path
38
+ if use_domain?
39
+ 'domain'
40
+ else
41
+ 'app'
42
+ end
43
+ end
44
+
45
+ def use_domain_class_file_path(type, file_name)
46
+ File.join use_domain_base_path, type, use_domain_class_path, file_name
47
+ end
48
+
49
+ def use_domain_param
50
+ '--domain' if use_domain?
51
+ end
52
+ end
53
+ end
54
54
  end
@@ -1,9 +1,9 @@
1
1
  module RailsDisco
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 4
5
- TINY = 3
6
- PRE = nil
4
+ MINOR = 5
5
+ TINY = 0
6
+ PRE = "pre"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
9
9
  end
data/lib/tasks/db.rake CHANGED
@@ -1,123 +1,222 @@
1
1
  require 'yaml'
2
- require 'logger'
3
2
  require 'active_record'
4
3
 
5
- namespace :drails do
4
+ namespace :disco do
6
5
  namespace :db do
7
- def create_database(config)
8
- options = {:charset => 'utf8', :collation => 'utf8_unicode_ci'}
6
+ def disco_database_configuration(disco_config, database)
7
+ disco_config.reduce({}) do |map, (key, value)|
8
+ if value.is_a?(Hash) && value.has_key?(database)
9
+ map[key] = value[database]
10
+ end
11
+ map
12
+ end
13
+ end
9
14
 
10
- create_db = lambda do |config|
11
- ActiveRecord::Base.establish_connection config.merge('database' => nil)
12
- ActiveRecord::Base.connection.create_database config['database'], options
13
- ActiveRecord::Base.establish_connection config
15
+ task :load_config => :environment do
16
+ migrate_path = 'db/migrate'
17
+ ActiveRecord::Tasks::DatabaseTasks.db_dir = Rails.application.config.paths['db'].first
18
+ ActiveRecord::Tasks::DatabaseTasks.seed_loader = Rails.application
19
+ ActiveRecord::Base.clear_all_connections!
20
+
21
+ if ENV['SYSTEM'] == 'domain'
22
+ migrate_path = 'db/migrate_domain'
23
+ ActiveRecord::Tasks::DatabaseTasks.env = ENV['DOMAIN_ENV'] || Rails.env
24
+ disco_config = YAML.load_file(File.join Rails.root, 'config', 'disco.yml')
25
+ ActiveRecord::Tasks::DatabaseTasks.database_configuration = disco_database_configuration(disco_config, 'domain_database')
26
+ ActiveRecord::Tasks::DatabaseTasks.migrations_paths =
27
+ Array(ENV['DOMAIN_MIGRATIONS_DIR'] || Rails.application.paths[migrate_path] || File.join(Rails.root, migrate_path))
28
+ ActiveRecord::Tasks::DatabaseTasks.fixtures_path = File.join Rails.root, 'test', 'fixtures_domain'
29
+ ENV['SCHEMA'] = File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, 'schema_domain.rb')
30
+ ENV['DB_STRUCTURE'] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, 'structure_domain.sql')
31
+
32
+ else # 'projection' - normal rails
33
+ ActiveRecord::Tasks::DatabaseTasks.env = ENV['PROJECTION_ENV'] || Rails.env
34
+ ActiveRecord::Tasks::DatabaseTasks.database_configuration = Rails.application.config.database_configuration
35
+ ActiveRecord::Tasks::DatabaseTasks.migrations_paths = Array(Rails.application.paths[migrate_path])
36
+ ActiveRecord::Tasks::DatabaseTasks.fixtures_path = File.join Rails.root, 'test', 'fixtures'
37
+ ENV['SCHEMA'] = File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, 'schema.rb')
38
+ ENV['DB_STRUCTURE'] = File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, 'structure.sql')
14
39
  end
15
40
 
16
- begin
17
- create_db.call config
18
- rescue Mysql::Error => sqlerr
19
- if sqlerr.errno == 1405
20
- print "#{sqlerr.error}. \nPlease provide the root password for your mysql installation\n>"
21
- root_password = $stdin.gets.strip
22
-
23
- grant_statement = <<-SQL
24
- GRANT ALL PRIVILEGES ON #{config['database']}.*
25
- TO '#{config['username']}'@'localhost'
26
- IDENTIFIED BY '#{config['password']}' WITH GRANT OPTION;
27
- SQL
28
-
29
- create_db.call config.merge('database' => nil, 'username' => 'root', 'password' => root_password)
30
- else
31
- $stderr.puts sqlerr.error
32
- $stderr.puts "Couldn't create database for #{config.inspect}, charset: utf8, collation: utf8_unicode_ci"
33
- $stderr.puts "(if you set the charset manually, make sure you have a matching collation)" if config['charset']
41
+ if defined?(ENGINE_PATH) && (engine = Rails::Engine.find(ENGINE_PATH))
42
+ if engine.paths[migrate_path].existent
43
+ ActiveRecord::Tasks::DatabaseTasks.migrations_paths += Array(engine.paths[migrate_path])
44
+ elsif Dir.exists?(File.join engine.root, migrate_path)
45
+ ActiveRecord::Tasks::DatabaseTasks.migrations_paths << File.join(engine.root, migrate_path)
34
46
  end
35
47
  end
48
+ Rails.env = ActiveRecord::Tasks::DatabaseTasks.env
49
+ ActiveRecord::Tasks::DatabaseTasks.root = Rails.root if ActiveRecord::Tasks::DatabaseTasks.respond_to? :root
50
+
51
+ #puts "env = #{ActiveRecord::Tasks::DatabaseTasks.env}"
52
+ puts "system = #{ENV['SYSTEM']}"
53
+ #puts "config = #{ActiveRecord::Tasks::DatabaseTasks.database_configuration[ActiveRecord::Tasks::DatabaseTasks.env]}"
36
54
  end
37
55
 
38
- task :db_env do
39
- DATABASE_ENV = ENV['DATABASE_ENV'] || 'development'
56
+ def connect
57
+ ActiveRecord::Base.establish_connection ActiveRecord::Tasks::DatabaseTasks.env
40
58
  end
41
59
 
42
- task :environment => :db_env do
43
- if ENV['ENV'] == 'domain'
44
- @migration_dir = ENV['MIGRATIONS_DIR'] || 'db/migrate_domain'
45
- @env = 'domain'
46
- else
47
- @migration_dir = ENV['MIGRATIONS_DIR'] || 'db/migrate'
48
- @env = 'projection'
60
+ namespace :migrate do
61
+ desc 'Copys the migrations files from the gems directories (options: SYSTEM=(projection|domain))'
62
+ task :copy => :load_config do
63
+ target_path = ActiveRecord::Tasks::DatabaseTasks.migrations_paths.first
64
+ gems = %w(active_event active_domain)
65
+ gems = %w(active_projection) if ENV['SYSTEM'] != 'domain'
66
+ gems.each do |gem|
67
+ gem_spec = Gem::Specification.find_by_name(gem)
68
+ if gem.nil?
69
+ puts "missing gem #{gem}!"
70
+ elsif Dir.exists?(File.join gem_spec.gem_dir, 'db/migrate')
71
+ cp_r (File.join gem_spec.gem_dir, 'db/migrate/.'), target_path
72
+ else
73
+ puts "missing db/migrate in gem #{gem}!"
74
+ end
75
+ end
49
76
  end
50
- end
51
77
 
52
- task :configuration => :environment do
53
- @config = YAML.load_file("config/disco.yml")[DATABASE_ENV]["#{@env}_database"]
54
- end
78
+ desc 'Copy and run migrations (options: SYSTEM=(projection|domain))'
79
+ task :setup do
80
+ Rake::Task[:'disco:db:migrate:copy'].invoke
81
+ Rake::Task[:'disco:db:create'].invoke
82
+ Rake::Task[:'disco:db:migrate'].invoke
83
+ end
55
84
 
56
- task :configure_connection => :configuration do
57
- ActiveRecord::Base.establish_connection @config
58
- ActiveRecord::Base.logger = Logger.new STDOUT if @config['logger']
85
+ # make sure the right database is connected
86
+ task :down do connect end
87
+ task :up do connect end
88
+ task :status do connect end
59
89
  end
60
90
 
61
- desc 'Create the database from config/disco.yml for the current DATABASE_ENV (options: ENV=(projection|domain))'
62
- task :create => :configure_connection do
63
- create_database @config
64
- end
91
+ task :migrate do connect end
65
92
 
66
- desc 'Drops the database for the current DATABASE_ENV (options: ENV=(projection|domain))'
67
- task :drop => :configure_connection do
68
- ActiveRecord::Base.connection.drop_database @config['database']
93
+ namespace :schema do
94
+ task :load do connect end
69
95
  end
96
+ namespace :structure do
97
+ task :load do connect end
98
+ end
99
+ end
70
100
 
71
- desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n) (options: ENV=(projection|domain)).'
72
- task :rollback => :configure_connection do
73
- step = ENV['STEP'] ? ENV['STEP'].to_i : 1
74
- ActiveRecord::Migrator.rollback @migration_dir, step
101
+ load 'active_record/railties/databases.rake'
102
+
103
+ namespace :domain do
104
+ task :environment do
105
+ ENV['SYSTEM'] = 'domain'
75
106
  end
76
107
 
77
- desc 'Retrieves the current schema version number'
78
- task :version => :configure_connection do
79
- puts "Current version: #{ActiveRecord::Migrator.current_version}"
108
+ namespace :create do
109
+ task :all => [:environment, :'disco:db:create:all']
80
110
  end
81
111
 
82
- desc 'Copys the migrations files from the gems directories (options: ENV=(projection|domain))'
83
- task :copy_migrations => :environment do
84
- if @env == 'domain'
85
- cp_r Gem::Specification.find_by_name('active_event').gem_dir + '/db/migrate/.', @migration_dir
86
- cp_r Gem::Specification.find_by_name('active_domain').gem_dir + '/db/migrate/.', @migration_dir
87
- else
88
- cp_r Gem::Specification.find_by_name('active_projection').gem_dir + '/db/migrate/.', @migration_dir
89
- end
112
+ desc 'Create the database from config/disco.yml (use create:all to create all dbs in the config)'
113
+ task :create => [:environment, :'disco:db:create']
114
+
115
+ namespace :drop do
116
+ task :all => [:environment, :'disco:db:drop:all']
90
117
  end
91
118
 
92
- desc 'Migrates the database (options: VERSION=x, ENV=(projection|domain))'
93
- task :migrate => :configure_connection do
94
- ActiveRecord::Migration.verbose = true
95
- ActiveRecord::Migrator.migrate @migration_dir, ENV['VERSION'] ? ENV['VERSION'].to_i : nil
119
+ desc 'Drops the database using config/disco.yml (use drop:all to drop all databases)'
120
+ task :drop => [:environment, :'disco:db:drop']
121
+
122
+ desc 'run domain migrations'
123
+ task :migrate => [:environment, :'disco:db:migrate']
124
+
125
+ namespace :migrate do
126
+ desc 'Display status of migrations'
127
+ task :status => [:environment, :'disco:db:migrate:status']
128
+
129
+ desc 'Copy migrations from rails disco'
130
+ task :copy => [:environment, :'disco:db:migrate:copy']
131
+
132
+ desc 'Copy and run migrations from rails disco'
133
+ task :setup => [:environment, :'disco:db:migrate:setup']
134
+
135
+ desc 'drop and create, copy and run migrations from rails disco'
136
+ task :reset => [:environment, :'disco:db:migrate:reset']
96
137
  end
97
138
 
98
- desc 'Copys the domain migrations and migrates the domain database'
99
- task :setup_domain do
100
- ENV['ENV'] = 'domain'
101
- Rake::Task[:'drails:db:copy_migrations'].invoke
102
- Rake::Task[:'drails:db:migrate'].invoke
139
+ desc 'create and load schema and seeds for domain database'
140
+ task :setup => [:environment, :'disco:db:setup']
141
+ end
142
+
143
+ def reenable
144
+ Rake::Task.tasks.map &:reenable
145
+ end
146
+
147
+ desc 'creates the domain and projection databases for the current environment'
148
+ task :create do
149
+ ENV['SYSTEM'] = 'projection'
150
+ Rake::Task[:'disco:db:create'].invoke
151
+
152
+ reenable
153
+ Rake::Task[:'disco:domain:create'].invoke
154
+ end
155
+
156
+ desc 'drops the domain and projection databases for the current environment'
157
+ task :drop do
158
+ ENV['SYSTEM'] = 'projection'
159
+ Rake::Task[:'disco:db:drop'].invoke
160
+
161
+ reenable
162
+ Rake::Task[:'disco:domain:drop'].invoke
163
+ end
164
+
165
+ desc 'migrates the domain and projection databases for the current environment'
166
+ task :migrate do
167
+ ENV['SYSTEM'] = 'projection'
168
+ Rake::Task[:'disco:db:migrate'].invoke
169
+
170
+ reenable
171
+ Rake::Task[:'disco:domain:migrate'].invoke
172
+ end
173
+
174
+ desc 'Create and load schema and seeds for domain and projection databases'
175
+ task :setup do
176
+ ENV['SYSTEM'] = 'projection'
177
+ Rake::Task[:'disco:db:setup'].invoke
178
+
179
+ reenable
180
+ Rake::Task[:'disco:domain:setup'].invoke
181
+ end
182
+
183
+ desc 'Drop, recreate and load schema and seeds for domain and projection databases'
184
+ task :reset do
185
+ ENV['SYSTEM'] = 'projection'
186
+ Rake::Task[:'disco:db:drop'].invoke
187
+ Rake::Task[:'disco:db:setup'].invoke
188
+
189
+ reenable
190
+ Rake::Task[:'disco:domain:drop'].invoke
191
+ Rake::Task[:'disco:domain:setup'].invoke
192
+ end
193
+
194
+ namespace :migrate do
195
+ desc 'copies, creates and runs all migrations for domain and projection databases for the current environment'
196
+ task :setup do
197
+ ENV['SYSTEM'] = 'projection'
198
+ Rake::Task[:'disco:db:migrate:setup'].invoke
199
+
200
+ reenable
201
+ Rake::Task[:'disco:domain:migrate:setup'].invoke
103
202
  end
104
203
 
105
- desc 'Copys the projection migrations and migrates the projection database'
106
- task :setup_projection do
107
- ENV['ENV'] = 'projection'
108
- Rake::Task[:'drails:db:copy_migrations'].invoke
109
- Rake::Task[:'drails:db:migrate'].invoke
204
+ desc 'Resets your domain and projection databases using your migrations for the current environment'
205
+ task :reset do
206
+ ENV['SYSTEM'] = 'projection'
207
+ Rake::Task[:'disco:db:migrate:reset'].invoke
208
+
209
+ reenable
210
+ Rake::Task[:'disco:domain:migrate:reset'].invoke
110
211
  end
111
212
 
112
- desc 'Copys the gem migrations and migrates the domain and the projection database after'
113
- task :setup do
114
- Rake::Task[:'drails:db:setup_domain'].invoke
115
- Rake::Task[:'drails:db:environment'].reenable
116
- Rake::Task[:'drails:db:configure_connection'].reenable
117
- Rake::Task[:'drails:db:configuration'].reenable
118
- Rake::Task[:'drails:db:migrate'].reenable
119
- Rake::Task[:'drails:db:copy_migrations'].reenable
120
- Rake::Task[:'drails:db:setup_projection'].invoke
213
+ desc 'Display status of domain and projection migrations'
214
+ task :status do
215
+ ENV['SYSTEM'] = 'projection'
216
+ Rake::Task[:'disco:db:migrate:status'].invoke
217
+
218
+ reenable
219
+ Rake::Task[:'disco:domain:migrate:status'].invoke
121
220
  end
122
221
  end
123
- end
222
+ end