db-migrate 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9703746febda4f9b2ef4d5ad0a5013fd044d80f0
4
- data.tar.gz: 396ff547f035d0ce68dc5093b9d441edbc93ba92
3
+ metadata.gz: eab419426da9f80e43140f1f4b25f5f56b7970e6
4
+ data.tar.gz: e2840d27dc6129e8aa4176100e87d60c1f3fa62b
5
5
  SHA512:
6
- metadata.gz: 5568c7624e9b6685ec1099b87a1a395c41016e82b501a2499738e934b3fc197104023c79b6a5d6b806e25cadb001d0dd15b60b9782219840a729efc182c30855
7
- data.tar.gz: 6f51e9a629a34023a42a50f30eed3ccaab4644de633a5148acdbc6cc236ff436ebd25d8d48af1d5a41916f87b57d16d3ee5d34cec67d59b6c27dd4d3d08a56cd
6
+ metadata.gz: 45ad601cb4e91159d8574972ad8db33f69f2d0690d9074b279228b1ce551aa47a61f50ca283b6ac5bde84e9d7f96b1cc5868c31720001b2828f1ea7a1e1117e6
7
+ data.tar.gz: cccb1098e5f70782fe3e471a82869245c08d294065337a3cc56f5e45b50bce6b69f9227a31ff59214ab9ab1994f9e4817e9bfc986e54063994107cd4766934db
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ db-migrate (0.0.4)
5
+ colorize (= 0.7.7)
6
+ highline (= 1.7.8)
7
+ json (= 1.8.3)
8
+ parseconfig (= 1.0.6)
9
+ terminal-table (= 1.5.2)
10
+ thor (= 0.19.1)
11
+ wannabe_bool (= 0.5.0)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ colorize (0.7.7)
17
+ diff-lcs (1.2.5)
18
+ highline (1.7.8)
19
+ json (1.8.3)
20
+ mysql2 (0.4.2)
21
+ parseconfig (1.0.6)
22
+ pg (0.18.4)
23
+ rspec (3.4.0)
24
+ rspec-core (~> 3.4.0)
25
+ rspec-expectations (~> 3.4.0)
26
+ rspec-mocks (~> 3.4.0)
27
+ rspec-core (3.4.2)
28
+ rspec-support (~> 3.4.0)
29
+ rspec-expectations (3.4.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.4.0)
32
+ rspec-mocks (3.4.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.4.0)
35
+ rspec-support (3.4.1)
36
+ terminal-table (1.5.2)
37
+ thor (0.19.1)
38
+ wannabe_bool (0.5.0)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ db-migrate!
45
+ mysql2 (= 0.4.2)
46
+ pg (= 0.18.4)
47
+ rspec (= 3.4.0)
48
+
49
+ BUNDLED WITH
50
+ 1.11.2
data/README.md CHANGED
@@ -51,31 +51,6 @@ Options:
51
51
  #### init
52
52
  First thing you have to do is to make initial configuration with **migrate init** command.
53
53
 
54
- **Demo:**
55
- ```
56
- $ migrate init
57
- [INFO] Creating configuration...
58
- 1. mysql
59
- 2. pg
60
- Which database do you prefer?
61
- 1
62
- 1. sql
63
- 2. ruby
64
- 3. javascript
65
- 4. go
66
- 5. python
67
- What language would you like use for your migration scripts?
68
- 1
69
- Host: |localhost|
70
- Port: |3306|
71
- Database Name: |mydb|
72
- User: |root|
73
- Password: password
74
- Version info table: |version_info|
75
- Version number table: |version_number|
76
- [SUCCESS] Configuration file created. Location: `./migrate.conf`
77
- ```
78
-
79
54
  #### new
80
55
  After that you can start generating migrations by using **migrate new** command. This will generate migration script for you based on your prefered language.
81
56
 
@@ -3,12 +3,16 @@
3
3
  require "thor"
4
4
  require "json"
5
5
  require "highline"
6
+ require 'wannabe_bool'
6
7
  require_relative "../lib/migrate"
7
8
 
8
9
  include Migrate
9
10
  $asker = HighLine.new
10
11
 
11
12
  class CLI < Thor
13
+ @@pg_version = "0.18.4"
14
+ @@mysql_version = "0.4.2"
15
+
12
16
  method_option :root, {
13
17
  :aliases => "-r",
14
18
  :default => ".",
@@ -47,6 +51,29 @@ class CLI < Thor
47
51
  menu.choices(:pg) { storage = "pg" }
48
52
  end
49
53
 
54
+ install_dep = ""
55
+ case storage
56
+ when "pg"
57
+ if `gem list -i pg`.to_b != true
58
+ install_dep = "sudo gem install pg -v #{@@pg_version}"
59
+ Log.info "pg package not installed. Will install it."
60
+ end
61
+ when "mysql"
62
+ if `gem list -i mysql2`.to_b != "true"
63
+ install_dep = "sudo gem install mysql2 -v #{@@mysql_version}"
64
+ Log.info "mysql2 package not installed. Will install it."
65
+ end
66
+ end
67
+
68
+ unless install_dep.empty?
69
+ Log.info "Running '#{install_dep}'"
70
+ unless system(install_dep)
71
+ raise "Wrror while install dependencies. Please try to run '#{install_dep}' manually and try running 'init' again."
72
+ else
73
+ Log.info "Missing dependencies installed"
74
+ end
75
+ end
76
+
50
77
  db_defaults = case storage
51
78
  when "mysql"
52
79
  { :port => "3306", :user => "root" }
@@ -57,7 +84,7 @@ class CLI < Thor
57
84
  lang = nil
58
85
  $asker.choose do |menu|
59
86
  menu.prompt = "What language would you like use for your migration scripts?"
60
-
87
+
61
88
  menu.choice(:sql) { lang = "sql" }
62
89
  menu.choices(:ruby) { lang = "ruby" }
63
90
  menu.choice(:javascript) { lang = "javascript" }
@@ -82,7 +109,7 @@ class CLI < Thor
82
109
  Migrator.new(@config).init
83
110
  rescue Exception => e
84
111
  Log.error("Error while initialization.", e)
85
- @config.remove
112
+ @config.delete
86
113
  exit
87
114
  end
88
115
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'db-migrate'
3
- s.version = '0.0.3'
3
+ s.version = '0.0.4'
4
4
  s.licenses = ['MIT']
5
5
  s.summary = "Tool for managing and executing your database migrations."
6
6
  s.description = "#{s.summary} It supports multiple databases and multiple languages for writing migration scripts."
@@ -14,12 +14,13 @@ Gem::Specification.new do |s|
14
14
  s.add_runtime_dependency 'thor', ['0.19.1']
15
15
  s.add_runtime_dependency 'highline', ['1.7.8']
16
16
  s.add_runtime_dependency 'json', ['1.8.3']
17
- s.add_runtime_dependency 'mysql2', ['0.4.2']
18
- s.add_runtime_dependency 'pg', ['0.18.4']
19
17
  s.add_runtime_dependency 'parseconfig', ['1.0.6']
20
18
  s.add_runtime_dependency 'colorize', ['0.7.7']
21
19
  s.add_runtime_dependency 'terminal-table', ['1.5.2']
20
+ s.add_runtime_dependency 'wannabe_bool', ['0.5.0']
22
21
 
23
22
  # dev deps
24
23
  s.add_development_dependency 'rspec', ['3.4.0']
24
+ s.add_development_dependency 'pg', ['0.18.4']
25
+ s.add_development_dependency 'mysql2', ['0.4.2']
25
26
  end
@@ -32,10 +32,19 @@ module Migrate
32
32
  def load!
33
33
  Log.info("Loading configuration...")
34
34
  config = ParseConfig.new(@file_path)
35
-
35
+
36
36
  config.get_params.map do |param|
37
+ value = nil
38
+ env_var = config[param].match(/\$\{(.*)\}/)
39
+
40
+ if env_var != nil
41
+ value = ENV[env_var[1]]
42
+ else
43
+ value = config[param]
44
+ end
45
+
37
46
  self.class.send(:attr_reader, param)
38
- instance_variable_set("@#{param}", config[param])
47
+ instance_variable_set("@#{param}", value)
39
48
  end
40
49
 
41
50
  @loaded = true
@@ -43,7 +52,9 @@ module Migrate
43
52
  end
44
53
 
45
54
  def delete
46
- File.delete @file_path
55
+ if File.exists? @file_path
56
+ File.delete @file_path
57
+ end
47
58
  rescue Exception => e
48
59
  Log.error("Error while removing configuration file.", e)
49
60
  exit
@@ -53,12 +64,14 @@ module Migrate
53
64
  case @storage
54
65
  when "pg"
55
66
  if @pg == nil
67
+ require_relative "./storage/postgres"
56
68
  @pg = Storage::Postgres.new(self)
57
69
  end
58
70
 
59
71
  @pg
60
72
  when "mysql"
61
73
  if @mysql == nil
74
+ require_relative "./storage/mysql"
62
75
  @mysql = Storage::Mysql.new(self)
63
76
  end
64
77
 
@@ -1,7 +1,5 @@
1
1
  module Migrate
2
2
  module Storage
3
3
  require_relative "./storage/db"
4
- require_relative "./storage/postgres"
5
- require_relative "./storage/mysql"
6
4
  end
7
5
  end
@@ -7,7 +7,7 @@ module Migrate
7
7
  super
8
8
  @conn = Mysql2::Client.new(
9
9
  :database => @config.database,
10
- :host => @config.host,
10
+ :host => @config.host,
11
11
  :port => @config.port,
12
12
  :username => @config.user,
13
13
  :password => @config.password,
@@ -22,8 +22,8 @@ module Migrate
22
22
  version INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
23
23
  description TEXT,
24
24
  created_date TIMESTAMP NOT NULL,
25
- last_up TIMESTAMP,
26
- last_down TIMESTAMP
25
+ last_up TIMESTAMP NULL,
26
+ last_down TIMESTAMP NULL
27
27
  );
28
28
  eos
29
29
 
@@ -9,7 +9,7 @@ describe "Conf" do
9
9
  user: "postgres",
10
10
  password: "password",
11
11
  version_info: "version_info",
12
- version_number: "version_number"
12
+ version_number: "${MIGRATE_TEST_VERSION_NUMBER}"
13
13
  }
14
14
  }
15
15
 
@@ -33,7 +33,7 @@ describe "Conf" do
33
33
 
34
34
  config = Conf.new(fixtures, "test.config")
35
35
  config.init(config_hash)
36
- expect(config.exists?).to eq(true)
36
+ expect(config.exists?).to eq(true)
37
37
  expect(File.exist? config_path). to be true
38
38
  ensure
39
39
  if File.exist? config_path
@@ -41,8 +41,9 @@ describe "Conf" do
41
41
  end
42
42
  end
43
43
  end
44
-
44
+
45
45
  it "should load configuration" do
46
+ ENV["MIGRATE_TEST_VERSION_NUMBER"] = "version_number"
46
47
  config.init(config_hash)
47
48
  config.load!
48
49
  expect(config.host).to eq("localhost")
@@ -71,7 +72,7 @@ describe "Conf" do
71
72
  end
72
73
  end
73
74
 
74
- [{type: "pg", cls: Storage::Postgres, conf: $pg_config_hash},
75
+ [{type: "pg", cls: Storage::Postgres, conf: $pg_config_hash},
75
76
  {type: "mysql", cls: Storage::Mysql, conf: $mysql_config_hash}].each do |storage|
76
77
  context storage[:type] do
77
78
  it "should be able to get database instance" do
@@ -83,7 +84,7 @@ describe "Conf" do
83
84
  end
84
85
 
85
86
  [{type: "go", cls: Lang::Go}, {type: "sql", cls: Lang::Sql},
86
- {type: "ruby", cls: Lang::Ruby}, {type: "javascript", cls: Lang::Javascript},
87
+ {type: "ruby", cls: Lang::Ruby}, {type: "javascript", cls: Lang::Javascript},
87
88
  {type: "python", cls: Lang::Python}].each do |lang|
88
89
  context lang[:type] do
89
90
  it "should be able to get language instance" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db-migrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Pusic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-06 00:00:00.000000000 Z
11
+ date: 2016-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -53,89 +53,103 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.8.3
55
55
  - !ruby/object:Gem::Dependency
56
- name: mysql2
56
+ name: parseconfig
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.4.2
61
+ version: 1.0.6
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.4.2
68
+ version: 1.0.6
69
69
  - !ruby/object:Gem::Dependency
70
- name: pg
70
+ name: colorize
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 0.18.4
75
+ version: 0.7.7
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 0.18.4
82
+ version: 0.7.7
83
83
  - !ruby/object:Gem::Dependency
84
- name: parseconfig
84
+ name: terminal-table
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 1.0.6
89
+ version: 1.5.2
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 1.0.6
96
+ version: 1.5.2
97
97
  - !ruby/object:Gem::Dependency
98
- name: colorize
98
+ name: wannabe_bool
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 0.7.7
103
+ version: 0.5.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 0.7.7
110
+ version: 0.5.0
111
111
  - !ruby/object:Gem::Dependency
112
- name: terminal-table
112
+ name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 1.5.2
118
- type: :runtime
117
+ version: 3.4.0
118
+ type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 1.5.2
124
+ version: 3.4.0
125
125
  - !ruby/object:Gem::Dependency
126
- name: rspec
126
+ name: pg
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 3.4.0
131
+ version: 0.18.4
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 3.4.0
138
+ version: 0.18.4
139
+ - !ruby/object:Gem::Dependency
140
+ name: mysql2
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 0.4.2
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 0.4.2
139
153
  description: Tool for managing and executing your database migrations. It supports
140
154
  multiple databases and multiple languages for writing migration scripts.
141
155
  email: pusic007@gmail.com
@@ -144,10 +158,11 @@ executables:
144
158
  extensions: []
145
159
  extra_rdoc_files: []
146
160
  files:
147
- - ".gitignore"
148
- - ".rspec"
149
- - ".travis.yml"
161
+ - .gitignore
162
+ - .rspec
163
+ - .travis.yml
150
164
  - Gemfile
165
+ - Gemfile.lock
151
166
  - LICENSE
152
167
  - README.md
153
168
  - bin/migrate
@@ -193,17 +208,17 @@ require_paths:
193
208
  - lib
194
209
  required_ruby_version: !ruby/object:Gem::Requirement
195
210
  requirements:
196
- - - ">="
211
+ - - '>='
197
212
  - !ruby/object:Gem::Version
198
213
  version: '0'
199
214
  required_rubygems_version: !ruby/object:Gem::Requirement
200
215
  requirements:
201
- - - ">="
216
+ - - '>='
202
217
  - !ruby/object:Gem::Version
203
218
  version: '0'
204
219
  requirements: []
205
220
  rubyforge_project:
206
- rubygems_version: 2.4.8
221
+ rubygems_version: 2.0.14
207
222
  signing_key:
208
223
  specification_version: 4
209
224
  summary: Tool for managing and executing your database migrations.