drailties 0.4.3 → 0.5.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +6 -14
- data/bin/drails +4 -42
- data/lib/drails/app_drails_loader.rb +62 -0
- data/lib/drails/cli.rb +11 -0
- data/lib/drails/commands/application.rb +43 -0
- data/lib/drails/commands/destroy.rb +12 -0
- data/lib/drails/commands/domainserver.rb +6 -0
- data/lib/drails/commands/generate.rb +12 -0
- data/lib/drails/commands/projectionserver.rb +9 -0
- data/lib/drails/commands/server.rb +22 -0
- data/lib/drails/commands.rb +70 -0
- data/lib/drails/generators.rb +48 -0
- data/lib/drails/server/domain_server.rb +4 -1
- data/lib/drails/server/projection_servers.rb +5 -2
- data/lib/generators/drails/app/USAGE +12 -12
- data/lib/generators/drails/app/app_generator.rb +134 -52
- data/lib/generators/drails/app/templates/{event_source_controller.rb → app/controllers/event_source_controller.rb} +15 -15
- data/lib/generators/drails/app/templates/bin/drails +3 -0
- data/lib/generators/drails/app/templates/config/disco.yml +27 -0
- data/lib/generators/drails/app/templates/{build_validations_registry.rb → config/initializers/build_validations_registry.rb} +18 -18
- data/lib/generators/drails/app/templates/{create_domain.rb → config/initializers/create_domain.rb} +4 -4
- data/lib/generators/drails/app/templates/db/seeds.rb +14 -0
- data/lib/generators/drails/command/USAGE +11 -11
- data/lib/generators/drails/command/command_generator.rb +68 -40
- data/lib/generators/drails/command/templates/command.rb +24 -6
- data/lib/generators/drails/command/templates/event.rb +11 -10
- data/lib/generators/drails/command_processor/USAGE +1 -1
- data/lib/generators/drails/command_processor/command_processor_generator.rb +22 -15
- data/lib/generators/drails/command_processor/templates/command_processor.rb +5 -5
- data/lib/generators/drails/domain.rb +18 -18
- data/lib/generators/drails/event_name.rb +51 -51
- data/lib/generators/drails/migration/USAGE +41 -1
- data/lib/generators/drails/migration/migration_generator.rb +27 -28
- data/lib/generators/drails/migration/templates/create_table_migration.rb +19 -19
- data/lib/generators/drails/model/USAGE +17 -17
- data/lib/generators/drails/model/model_generator.rb +29 -23
- data/lib/generators/drails/model/templates/domain_model.rb +5 -5
- data/lib/generators/drails/model/templates/model.rb +4 -4
- data/lib/generators/drails/processor_name.rb +47 -47
- data/lib/generators/drails/projection/projection_generator.rb +3 -3
- data/lib/generators/drails/projection/templates/domain_projection.rb +9 -9
- data/lib/generators/drails/projection/templates/domain_projection_test.rb +6 -6
- data/lib/generators/drails/projection/templates/projection.rb +9 -9
- data/lib/generators/drails/projection/templates/projection_test.rb +6 -6
- data/lib/generators/drails/scaffold/USAGE +26 -26
- data/lib/generators/drails/scaffold/scaffold_generator.rb +91 -89
- data/lib/generators/drails/scaffold/templates/_eventstream.js.erb +15 -15
- data/lib/generators/drails/{controller → scaffold_controller}/USAGE +1 -1
- data/lib/generators/drails/{controller/controller_generator.rb → scaffold_controller/scaffold_controller_generator.rb} +27 -26
- data/lib/generators/drails/scaffold_controller/templates/controller.rb +68 -0
- data/lib/generators/drails/{controller → scaffold_controller}/templates/controller_test.rb +45 -45
- data/lib/generators/drails/use_domain_option.rb +53 -53
- data/lib/rails-disco/version.rb +3 -3
- data/lib/tasks/db.rake +187 -88
- metadata +33 -27
- data/lib/drails/application.rb +0 -8
- data/lib/drails/domainserver.rb +0 -5
- data/lib/drails/generate.rb +0 -21
- data/lib/drails/projectionserver.rb +0 -8
- data/lib/drails/server.rb +0 -18
- data/lib/generators/drails/app/templates/disco.yml +0 -54
- data/lib/generators/drails/controller/templates/controller.rb +0 -67
@@ -0,0 +1,27 @@
|
|
1
|
+
development:
|
2
|
+
<%= domain_database(:development, 2) -%>
|
3
|
+
drb_server:
|
4
|
+
scheme: druby
|
5
|
+
host: 127.0.0.1
|
6
|
+
port: 8787
|
7
|
+
event_connection:
|
8
|
+
scheme: amqp
|
9
|
+
host: 127.0.0.1
|
10
|
+
port: 5672
|
11
|
+
event_exchange: events
|
12
|
+
|
13
|
+
test:
|
14
|
+
<%= domain_database(:test, 2) -%>
|
15
|
+
|
16
|
+
production:
|
17
|
+
<%= domain_database(:production, 2) -%>
|
18
|
+
drb_server:
|
19
|
+
protocol: druby
|
20
|
+
host: 127.0.0.1
|
21
|
+
port: 8787
|
22
|
+
event_connection:
|
23
|
+
scheme: amqp
|
24
|
+
userinfo: amqp:password
|
25
|
+
host: 127.0.0.1
|
26
|
+
port: 9797
|
27
|
+
event_exchange: events
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require 'active_event'
|
2
|
-
require 'active_projection'
|
3
|
-
ActiveEvent::Autoload.app_path = File.expand_path('../../..', __FILE__)
|
4
|
-
ActiveProjection::Autoload.app_path = File.expand_path('../../..', __FILE__)
|
5
|
-
LOGGER = ActiveEvent::Support::MultiLogger.new 'Rails Server'
|
6
|
-
|
7
|
-
watchable_dirs = ActiveEvent::Autoload.watchable_dirs.merge ActiveProjection::Autoload.watchable_dirs
|
8
|
-
RELOADER = ActiveSupport::FileUpdateChecker.new([], watchable_dirs) do
|
9
|
-
ActiveEvent::Autoload.reload_module :ValidationsRegistry
|
10
|
-
ActiveEvent::Autoload.reload
|
11
|
-
ActiveProjection::Autoload.reload
|
12
|
-
ActiveEvent::ValidationsRegistry.build
|
13
|
-
end
|
14
|
-
|
15
|
-
ActionDispatch::Reloader.to_prepare do
|
16
|
-
RELOADER.execute_if_updated
|
17
|
-
end
|
18
|
-
|
1
|
+
require 'active_event'
|
2
|
+
require 'active_projection'
|
3
|
+
ActiveEvent::Autoload.app_path = File.expand_path('../../..', __FILE__)
|
4
|
+
ActiveProjection::Autoload.app_path = File.expand_path('../../..', __FILE__)
|
5
|
+
LOGGER = ActiveEvent::Support::MultiLogger.new 'Rails Server'
|
6
|
+
|
7
|
+
watchable_dirs = ActiveEvent::Autoload.watchable_dirs.merge ActiveProjection::Autoload.watchable_dirs
|
8
|
+
RELOADER = ActiveSupport::FileUpdateChecker.new([], watchable_dirs) do
|
9
|
+
ActiveEvent::Autoload.reload_module :ValidationsRegistry
|
10
|
+
ActiveEvent::Autoload.reload
|
11
|
+
ActiveProjection::Autoload.reload
|
12
|
+
ActiveEvent::ValidationsRegistry.build
|
13
|
+
end
|
14
|
+
|
15
|
+
ActionDispatch::Reloader.to_prepare do
|
16
|
+
RELOADER.execute_if_updated
|
17
|
+
end
|
18
|
+
|
19
19
|
ActiveEvent::ValidationsRegistry.build
|
data/lib/generators/drails/app/templates/{create_domain.rb → config/initializers/create_domain.rb}
RENAMED
@@ -1,5 +1,5 @@
|
|
1
|
-
<% module_namespacing do -%>
|
2
|
-
class Domain
|
3
|
-
include ::ActiveEvent::Domain
|
4
|
-
end
|
1
|
+
<% module_namespacing do -%>
|
2
|
+
class Domain
|
3
|
+
include ::ActiveEvent::Domain
|
4
|
+
end
|
5
5
|
<% end -%>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#
|
2
|
+
# With Rails Disco you can invoke domain commands
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# city_id = domain_run(CityCreateCommand.new(name: 'Chicago'))
|
7
|
+
# domain_run(MayorCreateCommand(name: 'Emanuel', city_id: city_id)
|
8
|
+
@@can_run = true
|
9
|
+
def domain_run(command)
|
10
|
+
Domain.run_command(command) if @@can_run
|
11
|
+
rescue DRb::DRbConnError
|
12
|
+
puts 'no domain server for seeds'
|
13
|
+
@@can_run = false
|
14
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
Description:
|
2
|
-
Generates a Command, an Event and adds it to the CommandProcessor or creates one.
|
3
|
-
|
4
|
-
Example:
|
5
|
-
rails generate drails:command CreateThing [attr1, attr2] --event=CreatedThing --processor=Things
|
6
|
-
|
7
|
-
This will create:
|
8
|
-
app/commands/create_thing_command.rb
|
9
|
-
app/events/created_thing_event.rb
|
10
|
-
domain/command_processors/things_processor.rb unless it exists
|
11
|
-
Adds a command handler to this or an existing processor
|
1
|
+
Description:
|
2
|
+
Generates a Command, an Event and adds it to the CommandProcessor or creates one.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate drails:command CreateThing [attr1, attr2] --event=CreatedThing --processor=Things
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
app/commands/create_thing_command.rb
|
9
|
+
app/events/created_thing_event.rb
|
10
|
+
domain/command_processors/things_processor.rb unless it exists
|
11
|
+
Adds a command handler to this or an existing processor
|
@@ -1,40 +1,68 @@
|
|
1
|
-
require 'generators/drails/processor_name.rb'
|
2
|
-
require 'generators/drails/event_name.rb'
|
3
|
-
require 'generators/drails/domain.rb'
|
4
|
-
|
5
|
-
module Drails
|
6
|
-
module Generators
|
7
|
-
class CommandGenerator < Rails::Generators::NamedBase
|
8
|
-
source_root File.expand_path('../templates', __FILE__)
|
9
|
-
argument :attributes, type: :array, default: [], banner:
|
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
|
-
|
1
|
+
require 'generators/drails/processor_name.rb'
|
2
|
+
require 'generators/drails/event_name.rb'
|
3
|
+
require 'generators/drails/domain.rb'
|
4
|
+
|
5
|
+
module Drails
|
6
|
+
module Generators
|
7
|
+
class CommandGenerator < Rails::Generators::NamedBase
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
argument :attributes, type: :array, default: [], banner: 'attribute attribute'
|
10
|
+
class_option :skip_model, type: :boolean, default: false, desc: 'Skip active model from the command'
|
11
|
+
class_option :model_name, type: :string, desc: 'Name of the active model behind the command'
|
12
|
+
class_option :persisted, type: :boolean, default: false, desc: 'Does the command update an existing model'
|
13
|
+
include ProcessorName
|
14
|
+
include EventName
|
15
|
+
include Domain
|
16
|
+
|
17
|
+
def create_command_file
|
18
|
+
template 'command.rb', File.join('app/commands', class_path, "#{file_name}_command.rb")
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_related_event_file
|
22
|
+
return if skip_event?
|
23
|
+
template 'event.rb', File.join('app/events', event_class_path, "#{event_file_name}_event.rb")
|
24
|
+
end
|
25
|
+
|
26
|
+
hook_for :command_processor, require: true do |hook|
|
27
|
+
unless skip_processor?
|
28
|
+
invoke hook, [processor_file_path], %w(-s --skip-namespace)
|
29
|
+
add_to_command_processor
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def add_to_command_processor
|
36
|
+
return if skip_processor? || (behavior == :revoke)
|
37
|
+
content = "
|
38
|
+
|
39
|
+
process #{class_name}Command do |command|
|
40
|
+
command.is_valid_do { event #{event_class_name}Event.new command.to_hash }
|
41
|
+
end"
|
42
|
+
file = File.join('domain/command_processors', processor_domain_class_path, "#{processor_file_name}_processor.rb")
|
43
|
+
inject_into_file file, content, after: /(\s)*include(\s)*ActiveDomain::CommandProcessor/
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
def skip_model?
|
49
|
+
options[:skip_model]
|
50
|
+
end
|
51
|
+
|
52
|
+
def model_name
|
53
|
+
options[:model_name]
|
54
|
+
end
|
55
|
+
|
56
|
+
def persisted?
|
57
|
+
options[:persisted]
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
# allow this generator to be called multiple times
|
63
|
+
def invoke_command(command, *args) #:nodoc:
|
64
|
+
command.run(self, *args)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,6 +1,24 @@
|
|
1
|
-
<% module_namespacing do -%>
|
2
|
-
class <%= class_name %>Command
|
3
|
-
|
4
|
-
|
5
|
-
end
|
6
|
-
|
1
|
+
<% module_namespacing do -%>
|
2
|
+
class <%= class_name %>Command
|
3
|
+
<%- unless skip_model? -%>
|
4
|
+
include ActiveModel::Model
|
5
|
+
<%- end -%>
|
6
|
+
include ActiveEvent::Command
|
7
|
+
attributes <%= (['id'] + attributes_names).map{|x| ":#{x}"}.join(', ') %>
|
8
|
+
<%- if !model_name.blank? && !skip_model? -%>
|
9
|
+
|
10
|
+
def self.model_name
|
11
|
+
@_model_name ||= begin
|
12
|
+
namespace = self.parents.detect do |n|
|
13
|
+
n.respond_to?(:use_relative_model_naming?) && n.use_relative_model_naming?
|
14
|
+
end
|
15
|
+
ActiveModel::Name.new(self, namespace, <%= model_name.inspect %>)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
<%- end -%>
|
19
|
+
<%- if persisted? && ! skip_model? -%>
|
20
|
+
|
21
|
+
def persisted?; true end
|
22
|
+
<%- end -%>
|
23
|
+
end
|
24
|
+
<% end -%>
|
@@ -1,10 +1,11 @@
|
|
1
|
-
<% module_namespacing do -%>
|
2
|
-
class <%= event_class_name %>Event
|
3
|
-
include ActiveEvent::EventType
|
4
|
-
attributes
|
5
|
-
|
6
|
-
def values
|
7
|
-
attributes_except :id
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
1
|
+
<% module_namespacing do -%>
|
2
|
+
class <%= event_class_name %>Event
|
3
|
+
include ActiveEvent::EventType
|
4
|
+
attributes <%= (['id'] + attributes_names).map{|x| ":#{x}"}.join(', ') %>
|
5
|
+
<%- unless attributes_names.empty? -%>
|
6
|
+
def values
|
7
|
+
attributes_except :id
|
8
|
+
end
|
9
|
+
<%- end -%>
|
10
|
+
end
|
11
|
+
<% end -%>
|
@@ -1 +1 @@
|
|
1
|
-
Not intended for extern use!
|
1
|
+
Not intended for extern use!
|
@@ -1,15 +1,22 @@
|
|
1
|
-
require 'generators/drails/domain.rb'
|
2
|
-
|
3
|
-
module Drails
|
4
|
-
module Generators
|
5
|
-
class CommandProcessorGenerator < Rails::Generators::NamedBase
|
6
|
-
source_root File.expand_path('../templates', __FILE__)
|
7
|
-
include Domain
|
8
|
-
hide!
|
9
|
-
|
10
|
-
def create_command_processor_file
|
11
|
-
template 'command_processor.rb', File.join('domain/command_processors', domain_class_path, "#{file_name}_processor.rb")
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
|
1
|
+
require 'generators/drails/domain.rb'
|
2
|
+
|
3
|
+
module Drails
|
4
|
+
module Generators
|
5
|
+
class CommandProcessorGenerator < Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
include Domain
|
8
|
+
hide!
|
9
|
+
|
10
|
+
def create_command_processor_file
|
11
|
+
template 'command_processor.rb', File.join('domain/command_processors', domain_class_path, "#{file_name}_processor.rb")
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# allow this generator to be called multiple times
|
17
|
+
def invoke_command(command, *args) #:nodoc:
|
18
|
+
command.run(self, *args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module <%=
|
2
|
-
class <%= class_name %>Processor
|
3
|
-
include ActiveDomain::CommandProcessor
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module <%= Rails::Generators.namespace.name if Rails::Generators.namespace.present? %>Domain
|
2
|
+
class <%= class_name %>Processor
|
3
|
+
include ActiveDomain::CommandProcessor
|
4
|
+
end
|
5
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
|
3
|
-
module Drails
|
4
|
-
module Generators
|
5
|
-
module Domain
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
def domain_class_path
|
9
|
-
@domain_calss_path ||= class_path_domain class_path
|
10
|
-
end
|
11
|
-
|
12
|
-
protected
|
13
|
-
|
14
|
-
def class_path_domain(class_path)
|
15
|
-
(Array.new class_path).unshift 'domain'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Drails
|
4
|
+
module Generators
|
5
|
+
module Domain
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
def domain_class_path
|
9
|
+
@domain_calss_path ||= class_path_domain class_path
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def class_path_domain(class_path)
|
15
|
+
(Array.new class_path).unshift 'domain'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
19
|
end
|
@@ -1,52 +1,52 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
|
3
|
-
module Drails
|
4
|
-
module Generators
|
5
|
-
module EventName
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
class_option :event, type: :string, default: nil, desc: "name of the event (defaults to NAME)"
|
10
|
-
class_option :skip_event, type: :boolean, default: false, desc: "skip event generation"
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(args, *options)
|
14
|
-
super
|
15
|
-
assign_event_name!(event_name)
|
16
|
-
end
|
17
|
-
|
18
|
-
protected
|
19
|
-
|
20
|
-
attr_reader :event_file_name
|
21
|
-
attr_reader :event_class_path
|
22
|
-
|
23
|
-
def skip_event?
|
24
|
-
options[:skip_event]
|
25
|
-
end
|
26
|
-
|
27
|
-
def event_name
|
28
|
-
options[:event] || name
|
29
|
-
end
|
30
|
-
|
31
|
-
def event_class_name
|
32
|
-
(event_class_path + [event_file_name]).map!{ |m| m.camelize }.join('::')
|
33
|
-
end
|
34
|
-
|
35
|
-
def event_file_path
|
36
|
-
@event_file_path ||= (event_class_path + [event_file_name]).join('/')
|
37
|
-
end
|
38
|
-
|
39
|
-
def event_domain_class_path
|
40
|
-
@event_domain_class_path ||= class_path_domain event_class_path
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def assign_event_name!(event_name)
|
46
|
-
@event_class_path = event_name.include?('/') ? event_name.split('/') : event_name.split('::')
|
47
|
-
@event_class_path.map! &:underscore
|
48
|
-
@event_file_name = @event_class_path.pop
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Drails
|
4
|
+
module Generators
|
5
|
+
module EventName
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
class_option :event, type: :string, default: nil, desc: "name of the event (defaults to NAME)"
|
10
|
+
class_option :skip_event, type: :boolean, default: false, desc: "skip event generation"
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(args, *options)
|
14
|
+
super
|
15
|
+
assign_event_name!(event_name)
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
attr_reader :event_file_name
|
21
|
+
attr_reader :event_class_path
|
22
|
+
|
23
|
+
def skip_event?
|
24
|
+
options[:skip_event]
|
25
|
+
end
|
26
|
+
|
27
|
+
def event_name
|
28
|
+
options[:event] || name
|
29
|
+
end
|
30
|
+
|
31
|
+
def event_class_name
|
32
|
+
(event_class_path + [event_file_name]).map!{ |m| m.camelize }.join('::')
|
33
|
+
end
|
34
|
+
|
35
|
+
def event_file_path
|
36
|
+
@event_file_path ||= (event_class_path + [event_file_name]).join('/')
|
37
|
+
end
|
38
|
+
|
39
|
+
def event_domain_class_path
|
40
|
+
@event_domain_class_path ||= class_path_domain event_class_path
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def assign_event_name!(event_name)
|
46
|
+
@event_class_path = event_name.include?('/') ? event_name.split('/') : event_name.split('::')
|
47
|
+
@event_class_path.map! &:underscore
|
48
|
+
@event_file_name = @event_class_path.pop
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
52
|
end
|
@@ -1 +1,41 @@
|
|
1
|
-
|
1
|
+
Description:
|
2
|
+
Stubs out a new database migration for ActiveRecord. Pass the migration name, either
|
3
|
+
CamelCased or under_scored, and an optional list of attribute pairs as arguments.
|
4
|
+
|
5
|
+
A migration class is generated in db/migrate prefixed by a timestamp of the current date and time.
|
6
|
+
|
7
|
+
You can name your migration in either of these formats to generate add/remove
|
8
|
+
column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable
|
9
|
+
|
10
|
+
Example:
|
11
|
+
`drails generate migration AddSslFlag`
|
12
|
+
|
13
|
+
If the current date is May 14, 2008 and the current time 09:09:12, this creates the AddSslFlag migration
|
14
|
+
db/migrate/20080514090912_add_ssl_flag.rb
|
15
|
+
|
16
|
+
`drails generate migration AddSslFlag --domain`
|
17
|
+
|
18
|
+
Under the same conditions as above, this creates the AddSslFlag migration
|
19
|
+
db/migrate_domain/20080514090912_add_ssl_flag.rb
|
20
|
+
|
21
|
+
`drails generate migration AddTitleBodyToPost title:string body:text published:boolean`
|
22
|
+
|
23
|
+
This will create the AddTitleBodyToPost in db/migrate/20080514090912_add_title_body_to_post.rb with this in the Change migration:
|
24
|
+
|
25
|
+
add_column :posts, :title, :string
|
26
|
+
add_column :posts, :body, :text
|
27
|
+
add_column :posts, :published, :boolean
|
28
|
+
|
29
|
+
Migration names containing JoinTable will generate join tables for use with
|
30
|
+
has_and_belongs_to_many associations.
|
31
|
+
|
32
|
+
Example:
|
33
|
+
`drails g migration CreateMediaJoinTable artists musics:uniq`
|
34
|
+
|
35
|
+
will create the migration
|
36
|
+
|
37
|
+
create_join_table :artists, :musics do |t|
|
38
|
+
# t.index [:artist_id, :music_id]
|
39
|
+
t.index [:music_id, :artist_id], unique: true
|
40
|
+
end
|
41
|
+
|
@@ -1,28 +1,27 @@
|
|
1
|
-
require 'rails/generators/active_record/migration/migration_generator'
|
2
|
-
require 'generators/drails/use_domain_option.rb'
|
3
|
-
|
4
|
-
module Drails
|
5
|
-
module Generators
|
6
|
-
class MigrationGenerator < ActiveRecord::Generators::MigrationGenerator
|
7
|
-
source_root File.expand_path('../templates', __FILE__)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
1
|
+
require 'rails/generators/active_record/migration/migration_generator'
|
2
|
+
require 'generators/drails/use_domain_option.rb'
|
3
|
+
|
4
|
+
module Drails
|
5
|
+
module Generators
|
6
|
+
class MigrationGenerator < ActiveRecord::Generators::MigrationGenerator
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
include UseDomainOption
|
9
|
+
|
10
|
+
def create_migration_file
|
11
|
+
set_local_assigns!
|
12
|
+
validate_file_name!
|
13
|
+
migration_template @migration_template, "db/#{migration_dir}/#{file_name}.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def migration_dir
|
19
|
+
if use_domain?
|
20
|
+
'migrate_domain'
|
21
|
+
else
|
22
|
+
'migrate'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :<%= table_name %> do |t|
|
4
|
-
<% attributes.each do |attribute| -%>
|
5
|
-
<% if attribute.password_digest? -%>
|
6
|
-
t.string :password_digest<%= attribute.inject_options %>
|
7
|
-
<% else -%>
|
8
|
-
t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
|
9
|
-
<% end -%>
|
10
|
-
<% end -%>
|
11
|
-
<% if options[:timestamps] %>
|
12
|
-
t.timestamps
|
13
|
-
<% end -%>
|
14
|
-
end
|
15
|
-
<% attributes_with_index.each do |attribute| -%>
|
16
|
-
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
17
|
-
<% end -%>
|
18
|
-
end
|
19
|
-
end
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :<%= table_name %> do |t|
|
4
|
+
<% attributes.each do |attribute| -%>
|
5
|
+
<% if attribute.password_digest? -%>
|
6
|
+
t.string :password_digest<%= attribute.inject_options %>
|
7
|
+
<% else -%>
|
8
|
+
t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
|
9
|
+
<% end -%>
|
10
|
+
<% end -%>
|
11
|
+
<% if options[:timestamps] %>
|
12
|
+
t.timestamps
|
13
|
+
<% end -%>
|
14
|
+
end
|
15
|
+
<% attributes_with_index.each do |attribute| -%>
|
16
|
+
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
17
|
+
<% end -%>
|
18
|
+
end
|
19
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
Description:
|
2
|
-
Generates a Model and a Projection for it.
|
3
|
-
|
4
|
-
Example:
|
5
|
-
rails generate drails:model Thing [attr1:type, attr2:type]
|
6
|
-
|
7
|
-
This will create:
|
8
|
-
app/projection/thing_projection.rb
|
9
|
-
app/models/thing.rb
|
10
|
-
db/migrate/create_thing.rb
|
11
|
-
|
12
|
-
rails generate drails:model Thing [attr1:type, attr2:type] --domain
|
13
|
-
|
14
|
-
This will create:
|
15
|
-
domain/projections/domain/thing_projection.rb
|
16
|
-
domain/models/domain/thing.rb
|
17
|
-
db/migrate_domain/create_thing.rb
|
1
|
+
Description:
|
2
|
+
Generates a Model and a Projection for it.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate drails:model Thing [attr1:type, attr2:type]
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
app/projection/thing_projection.rb
|
9
|
+
app/models/thing.rb
|
10
|
+
db/migrate/create_thing.rb
|
11
|
+
|
12
|
+
rails generate drails:model Thing [attr1:type, attr2:type] --domain
|
13
|
+
|
14
|
+
This will create:
|
15
|
+
domain/projections/domain/thing_projection.rb
|
16
|
+
domain/models/domain/thing.rb
|
17
|
+
db/migrate_domain/create_thing.rb
|