dohmysql 0.2.18 → 0.2.19

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.
data/bin/migrate CHANGED
@@ -7,7 +7,7 @@ module DohDb
7
7
  module Migrate
8
8
 
9
9
  if ['make', 'apply', 'revert'].include?(CMD_NAME)
10
- success, msg = DohDb::MigrateRunner.new(OPTS.database).send(CMD_NAME, *CMD_ARGS)
10
+ success, msg = DohDb::MigrateRunner.new(OPTS.database).send(CMD_NAME, *CMD_ARGS, OPTS)
11
11
  elsif ['check', 'verify'].include?(CMD_NAME)
12
12
  success, msg = DohDb::MigrateAnalyzer.new(OPTS.database).send(CMD_NAME, *CMD_ARGS)
13
13
  end
@@ -16,6 +16,7 @@ class Handle
16
16
 
17
17
  def initialize(config)
18
18
  @config = config
19
+ @testing_rollback = false
19
20
  log_config = @config.dup
20
21
  log_config.delete(:password)
21
22
  DohDb.logger.call('connection', "creating connection with config: #{log_config}")
@@ -20,6 +20,7 @@ end.join("\n")
20
20
 
21
21
  OPTS = Doh::Options.new(
22
22
  {'database' => [Doh.config[:default_database], "-d", "--database <database>", "name of the database to migrate -- defaults to config[:default_database], currently '#{Doh.config[:default_database]}'"] \
23
+ , 'runafter' => [false, "-a", "--after", "for migrate make, creates the migrations designed to be run after a deploy (defaults to before)"] \
23
24
  }, true, "Commands:\n\n#{cmd_detail}")
24
25
 
25
26
  CMD_NAME, CMD_ARGS = OPTS.varargs.shift, OPTS.varargs
@@ -10,21 +10,21 @@ class MigrateRunner
10
10
  @config = DohDb::connector_instance.config
11
11
  end
12
12
 
13
- def make(migrate_name)
14
- apply_fname = apply_filename(migrate_name)
13
+ def make(migrate_name, opts)
14
+ apply_fname = apply_filename(migrate_name, opts)
15
15
  if File.exist?(apply_fname)
16
16
  return [false, "it appears that migration #{migrate_name} already exists"]
17
17
  end
18
18
  `touch #{apply_fname}`
19
- `touch #{revert_filename(migrate_name)}`
19
+ `touch #{revert_filename(migrate_name, opts)}`
20
20
  [true, "files for migration #{migrate_name} created in #{@directory}"]
21
21
  end
22
22
 
23
- def apply(migrate_name)
23
+ def apply(migrate_name, opts)
24
24
  if migrate_exist?(migrate_name)
25
25
  return [false, "migration #{migrate_name} has already been applied"]
26
26
  end
27
- fname = apply_filename(migrate_name)
27
+ fname = apply_filename(migrate_name, opts)
28
28
  load_sql(fname)
29
29
  contents = File.open(fname) {|file| file.read}
30
30
  Doh.db.query("INSERT INTO #@table SET migrated_at = NOW(), name = #{migrate_name.to_sql}, sql_applied = #{contents.to_sql}")
@@ -33,11 +33,11 @@ class MigrateRunner
33
33
  [false, excpt.message]
34
34
  end
35
35
 
36
- def revert(migrate_name)
36
+ def revert(migrate_name, opts)
37
37
  unless migrate_exist?(migrate_name)
38
38
  return [false, "migration #{migrate_name} can't be reverted until it has been applied"]
39
39
  end
40
- load_sql(revert_filename(migrate_name))
40
+ load_sql(revert_filename(migrate_name, opts))
41
41
  Doh.db.query("DELETE FROM #@table WHERE name = #{migrate_name.to_sql}")
42
42
  [true, "migration #{migrate_name} reverted successfully"]
43
43
  rescue Exception => excpt
@@ -45,12 +45,14 @@ class MigrateRunner
45
45
  end
46
46
 
47
47
  private
48
- def apply_filename(migrate_name)
49
- File.join(@directory, "#{migrate_name}_apply.sql")
48
+ def apply_filename(migrate_name, opts)
49
+ position_str = opts.runafter ? 'after' : 'before'
50
+ File.join(@directory, "#{migrate_name}_#{position_str}_apply.sql")
50
51
  end
51
52
 
52
- def revert_filename(migrate_name)
53
- File.join(@directory, "#{migrate_name}_revert.sql")
53
+ def revert_filename(migrate_name, opts)
54
+ position_str = opts.runafter ? 'before' : 'after'
55
+ File.join(@directory, "#{migrate_name}_#{position_str}_revert.sql")
54
56
  end
55
57
 
56
58
  def load_sql(filename)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dohmysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.19
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-25 00:00:00.000000000 Z
13
+ date: 2013-05-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: dohroot