migsql 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/migsql +1 -1
  3. data/lib/migsql/app.rb +32 -13
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a4290a355bd2a6c5a68be7f11db3ae46f48f877
4
- data.tar.gz: 87ff7d1ca701dab1570acb45c443d05b32565ad4
3
+ metadata.gz: f64099740e799ae5f22f6892a9db6d9d7c36fd78
4
+ data.tar.gz: e5cd9d2217805ad0a5c640f54c6b69c86ffb3bb7
5
5
  SHA512:
6
- metadata.gz: 501d32de6a8ed95adaf753f920d735f6c92d7c6c125a1e61bfc51206ba8af012128fc2eb8bab0459d8d442553f02424f38e519ef7f585d4859d906179bf6798d
7
- data.tar.gz: 69cde86f82c4552a81a8ff1337f93ed7b0c03b4fe0ed751478f814125e7edc6a2c8846385f830f37abf586dd845a97da597bc634057d2bc1b23cc95a6248325d
6
+ metadata.gz: a2143353fc0b516eab6bbb9f60952f6afc020749ed6f1f1f857e47cb1d28fad1ca09bc743ba8b53808bf06d5770147501545d521dd2f83dac4daf6b68b74f382
7
+ data.tar.gz: d59ca627f647052f066329f510be15dae3a6d1d63323c3669a36a11b154e57b953e0644bb8a7eaaee10da8aa1c97b6b43d4e3b239ef6c74361440fe742c18d75
data/bin/migsql CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require_relative '../lib/migsql'
3
- @app = MigSql.new
3
+ @app = MigSql.new(nil)
4
4
  @app.handle_argv(ARGV)
data/lib/migsql/app.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'colorize'
2
2
  class MigSql
3
- def initialize
4
- @migration = Migration.new './db/config.yml'
3
+ def initialize(migration)
4
+ @migration = migration || Migration.new('./db/config.yml')
5
5
  @migration.load
6
6
  end
7
7
 
@@ -16,10 +16,31 @@ class MigSql
16
16
  handle_create_migration argv
17
17
  when 'migrate'
18
18
  handle_migrate argv
19
+ when 'apply'
20
+ handle_apply argv
19
21
  end
20
22
  end
21
23
  end
22
24
 
25
+ def enforce_arg(value, name)
26
+ if value.nil?
27
+ puts "Error: You must specify a value for #{name}".red
28
+ return true
29
+ end
30
+ false
31
+ end
32
+
33
+ def handle_apply(argv)
34
+ return if enforce_arg(argv[1], 'migration name')
35
+ return if enforce_arg(argv[2], 'up/down')
36
+ migration_server = get_migration_server(argv[4])
37
+ migration_name = get_migration_target(migration_server, argv[1])
38
+ return if migration_name.nil?
39
+ migration_name = "#{migration_name}_#{argv[2]}.sql"
40
+ @migration.apply_migration(migration_server, migration_name)\
41
+ unless migration_server.nil? || migration_name.nil?
42
+ end
43
+
23
44
  def handle_init
24
45
  if File.directory?('./db')
25
46
  puts 'Error: the ./db directory already exists'.red
@@ -51,17 +72,13 @@ class MigSql
51
72
  migration_server = get_migration_server(argv[1])
52
73
  migration_target = argv[3]
53
74
  end
54
- o_target = migration_target
55
75
  return if migration_server.nil?
56
76
  migration_target = get_migration_target(migration_server, migration_target)
57
- if !migration_target.nil?
58
- from = @migration.get_migration_status(migration_server)
59
- plan = calculate_migration_plan(migration_server, migration_target, from)
60
- @migration.apply_migration_plan(migration_server, plan, migration_target)\
61
- unless plan.nil?
62
- else
63
- puts "Error: No migration found with name: #{o_target}".red
64
- end
77
+ return if migration_target.nil?
78
+ from = @migration.get_migration_status(migration_server)
79
+ plan = calculate_migration_plan(migration_server, migration_target, from)
80
+ @migration.apply_migration_plan(migration_server, plan, migration_target)\
81
+ unless plan.nil?
65
82
  end
66
83
 
67
84
  def calculate_migration_plan(migration_server, to, from)
@@ -74,10 +91,12 @@ class MigSql
74
91
 
75
92
  def get_migration_target(migration_server, migration_target)
76
93
  if migration_target.nil?
77
- @migration.get_latest_migration(migration_server)
94
+ migration = @migration.get_latest_migration(migration_server)
78
95
  else
79
- @migration.get_migration_by_name(migration_server, migration_target)
96
+ migration = @migration.get_migration_by_name(migration_server, migration_target)
97
+ puts "Error: No migration found with name: #{migration_target}".red if migration.nil?
80
98
  end
99
+ migration
81
100
  end
82
101
 
83
102
  def get_migration_server(server_name)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migsql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Stoney