db-migrate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,104 @@
1
+ describe "Storage" do
2
+ $dbs.each do |db|
3
+
4
+ around(:each) do |test|
5
+ db.tx do
6
+ test.run
7
+ end
8
+ end
9
+
10
+ context db.type do
11
+ it "should create new migration" do
12
+ created = db.new_migration("this is description")
13
+ expect(created).not_to eq(nil)
14
+ expect(db.exec_sql(
15
+ "SELECT * FROM #{$version_info} WHERE version=#{created["version"]}")[0])
16
+ .to eq(created)
17
+ end
18
+
19
+ it "should list all migrations" do
20
+ migrations = db.list_migrations(nil, nil)
21
+ expect(migrations.count).to eq(5)
22
+ expect(migrations[0].keys).to eq(["version", "description", "created_date", "last_up", "last_down"])
23
+ end
24
+
25
+ it "should filter list of migrations" do
26
+ select = "version,created_date"
27
+ limit = 2
28
+
29
+ migrations = db.list_migrations(select, limit)
30
+ expect(migrations.count).to eq(limit)
31
+ expect(migrations[0].keys).to eq(["version", "created_date"])
32
+ end
33
+
34
+ describe "should get all migrations in range" do
35
+ context "when doing up" do
36
+ it do
37
+ migrations = db.migrations_range(2, 4, true)
38
+ expect(migrations.count).to eq(3)
39
+ expect(migrations[0]["version"].to_s).to eq("2")
40
+ expect(migrations[1]["version"].to_s).to eq("3")
41
+ expect(migrations[2]["version"].to_s).to eq("4")
42
+ end
43
+ end
44
+
45
+ context "when doing down" do
46
+ it do
47
+ migrations = db.migrations_range(2, 4, false)
48
+ expect(migrations.count).to eq(3)
49
+ expect(migrations[0]["version"].to_s).to eq("4")
50
+ expect(migrations[1]["version"].to_s).to eq("3")
51
+ expect(migrations[2]["version"].to_s).to eq("2")
52
+ end
53
+ end
54
+ end
55
+
56
+ it "should get lowest version" do
57
+ version = db.lowest_version
58
+ expect(version.to_s).to eq("1")
59
+ end
60
+
61
+ it "should get next version" do
62
+ nxt = db.next_version
63
+ expect(nxt.to_s).to eq("4")
64
+ end
65
+
66
+ it "should get current version" do
67
+ current = db.current_version
68
+ expect(current.to_s).to eq("3")
69
+ end
70
+
71
+ it "should get previous version" do
72
+ prev = db.prev_version
73
+ expect(prev.to_s).to eq("2")
74
+ end
75
+
76
+ it "should perform log up" do
77
+ db.log_up(4)
78
+ current = db.current_version
79
+ expect(current.to_s).to eq("4")
80
+ end
81
+
82
+ it "should perform log down" do
83
+ db.log_down("1")
84
+ current = db.current_version
85
+ expect(current.to_s).to eq("0")
86
+ end
87
+
88
+ it "should get migration" do
89
+ migration = db.get_migration(4)
90
+ expect(migration["version"].to_s).to eq("4")
91
+ end
92
+
93
+ it "should delete migration" do
94
+ db.delete(4)
95
+ expect{db.get_migration(4)}.to raise_error(VersionNotFound)
96
+ end
97
+
98
+ it "should exec sql" do
99
+ result = db.exec_sql("SELECT * FROM #{$version_info}")
100
+ expect(result.count).to eq(5)
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,109 @@
1
+ require_relative "../lib/migrate"
2
+ include Migrate
3
+
4
+ Log.verbose(false)
5
+
6
+ $config_base = {
7
+ :lang => "sql",
8
+ :database => "migrate_test",
9
+ :host => "localhost",
10
+ :version_info => "version_info",
11
+ :version_number => "version_number"
12
+ }
13
+
14
+ $pg_config_hash = $config_base.merge({
15
+ :storage => "pg",
16
+ :port => 5432,
17
+ :user => "migrate",
18
+ :password => "migrate"
19
+ })
20
+
21
+ def load_pg_config
22
+ config = Config.new("spec/lib/fixtures", "example_pg.config")
23
+ config.init($pg_config_hash)
24
+ config.load!
25
+ return config
26
+ end
27
+
28
+ $mysql_config_hash = $config_base.merge({
29
+ :storage => "mysql",
30
+ :port => 3306,
31
+ :user => "migrate",
32
+ :password => "migrate"
33
+ })
34
+
35
+ def load_mysql_config
36
+ config = Config.new("spec/lib/fixtures", "example_mysql.config")
37
+ config.init($mysql_config_hash)
38
+ config.load!
39
+ return config
40
+ end
41
+
42
+ $dbs = [load_pg_config().get_db, load_mysql_config().get_db]
43
+ $version_info = $config_base[:version_info]
44
+ $version_number = $config_base[:version_number]
45
+
46
+ def load_fixtures
47
+ drop_fixtures
48
+ $dbs.each do |db|
49
+ if db.has_tx
50
+ case db.type
51
+ when "pg"
52
+ db.exec_sql "ALTER SEQUENCE #{$version_info}_version_seq RESTART WITH 1"
53
+ when "mysql"
54
+ db.exec_sql "ALTER TABLE #{$version_info} AUTO_INCREMENT = 1"
55
+ end
56
+
57
+ db.exec_sql "INSERT INTO #{$version_info} (created_date) VALUES (now())"
58
+ db.exec_sql "INSERT INTO #{$version_info} (created_date) VALUES (now())"
59
+ db.exec_sql "INSERT INTO #{$version_info} (created_date) VALUES (now())"
60
+ db.exec_sql "INSERT INTO #{$version_info} (created_date) VALUES (now())"
61
+ db.exec_sql "INSERT INTO #{$version_info} (created_date) VALUES (now())"
62
+ db.exec_sql "UPDATE #{$version_number} SET version=3"
63
+ end
64
+ end
65
+ end
66
+
67
+ def drop_fixtures
68
+ $dbs.each do |db|
69
+ if db.has_tx
70
+ db.exec_sql "DELETE FROM #{$version_info}"
71
+ end
72
+ end
73
+ end
74
+
75
+ def create_tables
76
+ $dbs.each do |db|
77
+ db.tx do
78
+ db.create_tables
79
+ end
80
+ end
81
+ end
82
+
83
+ def drop_tables
84
+ $dbs.each do |db|
85
+ db.tx do
86
+ db.exec_sql "DROP TABLE IF EXISTS #{$version_info}"
87
+ db.exec_sql "DROP TABLE IF EXISTS #{$version_number}"
88
+ end
89
+ end
90
+ end
91
+
92
+ RSpec.configure do |config|
93
+
94
+ config.before(:all) do
95
+ create_tables
96
+ end
97
+
98
+ config.before(:each) do
99
+ load_fixtures
100
+ end
101
+
102
+ config.after(:each) do
103
+ drop_fixtures
104
+ end
105
+
106
+ config.after(:all) do
107
+ drop_tables
108
+ end
109
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: db-migrate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Pusic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: highline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.7.8
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: mysql2
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.4.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: pg
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.18.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.18.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: parseconfig
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.6
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.6
97
+ - !ruby/object:Gem::Dependency
98
+ name: colorize
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.7.7
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.7.7
111
+ description: Tool for managing and executing your database migrations. It supports
112
+ multiple databases and multiple languages for writing migration scripts.
113
+ email: pusic007@gmail.com
114
+ executables:
115
+ - migrate
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE
125
+ - README.md
126
+ - bin/migrate
127
+ - lib/migrate.rb
128
+ - lib/migrate/config.rb
129
+ - lib/migrate/errors.rb
130
+ - lib/migrate/lang.rb
131
+ - lib/migrate/lang/go.rb
132
+ - lib/migrate/lang/javascript.rb
133
+ - lib/migrate/lang/lang.rb
134
+ - lib/migrate/lang/python.rb
135
+ - lib/migrate/lang/ruby.rb
136
+ - lib/migrate/lang/sql.rb
137
+ - lib/migrate/logger.rb
138
+ - lib/migrate/migrator.rb
139
+ - lib/migrate/storage.rb
140
+ - lib/migrate/storage/db.rb
141
+ - lib/migrate/storage/mysql.rb
142
+ - lib/migrate/storage/postgres.rb
143
+ - migrate.gemspec
144
+ - spec/lib/config_spec.rb
145
+ - spec/lib/fixtures/example.config
146
+ - spec/lib/fixtures/go/down.go
147
+ - spec/lib/fixtures/go/up.go
148
+ - spec/lib/fixtures/js/down.js
149
+ - spec/lib/fixtures/js/up.js
150
+ - spec/lib/fixtures/py/down.py
151
+ - spec/lib/fixtures/py/up.py
152
+ - spec/lib/fixtures/rb/down.rb
153
+ - spec/lib/fixtures/rb/up.rb
154
+ - spec/lib/fixtures/sql/down.sql
155
+ - spec/lib/fixtures/sql/up.sql
156
+ - spec/lib/lang/lang_spec.rb
157
+ - spec/lib/migrator_spec.rb
158
+ - spec/lib/storage/db_spec.rb
159
+ - spec/spec_helper.rb
160
+ homepage: https://github.com/ivpusic/migrate
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.4.8
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: Tool for managing and executing your database migrations.
184
+ test_files: []