physique 0.3.10 → 0.4.0
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 +4 -4
- data/FLUENT_MIGRATOR.md +300 -300
- data/Gemfile +3 -3
- data/Gemfile.lock +51 -11
- data/Guardfile +34 -0
- data/README.md +368 -368
- data/RUBY_SETUP.md +14 -14
- data/Rakefile +1 -1
- data/lib/physique.rb +22 -22
- data/lib/physique/config.rb +23 -23
- data/lib/physique/dsl.rb +46 -46
- data/lib/physique/project_path_resolver.rb +45 -45
- data/lib/physique/solution.rb +72 -72
- data/lib/physique/task_builders/build.rb +76 -69
- data/lib/physique/task_builders/default.rb +19 -19
- data/lib/physique/task_builders/fluent_migrator.rb +302 -299
- data/lib/physique/task_builders/nuget.rb +18 -6
- data/lib/physique/task_builders/octopus.rb +4 -2
- data/lib/physique/task_builders/publish_nugets.rb +5 -3
- data/lib/physique/task_builders/test.rb +4 -4
- data/lib/physique/tasks/fluent_migrator.rb +158 -158
- data/lib/physique/tasks/nugets_pack.rb +12 -12
- data/lib/physique/tasks/octopus_pack.rb +1 -1
- data/lib/physique/tasks/sqlcmd.rb +109 -109
- data/lib/physique/tasks/versionizer.rb +112 -112
- data/lib/physique/tasks_builder.rb +59 -59
- data/lib/physique/tool_locator.rb +50 -50
- data/lib/physique/version.rb +3 -3
- data/physique.gemspec +29 -28
- data/spec/fluent_migrator_config_spec.rb +39 -39
- data/spec/project_spec.rb +42 -42
- data/spec/publish_nugets_spec.rb +40 -40
- data/spec/solution_spec.rb +11 -11
- data/spec/sqlcmd_spec.rb +146 -146
- data/spec/support/shared_contexts/rake.rb +20 -21
- data/spec/task_builders/build_spec.rb +25 -25
- data/spec/task_builders/default_spec.rb +17 -17
- data/spec/task_builders/fluent_migrator_spec.rb +70 -68
- data/spec/task_builders/nspec_spec.rb +13 -13
- data/spec/task_builders/nuget_spec.rb +16 -16
- data/spec/test_data/solutions/.nuget/NuGet.Config +5 -5
- data/spec/test_data/solutions/.nuget/NuGet.exe +0 -0
- data/spec/test_data/solutions/.nuget/NuGet.targets +144 -144
- data/spec/test_data/solutions/.nuget/packages.config +3 -3
- data/spec/test_data/solutions/basic/.semver +6 -6
- data/spec/test_data/solutions/basic/Basic.Tests/Basic.Tests.csproj +58 -58
- data/spec/test_data/solutions/basic/Basic.Tests/Class1.cs +14 -14
- data/spec/test_data/solutions/basic/Basic.Tests/Properties/AssemblyInfo.cs +36 -36
- data/spec/test_data/solutions/basic/Basic.Tests/packages.config +3 -3
- data/spec/test_data/solutions/basic/Basic.sln +28 -28
- data/spec/test_data/solutions/basic/Basic/Basic.csproj +52 -52
- data/spec/test_data/solutions/basic/Basic/Class1.cs +12 -12
- data/spec/test_data/solutions/basic/Basic/Properties/AssemblyInfo.cs +36 -36
- data/spec/test_data/solutions/basic/Rakefile.rb +10 -10
- data/spec/test_data/solutions/basic/packages.config +3 -3
- data/spec/test_data/solutions/fluent-migrator/.semver +6 -6
- data/spec/test_data/solutions/fluent-migrator/Basic.Migrations/Migrations/.gitkeep +0 -0
- data/spec/test_data/solutions/fluent-migrator/Basic.Migrations/Properties/AssemblyInfo.cs +36 -36
- data/spec/test_data/solutions/fluent-migrator/Basic.Migrations/TestMigration.cs +19 -19
- data/spec/test_data/solutions/fluent-migrator/Basic.Migrations/_Scripts/create.sql +1 -1
- data/spec/test_data/solutions/fluent-migrator/Basic.Migrations/_Scripts/drop.sql +4 -4
- data/spec/test_data/solutions/fluent-migrator/Basic.Migrations/_Scripts/seed.sql +1 -1
- data/spec/test_data/solutions/fluent-migrator/Basic.Migrations/packages.config +3 -3
- data/spec/test_data/solutions/fluent-migrator/Basic.Specs/Basic.Specs.csproj +59 -59
- data/spec/test_data/solutions/fluent-migrator/Basic.Specs/Class1.cs +12 -12
- data/spec/test_data/solutions/fluent-migrator/Basic.Specs/DebuggerShim.cs +42 -42
- data/spec/test_data/solutions/fluent-migrator/Basic.Specs/Properties/AssemblyInfo.cs +36 -36
- data/spec/test_data/solutions/fluent-migrator/Basic.Specs/packages.config +3 -3
- data/spec/test_data/solutions/fluent-migrator/Basic.sln +39 -39
- data/spec/test_data/solutions/fluent-migrator/Basic/Basic.csproj +55 -55
- data/spec/test_data/solutions/fluent-migrator/Basic/Class1.cs +12 -12
- data/spec/test_data/solutions/fluent-migrator/Basic/Properties/AssemblyInfo.cs +36 -36
- data/spec/test_data/solutions/fluent-migrator/Basic/packages.config +2 -2
- data/spec/test_data/solutions/fluent-migrator/Rakefile.rb +20 -20
- data/spec/test_data/solutions/multiple-fluent-migrator/.semver +6 -6
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic.Migrations1/Basic.Migrations1.csproj +52 -52
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic.Migrations1/Class1.cs +12 -12
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic.Migrations1/Properties/AssemblyInfo.cs +36 -36
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic.Migrations2/Basic.Migrations2.csproj +52 -52
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic.Migrations2/Class1.cs +12 -12
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic.Migrations2/Properties/AssemblyInfo.cs +36 -36
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic.Specs/Basic.Specs.csproj +59 -59
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic.Specs/Class1.cs +12 -12
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic.Specs/DebuggerShim.cs +42 -42
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic.Specs/Properties/AssemblyInfo.cs +36 -36
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic.Specs/packages.config +3 -3
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic.sln +45 -45
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic/Basic.csproj +55 -55
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic/Class1.cs +12 -12
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic/Properties/AssemblyInfo.cs +36 -36
- data/spec/test_data/solutions/multiple-fluent-migrator/Basic/packages.config +2 -2
- data/spec/test_data/solutions/multiple-fluent-migrator/Rakefile.rb +28 -28
- data/spec/test_data/solutions/nspec/.semver +6 -6
- data/spec/test_data/solutions/nspec/Basic.Specs/Basic.Specs.csproj +59 -59
- data/spec/test_data/solutions/nspec/Basic.Specs/Class1.cs +12 -12
- data/spec/test_data/solutions/nspec/Basic.Specs/DebuggerShim.cs +42 -42
- data/spec/test_data/solutions/nspec/Basic.Specs/Properties/AssemblyInfo.cs +36 -36
- data/spec/test_data/solutions/nspec/Basic.Specs/packages.config +3 -3
- data/spec/test_data/solutions/nspec/Basic.sln +28 -28
- data/spec/test_data/solutions/nspec/Basic/Basic.csproj +55 -55
- data/spec/test_data/solutions/nspec/Basic/Class1.cs +12 -12
- data/spec/test_data/solutions/nspec/Basic/Properties/AssemblyInfo.cs +36 -36
- data/spec/test_data/solutions/nspec/Basic/packages.config +2 -2
- data/spec/test_data/solutions/nspec/Rakefile.rb +14 -14
- data/spec/test_data/tool_locator/Program Files/Microsoft SQL Server/110/Tools/Binn/SQLCMD.exe.txt b/data/spec/test_data/tool_locator/Program Files/Microsoft SQL → Server/110/Tools/Binn/SQLCMD.exe.txt +0 -0
- data/spec/test_data/tool_locator/Windows/Microsoft.NET/Framework/v3.5/MSBuild.exe.txt +0 -0
- data/spec/test_data/tool_locator/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe.txt +0 -0
- data/spec/tool_locator_spec.rb +27 -29
- metadata +33 -16
@@ -1,69 +1,76 @@
|
|
1
|
-
module Physique
|
2
|
-
class CompileConfig
|
3
|
-
attr_writer :default_targets, # Default build targets for compile task
|
4
|
-
:configuration, # Build configuration (Release, Debug, etc.)
|
5
|
-
:logging # MSBuild Logging level (normal, verbose, etc.)
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@default_targets = %w(
|
9
|
-
@targets = %w(Clean Build Rebuild)
|
10
|
-
end
|
11
|
-
|
12
|
-
def
|
13
|
-
@
|
14
|
-
end
|
15
|
-
|
16
|
-
def
|
17
|
-
@targets
|
18
|
-
end
|
19
|
-
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
configuration:
|
30
|
-
logging:
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
|
1
|
+
module Physique
|
2
|
+
class CompileConfig
|
3
|
+
attr_writer :default_targets, # Default build targets for compile task
|
4
|
+
:configuration, # Build configuration (Release, Debug, etc.)
|
5
|
+
:logging # MSBuild Logging level (normal, verbose, etc.)
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@default_targets = %w(Rebuild)
|
9
|
+
@targets = %w(Clean Build Rebuild)
|
10
|
+
end
|
11
|
+
|
12
|
+
def disable_versioning
|
13
|
+
@disable_versioning = true
|
14
|
+
end
|
15
|
+
|
16
|
+
def clear_targets
|
17
|
+
@targets.clear
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_target(val)
|
21
|
+
@targets << val
|
22
|
+
end
|
23
|
+
|
24
|
+
def opts
|
25
|
+
raise ArgumentError, 'You must specify the default targets' if @default_targets.blank?
|
26
|
+
|
27
|
+
Map.new({
|
28
|
+
default_targets: @default_targets,
|
29
|
+
configuration: @configuration,
|
30
|
+
logging: @logging,
|
31
|
+
targets: @targets,
|
32
|
+
disable_versioning: !!@disable_versioning
|
33
|
+
}).apply(
|
34
|
+
configuration: 'Release',
|
35
|
+
logging: 'minimal'
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class BuildTasksBuilder < TasksBuilder
|
41
|
+
def build_tasks
|
42
|
+
add_version_task
|
43
|
+
add_compile_tasks
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def add_version_task
|
49
|
+
return if solution.compile.disable_versioning
|
50
|
+
|
51
|
+
require 'albacore/tasks/versionizer'
|
52
|
+
Albacore::Tasks::Versionizer.new :versionizer
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_compile_tasks
|
56
|
+
block = lambda(&method(:configure_build))
|
57
|
+
|
58
|
+
desc 'Builds the solution'
|
59
|
+
build :compile => [ :restore ], &block.curry.(solution.compile.default_targets)
|
60
|
+
|
61
|
+
namespace :compile do
|
62
|
+
solution.compile.targets.each do |t|
|
63
|
+
desc "Builds the solution using the #{t} target"
|
64
|
+
build t.downcase, &block.curry.(t)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def configure_build(target, config)
|
70
|
+
config.sln = solution.file
|
71
|
+
config.prop 'Configuration', solution.compile.configuration
|
72
|
+
config.logging = solution.compile.logging
|
73
|
+
config.target = target
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
module Physique
|
2
|
-
class DefaultTasksBuilder < TasksBuilder
|
3
|
-
|
4
|
-
def build_phases
|
5
|
-
task :version
|
6
|
-
task :restore => [ :version ]
|
7
|
-
task :compile => [ :restore ]
|
8
|
-
task :test => [ :compile ]
|
9
|
-
task :package => [ :test ]
|
10
|
-
task :publish => [ :package ]
|
11
|
-
task :default => [ :test ]
|
12
|
-
end
|
13
|
-
|
14
|
-
def build_tasks
|
15
|
-
task :default => [ :test ]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
1
|
+
module Physique
|
2
|
+
class DefaultTasksBuilder < TasksBuilder
|
3
|
+
|
4
|
+
def build_phases
|
5
|
+
task :version
|
6
|
+
task :restore => [ :version ]
|
7
|
+
task :compile => [ :restore ]
|
8
|
+
task :test => [ :compile ]
|
9
|
+
task :package => [ :test ]
|
10
|
+
task :publish => [ :package ]
|
11
|
+
task :default => [ :test ]
|
12
|
+
end
|
13
|
+
|
14
|
+
def build_tasks
|
15
|
+
task :default => [ :test ]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -1,299 +1,302 @@
|
|
1
|
-
require 'active_support/core_ext/object/blank'
|
2
|
-
require 'physique/project_path_resolver'
|
3
|
-
|
4
|
-
module Physique
|
5
|
-
class FluentMigratorConfig
|
6
|
-
self.extend Albacore::ConfigDSL
|
7
|
-
include Albacore::Logging
|
8
|
-
|
9
|
-
# Project name or path
|
10
|
-
attr_path :project
|
11
|
-
|
12
|
-
attr_writer :lang, # Programming language of the db project
|
13
|
-
:instance, # Server instance name
|
14
|
-
:name, # Database name
|
15
|
-
:scripts_dir, # Scripts folder to examine to create tasks
|
16
|
-
:dialect, # Dialect to use for generating SQL
|
17
|
-
:task_alias # Alias used to construct rake task names
|
18
|
-
|
19
|
-
def initialize
|
20
|
-
@lang = :cs
|
21
|
-
@scripts_dir = '_Scripts'
|
22
|
-
end
|
23
|
-
|
24
|
-
def opts
|
25
|
-
validate_config
|
26
|
-
|
27
|
-
Map.new({
|
28
|
-
lang: @lang,
|
29
|
-
instance: @instance,
|
30
|
-
name: @name,
|
31
|
-
scripts_dir: @scripts_dir,
|
32
|
-
dialect: @dialect,
|
33
|
-
project_file: Physique::ProjectPathResolver.resolve(@project, @lang),
|
34
|
-
task_alias: (@task_alias || @name),
|
35
|
-
})
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def validate_config
|
41
|
-
raise ArgumentError, 'You must specify a database instance' if @instance.blank?
|
42
|
-
raise ArgumentError, 'You must specify a database name' if @name.blank?
|
43
|
-
raise ArgumentError, 'You must specify the FluentMigrator project' if @project.blank?
|
44
|
-
raise ArgumentError, 'You must specify a language' if @lang.blank?
|
45
|
-
raise ArgumentError, 'You must specify a scripts_dir' if @scripts_dir.blank?
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class FluentMigratorTasksBuilder < TasksBuilder
|
50
|
-
def build_tasks
|
51
|
-
dbs = solution.fluent_migrator_dbs
|
52
|
-
return if dbs.blank?
|
53
|
-
|
54
|
-
dbs.each do |db|
|
55
|
-
expand_project_config db
|
56
|
-
task_namespace = db_task_name(db)
|
57
|
-
|
58
|
-
namespace :db do
|
59
|
-
namespace task_namespace do
|
60
|
-
# First look at the scripts_dir and add a task for every sql file that you find
|
61
|
-
defaults = default_tasks(db.name)
|
62
|
-
add_script_tasks db, defaults
|
63
|
-
|
64
|
-
# Then add the default minimum required tasks in case the scripts_dir didn't contain them
|
65
|
-
add_default_db_tasks db, defaults
|
66
|
-
|
67
|
-
# Add the migrate and rollback tasks
|
68
|
-
add_migrator_tasks db
|
69
|
-
|
70
|
-
# Add the tasks to create the db from scratch
|
71
|
-
add_create_tasks
|
72
|
-
|
73
|
-
# Add a task to create a new migration in the db project
|
74
|
-
add_new_migration_task db
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# Rebuild the databases when running tests
|
79
|
-
task :test => "db:#{task_namespace}:rebuild"
|
80
|
-
end
|
81
|
-
|
82
|
-
alias_default_tasks
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
def expand_project_config(db)
|
88
|
-
project = Albacore::Project.new(db.project_file)
|
89
|
-
db[:project_namespace] = project.namespace
|
90
|
-
db[:project_dir] = project.proj_path_base
|
91
|
-
db[:scripts_dir] = "#{
|
92
|
-
|
93
|
-
build_conf = solution.compile.configuration
|
94
|
-
db[:output_path] = project.output_path build_conf
|
95
|
-
db[:output_dll] = File.expand_path("#{db.project_dir}
|
96
|
-
end
|
97
|
-
|
98
|
-
def add_script_tasks(db, defaults)
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
s.
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
s.
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
#
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
b.
|
145
|
-
b.
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
config.
|
167
|
-
config.
|
168
|
-
config.
|
169
|
-
config.
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
1
|
+
require 'active_support/core_ext/object/blank'
|
2
|
+
require 'physique/project_path_resolver'
|
3
|
+
|
4
|
+
module Physique
|
5
|
+
class FluentMigratorConfig
|
6
|
+
self.extend Albacore::ConfigDSL
|
7
|
+
include Albacore::Logging
|
8
|
+
|
9
|
+
# Project name or path
|
10
|
+
attr_path :project
|
11
|
+
|
12
|
+
attr_writer :lang, # Programming language of the db project
|
13
|
+
:instance, # Server instance name
|
14
|
+
:name, # Database name
|
15
|
+
:scripts_dir, # Scripts folder to examine to create tasks
|
16
|
+
:dialect, # Dialect to use for generating SQL
|
17
|
+
:task_alias # Alias used to construct rake task names
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@lang = :cs
|
21
|
+
@scripts_dir = '_Scripts'
|
22
|
+
end
|
23
|
+
|
24
|
+
def opts
|
25
|
+
validate_config
|
26
|
+
|
27
|
+
Map.new({
|
28
|
+
lang: @lang,
|
29
|
+
instance: @instance,
|
30
|
+
name: @name,
|
31
|
+
scripts_dir: @scripts_dir,
|
32
|
+
dialect: @dialect,
|
33
|
+
project_file: Physique::ProjectPathResolver.resolve(@project, @lang),
|
34
|
+
task_alias: (@task_alias || @name),
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def validate_config
|
41
|
+
raise ArgumentError, 'You must specify a database instance' if @instance.blank?
|
42
|
+
raise ArgumentError, 'You must specify a database name' if @name.blank?
|
43
|
+
raise ArgumentError, 'You must specify the FluentMigrator project' if @project.blank?
|
44
|
+
raise ArgumentError, 'You must specify a language' if @lang.blank?
|
45
|
+
raise ArgumentError, 'You must specify a scripts_dir' if @scripts_dir.blank?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class FluentMigratorTasksBuilder < TasksBuilder
|
50
|
+
def build_tasks
|
51
|
+
dbs = solution.fluent_migrator_dbs
|
52
|
+
return if dbs.blank?
|
53
|
+
|
54
|
+
dbs.each do |db|
|
55
|
+
expand_project_config db
|
56
|
+
task_namespace = db_task_name(db)
|
57
|
+
|
58
|
+
namespace :db do
|
59
|
+
namespace task_namespace do
|
60
|
+
# First look at the scripts_dir and add a task for every sql file that you find
|
61
|
+
defaults = default_tasks(db.name)
|
62
|
+
add_script_tasks db, defaults
|
63
|
+
|
64
|
+
# Then add the default minimum required tasks in case the scripts_dir didn't contain them
|
65
|
+
add_default_db_tasks db, defaults
|
66
|
+
|
67
|
+
# Add the migrate and rollback tasks
|
68
|
+
add_migrator_tasks db
|
69
|
+
|
70
|
+
# Add the tasks to create the db from scratch
|
71
|
+
add_create_tasks
|
72
|
+
|
73
|
+
# Add a task to create a new migration in the db project
|
74
|
+
add_new_migration_task db
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Rebuild the databases when running tests
|
79
|
+
task :test => "db:#{task_namespace}:rebuild"
|
80
|
+
end
|
81
|
+
|
82
|
+
alias_default_tasks
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def expand_project_config(db)
|
88
|
+
project = Albacore::Project.new(db.project_file)
|
89
|
+
db[:project_namespace] = project.namespace
|
90
|
+
db[:project_dir] = project.proj_path_base
|
91
|
+
db[:scripts_dir] = "#{db[:project_dir]}\\#{db.scripts_dir}"
|
92
|
+
|
93
|
+
build_conf = solution.compile.configuration
|
94
|
+
db[:output_path] = project.output_path build_conf
|
95
|
+
db[:output_dll] = File.expand_path("#{db.project_dir}\\#{project.output_dll(build_conf)}")
|
96
|
+
end
|
97
|
+
|
98
|
+
def add_script_tasks(db, defaults)
|
99
|
+
# Need to keep the forward slashes for FileList.
|
100
|
+
scripts_dir = db.scripts_dir.gsub('\\', '/')
|
101
|
+
FileList["#{scripts_dir}/*.sql"].each do |f|
|
102
|
+
task_name = File.basename(f, '.*')
|
103
|
+
|
104
|
+
desc get_script_task_description(defaults, task_name, db)
|
105
|
+
sqlcmd task_name do |s|
|
106
|
+
s.file = f
|
107
|
+
s.server_name = db.instance
|
108
|
+
s.set_variable 'DATABASE_NAME', db.name
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def get_script_task_description(defaults, task_name, db)
|
114
|
+
default_task = defaults[task_name.to_sym]
|
115
|
+
default_task ? default_task[:description] : "Executes #{task_name}.sql on #{db.name} in the #{db.scripts_dir} folder."
|
116
|
+
end
|
117
|
+
|
118
|
+
def add_default_db_tasks(db, defaults)
|
119
|
+
defaults.each do |task_name,task_details|
|
120
|
+
unless Rake::Task.task_defined? "db:#{db_task_name(db)}:#{task_name.to_s}"
|
121
|
+
desc task_details[:description]
|
122
|
+
sqlcmd task_name do |s|
|
123
|
+
s.command = task_details[:command]
|
124
|
+
s.server_name = db.instance
|
125
|
+
s.set_variable 'DATABASE_NAME', db.name
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def default_tasks(database)
|
132
|
+
{ create: { description: 'Create the database', command: "CREATE DATABASE #{database}" },
|
133
|
+
drop: { description: 'Drop the database', command: "DROP DATABASE #{database}"},
|
134
|
+
seed: { description: 'Seed the database with test data', command: "SELECT 'No seed script found'" } }
|
135
|
+
end
|
136
|
+
|
137
|
+
def add_migrator_tasks(db)
|
138
|
+
require 'physique/tasks/fluent_migrator'
|
139
|
+
|
140
|
+
# Compile just the database project.
|
141
|
+
# This task is registered as a dependency of the migration
|
142
|
+
# tasks to ensure the latest code is available.
|
143
|
+
build :compile_db => [ :restore ] do |b|
|
144
|
+
b.target = [ 'Build' ]
|
145
|
+
b.file = db.project_file
|
146
|
+
b.prop 'Configuration', solution.compile.configuration
|
147
|
+
b.logging = solution.compile.logging
|
148
|
+
end
|
149
|
+
|
150
|
+
block = lambda &method(:configure_migration)
|
151
|
+
|
152
|
+
# Migrate up
|
153
|
+
desc 'Migrate database to the latest version'
|
154
|
+
fluent_migrator :migrate => [ :compile_db ], &block.curry.(db, 'migrate:up')
|
155
|
+
|
156
|
+
# Migrate down
|
157
|
+
desc 'Rollback the database to the previous version'
|
158
|
+
fluent_migrator :rollback => [ :compile_db ], &block.curry.(db, 'rollback')
|
159
|
+
|
160
|
+
# Try the migration
|
161
|
+
desc 'Migrate and then immediately rollback'
|
162
|
+
task :try => [ :migrate, :rollback ]
|
163
|
+
end
|
164
|
+
|
165
|
+
def configure_migration(db, task, config)
|
166
|
+
config.instance = db.instance
|
167
|
+
config.database = db.name
|
168
|
+
config.task = task
|
169
|
+
config.dll = %{"#{db.output_dll}"}
|
170
|
+
config.exe = locate_tool(tool_in_output_folder(db) || tool_in_nuget_package)
|
171
|
+
config.output_to_file
|
172
|
+
end
|
173
|
+
|
174
|
+
def add_create_tasks
|
175
|
+
# Setup the database from nothing
|
176
|
+
desc 'Create the database and run all migrations'
|
177
|
+
task :setup => [ :create, :migrate, :seed ]
|
178
|
+
|
179
|
+
# Drop and recreate the database
|
180
|
+
desc 'Drop and recreate the database'
|
181
|
+
task :rebuild => [ :drop, :setup ]
|
182
|
+
end
|
183
|
+
|
184
|
+
def tool_in_output_folder(db)
|
185
|
+
existing_path "#{db.output_path}/Migrate.exe"
|
186
|
+
end
|
187
|
+
|
188
|
+
def tool_in_nuget_package
|
189
|
+
existing_path "#{solution.nuget.restore_location}/FluentMigrator*/tools/Migrate.exe"
|
190
|
+
end
|
191
|
+
|
192
|
+
def existing_path(path)
|
193
|
+
path = path.gsub('\\', '/')
|
194
|
+
return path if FileList[path].any? { |p| File.exists? p }
|
195
|
+
nil
|
196
|
+
end
|
197
|
+
|
198
|
+
def db_task_name(db)
|
199
|
+
db.task_alias.downcase
|
200
|
+
end
|
201
|
+
|
202
|
+
def add_new_migration_task(db)
|
203
|
+
desc 'Create a new migration file with the specified name'
|
204
|
+
task :new_migration, :name, :description do |t, args|
|
205
|
+
name, description = args[:name], args[:description]
|
206
|
+
|
207
|
+
unless name
|
208
|
+
abort [
|
209
|
+
%Q{Usage: rake "#{t.name}[name[,description]]"},
|
210
|
+
desc,
|
211
|
+
].join "\n\n"
|
212
|
+
end
|
213
|
+
|
214
|
+
# Save the new migration file
|
215
|
+
version = migration_version
|
216
|
+
migration_file_name = "#{version}_#{name}.cs"
|
217
|
+
migration_content = migration_template(version, name, description, db.project_namespace)
|
218
|
+
save_file migration_content, "#{db.project_dir}/Migrations/#{migration_file_name}"
|
219
|
+
|
220
|
+
# Add the new migration file to the project
|
221
|
+
Albacore::Project.new(db.project_file).tap do |p|
|
222
|
+
p.add_compile_node :Migrations, migration_file_name
|
223
|
+
p.save
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def migration_version
|
229
|
+
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
230
|
+
end
|
231
|
+
|
232
|
+
def migration_template(version, name, description, project_namespace)
|
233
|
+
description = ", \"#{description}\"" unless description.nil?
|
234
|
+
return <<TEMPLATE
|
235
|
+
using FluentMigrator;
|
236
|
+
|
237
|
+
namespace #{project_namespace}.Migrations
|
238
|
+
{
|
239
|
+
[Migration(#{version}#{description})]
|
240
|
+
public class #{name} : Migration
|
241
|
+
{
|
242
|
+
public override void Up()
|
243
|
+
{
|
244
|
+
// Add migration code here
|
245
|
+
}
|
246
|
+
|
247
|
+
public override void Down()
|
248
|
+
{
|
249
|
+
// Add migration rollback code here
|
250
|
+
}
|
251
|
+
}
|
252
|
+
}
|
253
|
+
TEMPLATE
|
254
|
+
end
|
255
|
+
|
256
|
+
def save_file(content, file_path)
|
257
|
+
raise "#{file_path} already exists, cancelling" if File.exists? file_path
|
258
|
+
File.open(file_path, 'w') { |f| f.write(content) }
|
259
|
+
end
|
260
|
+
|
261
|
+
def alias_default_tasks
|
262
|
+
Rake.application.tasks
|
263
|
+
.select {|t| should_alias_db_task?(t)}
|
264
|
+
.group_by {|t| db_command(t) }
|
265
|
+
.each do |command,tasks|
|
266
|
+
desc global_task_description(command,tasks)
|
267
|
+
task "db:#{command}", tasks[0].arg_names => tasks.map {|t| t.name }
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
def db_command(task)
|
272
|
+
task.name.split(':').last.to_sym
|
273
|
+
end
|
274
|
+
|
275
|
+
def should_alias_db_task?(task)
|
276
|
+
task.name.starts_with?('db') &&
|
277
|
+
(only_one_db_configured? ||
|
278
|
+
GLOBAL_TASKS.has_key?(db_command(task)))
|
279
|
+
end
|
280
|
+
|
281
|
+
def global_task_description(command, tasks)
|
282
|
+
return GLOBAL_TASKS[command] unless only_one_db_configured?
|
283
|
+
|
284
|
+
# Blank out the comment to hide the task in the list by default
|
285
|
+
description = tasks[0].comment
|
286
|
+
tasks[0].clear_comments
|
287
|
+
description
|
288
|
+
end
|
289
|
+
|
290
|
+
def only_one_db_configured?
|
291
|
+
solution.fluent_migrator_dbs.length == 1
|
292
|
+
end
|
293
|
+
|
294
|
+
GLOBAL_TASKS = {
|
295
|
+
create: 'Create all databases',
|
296
|
+
drop: 'Drop all databases',
|
297
|
+
seed: 'Seed all databases with test data',
|
298
|
+
setup: 'Build all databases and migrate them to the latest version',
|
299
|
+
rebuild: 'Drop and recreate all databases',
|
300
|
+
migrate: 'Migrates all databases to the latest version' }
|
301
|
+
end
|
302
|
+
end
|