lib/physique/task_builders/fluent_migrator.rb in physique-0.3.4 vs lib/physique/task_builders/fluent_migrator.rb in physique-0.3.5
- old
+ new
@@ -1,7 +1,7 @@
require 'active_support/core_ext/object/blank'
-require 'physique/project'
+require 'physique/project_path_resolver'
module Physique
class FluentMigratorConfig
self.extend Albacore::ConfigDSL
include Albacore::Logging
@@ -23,21 +23,18 @@
def opts
validate_config
Map.new({
+ lang: @lang,
instance: @instance,
name: @name,
- project: @project,
- project_file: Physique::Project.get_path(@project, @lang),
- lang: @lang,
- task_alias: (@task_alias || @name)
- }).apply(
- lang: :cs,
- project_dir: "src/#{@project}",
- scripts_dir: "src/#{@project}/#{@scripts_dir}"
- )
+ scripts_dir: @scripts_dir,
+ dialect: @dialect,
+ project_file: Physique::ProjectPathResolver.resolve(@project, @lang),
+ task_alias: (@task_alias || @name),
+ })
end
private
def validate_config
@@ -53,10 +50,11 @@
def build_tasks
dbs = solution.fluent_migrator_dbs
return if dbs.blank?
dbs.each do |db|
+ expand_project_config db
task_namespace = db_task_name(db)
namespace :db do
namespace task_namespace do
# First look at the scripts_dir and add a task for every sql file that you find
@@ -84,10 +82,20 @@
alias_default_tasks
end
private
+ def expand_project_config(db)
+ project = Albacore::Project.new(db.project_file)
+ db[:project_dir] = project.proj_path_base
+ db[:scripts_dir] = "#{project.proj_path_base}/#{db.scripts_dir}"
+
+ build_conf = solution.compile.configuration
+ db[:output_path] = project.output_path build_conf
+ db[:output_dll] = File.expand_path("#{db.project_dir}/#{project.output_dll(build_conf)}")
+ end
+
def add_script_tasks(db, defaults)
FileList["#{db.scripts_dir}/*.sql"].each do |f|
task_name = File.basename(f, '.*')
desc get_script_task_description(defaults, task_name, db)
@@ -150,11 +158,11 @@
def configure_migration(db, task, config)
config.instance = db.instance
config.database = db.name
config.task = task
- config.dll = migration_dll db
+ config.dll = db.output_dll
config.exe = locate_tool(tool_in_output_folder(db) || tool_in_nuget_package)
config.output_to_file
end
def add_create_tasks
@@ -165,16 +173,12 @@
# Drop and recreate the database
desc 'Drop and recreate the database'
task :rebuild => [ :drop, :setup ]
end
- def migration_dll(db)
- "#{db.project_dir}/bin/#{solution.compile.configuration}/#{db.project}.dll"
- end
-
def tool_in_output_folder(db)
- existing_path "#{db.project_dir}/bin/#{solution.compile.configuration}/Migrate.exe"
+ existing_path "#{db.output_path}/Migrate.exe"
end
def tool_in_nuget_package
existing_path "#{solution.nuget.restore_location}/FluentMigrator.*/tools/Migrate.exe"
end
@@ -247,19 +251,38 @@
File.open(file_path, 'w') { |f| f.write(content) }
end
def alias_default_tasks
Rake.application.tasks
- .select {|t| t.name.starts_with?('db') && GLOBAL_TASKS.has_key?(db_command(t))}
+ .select {|t| should_alias_db_task?(t)}
.group_by {|t| db_command(t) }
.each do |command,tasks|
- desc GLOBAL_TASKS[command]
- task "db:#{command}" => tasks.map {|t| t.name }
+ desc global_task_description(command,tasks)
+ task "db:#{command}", tasks[0].arg_names => tasks.map {|t| t.name }
end
end
def db_command(task)
task.name.split(':').last.to_sym
+ end
+
+ def should_alias_db_task?(task)
+ task.name.starts_with?('db') &&
+ (only_one_db_configured? ||
+ GLOBAL_TASKS.has_key?(db_command(task)))
+ end
+
+ def global_task_description(command, tasks)
+ return GLOBAL_TASKS[command] unless only_one_db_configured?
+
+ # Blank out the comment to hide the task in the list by default
+ description = tasks[0].comment
+ tasks[0].clear_comments
+ description
+ end
+
+ def only_one_db_configured?
+ solution.fluent_migrator_dbs.length == 1
end
GLOBAL_TASKS = {
create: 'Create all databases',
drop: 'Drop all databases',
\ No newline at end of file