migsql 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/migsql +1 -1
- data/lib/migsql/app.rb +32 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f64099740e799ae5f22f6892a9db6d9d7c36fd78
|
4
|
+
data.tar.gz: e5cd9d2217805ad0a5c640f54c6b69c86ffb3bb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2143353fc0b516eab6bbb9f60952f6afc020749ed6f1f1f857e47cb1d28fad1ca09bc743ba8b53808bf06d5770147501545d521dd2f83dac4daf6b68b74f382
|
7
|
+
data.tar.gz: d59ca627f647052f066329f510be15dae3a6d1d63323c3669a36a11b154e57b953e0644bb8a7eaaee10da8aa1c97b6b43d4e3b239ef6c74361440fe742c18d75
|
data/bin/migsql
CHANGED
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
|
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
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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)
|