data_migrate 9.4.2 → 11.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +25 -2
- data/README.md +20 -13
- data/lib/data_migrate/data_migrator.rb +1 -1
- data/lib/data_migrate/data_schema.rb +6 -6
- data/lib/data_migrate/database_tasks.rb +58 -21
- data/lib/data_migrate/rails_helper.rb +15 -3
- data/lib/data_migrate/tasks/data_migrate_tasks.rb +8 -6
- data/lib/data_migrate/version.rb +1 -1
- data/lib/generators/data_migration/data_migration_generator.rb +2 -1
- metadata +2 -47
- data/.github/workflows/build.yml +0 -35
- data/.github/workflows/gempush.yml +0 -28
- data/.gitignore +0 -12
- data/.hound.yml +0 -4
- data/.overcommit.yml +0 -21
- data/.rbenv-gemsets +0 -2
- data/.rspec +0 -3
- data/.rubocop.yml +0 -2
- data/.ruby-style.yml +0 -1061
- data/Appraisals +0 -11
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -184
- data/Rakefile +0 -2
- data/data_migrate.gemspec +0 -41
- data/gemfiles/rails_6.1.gemfile +0 -7
- data/gemfiles/rails_6.1.gemfile.lock +0 -229
- data/gemfiles/rails_7.0.gemfile +0 -7
- data/gemfiles/rails_7.0.gemfile.lock +0 -230
- data/gemfiles/rails_7.1.gemfile +0 -7
- data/gemfiles/rails_7.1.gemfile.lock +0 -263
- data/lib/data_migrate/test.rb +0 -14
- data/screenshot.png +0 -0
- data/spec/data_migrate/config_spec.rb +0 -69
- data/spec/data_migrate/data_migrator_spec.rb +0 -83
- data/spec/data_migrate/data_schema_migration_spec.rb +0 -33
- data/spec/data_migrate/data_spec.rb +0 -74
- data/spec/data_migrate/database_tasks_spec.rb +0 -105
- data/spec/data_migrate/migration.rb +0 -17
- data/spec/data_migrate/migration_context_spec.rb +0 -108
- data/spec/data_migrate/schema_dumper_spec.rb +0 -36
- data/spec/data_migrate/schema_migration_spec.rb +0 -104
- data/spec/data_migrate/status_service_spec.rb +0 -76
- data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +0 -129
- data/spec/db/data/20091231235959_some_name.rb +0 -9
- data/spec/db/data/20171231235959_super_update.rb +0 -9
- data/spec/db/data/20181128000207_excluded_file.rb.other_ext +0 -1
- data/spec/db/data/partial_schema/data_schema.rb +0 -1
- data/spec/db/data/partial_schema/test_data_schema.rb +0 -1
- data/spec/db/data/schema/data_schema.rb +0 -1
- data/spec/db/data/schema/test_data_schema.rb +0 -1
- data/spec/db/migrate/20131111111111_late_migration.rb +0 -9
- data/spec/db/migrate/20202020202011_db_migration.rb +0 -9
- data/spec/generators/data_migration/data_migration_generator_spec.rb +0 -101
- data/spec/spec_helper.rb +0 -28
- data/tasks/.gitkeep +0 -0
data/gemfiles/rails_7.1.gemfile
DELETED
@@ -1,263 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ..
|
3
|
-
specs:
|
4
|
-
data_migrate (9.4.2)
|
5
|
-
activerecord (>= 6.1)
|
6
|
-
railties (>= 6.1)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: http://rubygems.org/
|
10
|
-
specs:
|
11
|
-
actioncable (7.1.0)
|
12
|
-
actionpack (= 7.1.0)
|
13
|
-
activesupport (= 7.1.0)
|
14
|
-
nio4r (~> 2.0)
|
15
|
-
websocket-driver (>= 0.6.1)
|
16
|
-
zeitwerk (~> 2.6)
|
17
|
-
actionmailbox (7.1.0)
|
18
|
-
actionpack (= 7.1.0)
|
19
|
-
activejob (= 7.1.0)
|
20
|
-
activerecord (= 7.1.0)
|
21
|
-
activestorage (= 7.1.0)
|
22
|
-
activesupport (= 7.1.0)
|
23
|
-
mail (>= 2.7.1)
|
24
|
-
net-imap
|
25
|
-
net-pop
|
26
|
-
net-smtp
|
27
|
-
actionmailer (7.1.0)
|
28
|
-
actionpack (= 7.1.0)
|
29
|
-
actionview (= 7.1.0)
|
30
|
-
activejob (= 7.1.0)
|
31
|
-
activesupport (= 7.1.0)
|
32
|
-
mail (~> 2.5, >= 2.5.4)
|
33
|
-
net-imap
|
34
|
-
net-pop
|
35
|
-
net-smtp
|
36
|
-
rails-dom-testing (~> 2.2)
|
37
|
-
actionpack (7.1.0)
|
38
|
-
actionview (= 7.1.0)
|
39
|
-
activesupport (= 7.1.0)
|
40
|
-
nokogiri (>= 1.8.5)
|
41
|
-
rack (>= 2.2.4)
|
42
|
-
rack-session (>= 1.0.1)
|
43
|
-
rack-test (>= 0.6.3)
|
44
|
-
rails-dom-testing (~> 2.2)
|
45
|
-
rails-html-sanitizer (~> 1.6)
|
46
|
-
actiontext (7.1.0)
|
47
|
-
actionpack (= 7.1.0)
|
48
|
-
activerecord (= 7.1.0)
|
49
|
-
activestorage (= 7.1.0)
|
50
|
-
activesupport (= 7.1.0)
|
51
|
-
globalid (>= 0.6.0)
|
52
|
-
nokogiri (>= 1.8.5)
|
53
|
-
actionview (7.1.0)
|
54
|
-
activesupport (= 7.1.0)
|
55
|
-
builder (~> 3.1)
|
56
|
-
erubi (~> 1.11)
|
57
|
-
rails-dom-testing (~> 2.2)
|
58
|
-
rails-html-sanitizer (~> 1.6)
|
59
|
-
activejob (7.1.0)
|
60
|
-
activesupport (= 7.1.0)
|
61
|
-
globalid (>= 0.3.6)
|
62
|
-
activemodel (7.1.0)
|
63
|
-
activesupport (= 7.1.0)
|
64
|
-
activerecord (7.1.0)
|
65
|
-
activemodel (= 7.1.0)
|
66
|
-
activesupport (= 7.1.0)
|
67
|
-
timeout (>= 0.4.0)
|
68
|
-
activestorage (7.1.0)
|
69
|
-
actionpack (= 7.1.0)
|
70
|
-
activejob (= 7.1.0)
|
71
|
-
activerecord (= 7.1.0)
|
72
|
-
activesupport (= 7.1.0)
|
73
|
-
marcel (~> 1.0)
|
74
|
-
activesupport (7.1.0)
|
75
|
-
base64
|
76
|
-
bigdecimal
|
77
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
78
|
-
connection_pool (>= 2.2.5)
|
79
|
-
drb
|
80
|
-
i18n (>= 1.6, < 2)
|
81
|
-
minitest (>= 5.1)
|
82
|
-
mutex_m
|
83
|
-
tzinfo (~> 2.0)
|
84
|
-
appraisal (2.5.0)
|
85
|
-
bundler
|
86
|
-
rake
|
87
|
-
thor (>= 0.14.0)
|
88
|
-
ast (2.4.2)
|
89
|
-
base64 (0.2.0)
|
90
|
-
bigdecimal (3.1.6)
|
91
|
-
builder (3.2.4)
|
92
|
-
childprocess (4.1.0)
|
93
|
-
coderay (1.1.3)
|
94
|
-
concurrent-ruby (1.2.3)
|
95
|
-
connection_pool (2.4.1)
|
96
|
-
crass (1.0.6)
|
97
|
-
date (3.3.4)
|
98
|
-
diff-lcs (1.5.0)
|
99
|
-
drb (2.2.0)
|
100
|
-
ruby2_keywords
|
101
|
-
erubi (1.12.0)
|
102
|
-
globalid (1.2.1)
|
103
|
-
activesupport (>= 6.1)
|
104
|
-
i18n (1.14.1)
|
105
|
-
concurrent-ruby (~> 1.0)
|
106
|
-
iniparse (1.5.0)
|
107
|
-
io-console (0.7.2)
|
108
|
-
irb (1.11.2)
|
109
|
-
rdoc
|
110
|
-
reline (>= 0.4.2)
|
111
|
-
json (2.6.3)
|
112
|
-
language_server-protocol (3.17.0.3)
|
113
|
-
loofah (2.22.0)
|
114
|
-
crass (~> 1.0.2)
|
115
|
-
nokogiri (>= 1.12.0)
|
116
|
-
mail (2.8.1)
|
117
|
-
mini_mime (>= 0.1.1)
|
118
|
-
net-imap
|
119
|
-
net-pop
|
120
|
-
net-smtp
|
121
|
-
marcel (1.0.4)
|
122
|
-
method_source (1.0.0)
|
123
|
-
mini_mime (1.1.5)
|
124
|
-
minitest (5.22.2)
|
125
|
-
mutex_m (0.2.0)
|
126
|
-
net-imap (0.4.10)
|
127
|
-
date
|
128
|
-
net-protocol
|
129
|
-
net-pop (0.1.2)
|
130
|
-
net-protocol
|
131
|
-
net-protocol (0.2.2)
|
132
|
-
timeout
|
133
|
-
net-smtp (0.4.0.1)
|
134
|
-
net-protocol
|
135
|
-
nio4r (2.7.0)
|
136
|
-
nokogiri (1.16.2-arm64-darwin)
|
137
|
-
racc (~> 1.4)
|
138
|
-
nokogiri (1.16.2-x86_64-linux)
|
139
|
-
racc (~> 1.4)
|
140
|
-
overcommit (0.60.0)
|
141
|
-
childprocess (>= 0.6.3, < 5)
|
142
|
-
iniparse (~> 1.4)
|
143
|
-
rexml (~> 3.2)
|
144
|
-
parallel (1.23.0)
|
145
|
-
parser (3.2.2.3)
|
146
|
-
ast (~> 2.4.1)
|
147
|
-
racc
|
148
|
-
pry (0.14.2)
|
149
|
-
coderay (~> 1.1)
|
150
|
-
method_source (~> 1.0)
|
151
|
-
psych (5.1.2)
|
152
|
-
stringio
|
153
|
-
racc (1.7.3)
|
154
|
-
rack (3.0.9.1)
|
155
|
-
rack-session (2.0.0)
|
156
|
-
rack (>= 3.0.0)
|
157
|
-
rack-test (2.1.0)
|
158
|
-
rack (>= 1.3)
|
159
|
-
rackup (2.1.0)
|
160
|
-
rack (>= 3)
|
161
|
-
webrick (~> 1.8)
|
162
|
-
rails (7.1.0)
|
163
|
-
actioncable (= 7.1.0)
|
164
|
-
actionmailbox (= 7.1.0)
|
165
|
-
actionmailer (= 7.1.0)
|
166
|
-
actionpack (= 7.1.0)
|
167
|
-
actiontext (= 7.1.0)
|
168
|
-
actionview (= 7.1.0)
|
169
|
-
activejob (= 7.1.0)
|
170
|
-
activemodel (= 7.1.0)
|
171
|
-
activerecord (= 7.1.0)
|
172
|
-
activestorage (= 7.1.0)
|
173
|
-
activesupport (= 7.1.0)
|
174
|
-
bundler (>= 1.15.0)
|
175
|
-
railties (= 7.1.0)
|
176
|
-
rails-dom-testing (2.2.0)
|
177
|
-
activesupport (>= 5.0.0)
|
178
|
-
minitest
|
179
|
-
nokogiri (>= 1.6)
|
180
|
-
rails-html-sanitizer (1.6.0)
|
181
|
-
loofah (~> 2.21)
|
182
|
-
nokogiri (~> 1.14)
|
183
|
-
railties (7.1.0)
|
184
|
-
actionpack (= 7.1.0)
|
185
|
-
activesupport (= 7.1.0)
|
186
|
-
irb
|
187
|
-
rackup (>= 1.0.0)
|
188
|
-
rake (>= 12.2)
|
189
|
-
thor (~> 1.0, >= 1.2.2)
|
190
|
-
zeitwerk (~> 2.6)
|
191
|
-
rainbow (3.1.1)
|
192
|
-
rake (13.1.0)
|
193
|
-
rb-readline (0.5.5)
|
194
|
-
rdoc (6.6.2)
|
195
|
-
psych (>= 4.0.0)
|
196
|
-
regexp_parser (2.8.1)
|
197
|
-
reline (0.4.3)
|
198
|
-
io-console (~> 0.5)
|
199
|
-
rexml (3.2.5)
|
200
|
-
rspec (3.12.0)
|
201
|
-
rspec-core (~> 3.12.0)
|
202
|
-
rspec-expectations (~> 3.12.0)
|
203
|
-
rspec-mocks (~> 3.12.0)
|
204
|
-
rspec-core (3.12.2)
|
205
|
-
rspec-support (~> 3.12.0)
|
206
|
-
rspec-expectations (3.12.3)
|
207
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
208
|
-
rspec-support (~> 3.12.0)
|
209
|
-
rspec-mocks (3.12.6)
|
210
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
211
|
-
rspec-support (~> 3.12.0)
|
212
|
-
rspec-support (3.12.1)
|
213
|
-
rubocop (1.54.2)
|
214
|
-
json (~> 2.3)
|
215
|
-
language_server-protocol (>= 3.17.0)
|
216
|
-
parallel (~> 1.10)
|
217
|
-
parser (>= 3.2.2.3)
|
218
|
-
rainbow (>= 2.2.2, < 4.0)
|
219
|
-
regexp_parser (>= 1.8, < 3.0)
|
220
|
-
rexml (>= 3.2.5, < 4.0)
|
221
|
-
rubocop-ast (>= 1.28.0, < 2.0)
|
222
|
-
ruby-progressbar (~> 1.7)
|
223
|
-
unicode-display_width (>= 2.4.0, < 3.0)
|
224
|
-
rubocop-ast (1.29.0)
|
225
|
-
parser (>= 3.2.1.0)
|
226
|
-
ruby-progressbar (1.13.0)
|
227
|
-
ruby2_keywords (0.0.5)
|
228
|
-
sqlite3 (1.7.2-arm64-darwin)
|
229
|
-
sqlite3 (1.7.2-x86_64-linux)
|
230
|
-
stringio (3.1.0)
|
231
|
-
thor (1.3.1)
|
232
|
-
timecop (0.9.6)
|
233
|
-
timeout (0.4.1)
|
234
|
-
tzinfo (2.0.6)
|
235
|
-
concurrent-ruby (~> 1.0)
|
236
|
-
unicode-display_width (2.4.2)
|
237
|
-
webrick (1.8.1)
|
238
|
-
websocket-driver (0.7.6)
|
239
|
-
websocket-extensions (>= 0.1.0)
|
240
|
-
websocket-extensions (0.1.5)
|
241
|
-
zeitwerk (2.6.13)
|
242
|
-
|
243
|
-
PLATFORMS
|
244
|
-
arm64-darwin-22
|
245
|
-
arm64-darwin-23
|
246
|
-
x86_64-linux
|
247
|
-
|
248
|
-
DEPENDENCIES
|
249
|
-
appraisal
|
250
|
-
data_migrate!
|
251
|
-
overcommit
|
252
|
-
pry
|
253
|
-
rails (= 7.1.0)
|
254
|
-
rake
|
255
|
-
rb-readline
|
256
|
-
rspec
|
257
|
-
rspec-core
|
258
|
-
rubocop
|
259
|
-
sqlite3
|
260
|
-
timecop
|
261
|
-
|
262
|
-
BUNDLED WITH
|
263
|
-
2.4.17
|
data/lib/data_migrate/test.rb
DELETED
data/screenshot.png
DELETED
Binary file
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe DataMigrate::Config do
|
6
|
-
it "sets default data_migrations_path path", :no_override do
|
7
|
-
expect(DataMigrate.config.data_migrations_path).to eq "db/data/"
|
8
|
-
end
|
9
|
-
|
10
|
-
it "sets default data_template_path path", :no_override do
|
11
|
-
expect(DataMigrate.config.data_template_path).to eq DataMigrate::Config::DEFAULT_DATA_TEMPLATE_PATH
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "data migration path configured" do
|
15
|
-
subject { DataMigrate.config.data_migrations_path }
|
16
|
-
let(:data_migrations_path) { "db/awesome/" }
|
17
|
-
|
18
|
-
before do
|
19
|
-
@original_data_migrations_path = DataMigrate.config.data_migrations_path
|
20
|
-
|
21
|
-
DataMigrate.configure do |config|
|
22
|
-
config.data_migrations_path = data_migrations_path
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
after do
|
27
|
-
DataMigrate.configure do |config|
|
28
|
-
config.data_migrations_path = @original_data_migrations_path
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it "equals the custom data migration path" do
|
33
|
-
is_expected.to eq(data_migrations_path)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "data template path configured" do
|
38
|
-
subject { DataMigrate.config.data_template_path }
|
39
|
-
let(:data_template_path) { File.join(DataMigrate.root, "generators", "data_migration", "templates", "data_migration.rb") }
|
40
|
-
|
41
|
-
before do
|
42
|
-
@original_data_migrations_path = DataMigrate.config.data_template_path
|
43
|
-
|
44
|
-
DataMigrate.configure do |config|
|
45
|
-
config.data_template_path = data_template_path
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
after do
|
50
|
-
DataMigrate.configure do |config|
|
51
|
-
config.data_template_path = @original_data_migrations_path
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
it "equals the custom data template path" do
|
56
|
-
is_expected.to eq data_template_path
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when path does not exist" do
|
60
|
-
subject { DataMigrate.config.data_template_path = invalid_path }
|
61
|
-
|
62
|
-
let(:invalid_path) { "lib/awesome/templates/data_migration.rb" }
|
63
|
-
|
64
|
-
it "checks that file exists on setting config var" do
|
65
|
-
expect { subject }.to raise_error { ArgumentError.new("File not found: '#{data_template_path}'") }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe DataMigrate::DataMigrator do
|
6
|
-
let(:described_class) { DataMigrate::DataMigrator }
|
7
|
-
|
8
|
-
let(:db_config) do
|
9
|
-
{
|
10
|
-
adapter: "sqlite3",
|
11
|
-
database: "spec/db/test.db"
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
before do
|
16
|
-
ActiveRecord::Base.establish_connection(db_config)
|
17
|
-
DataMigrate::RailsHelper.schema_migration.create_table
|
18
|
-
DataMigrate::RailsHelper.data_schema_migration.create_table
|
19
|
-
end
|
20
|
-
|
21
|
-
after do
|
22
|
-
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
23
|
-
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
24
|
-
end
|
25
|
-
|
26
|
-
describe ".load_migrated" do
|
27
|
-
let(:migrator) { DataMigrate::RailsHelper.data_migrator(:up, []) }
|
28
|
-
|
29
|
-
it "loads migrated versions" do
|
30
|
-
DataMigrate::RailsHelper.data_schema_migration.create_version(20090000000000)
|
31
|
-
DataMigrate::RailsHelper.schema_create_version(20100000000000)
|
32
|
-
DataMigrate::RailsHelper.data_schema_migration.create_version(20110000000000)
|
33
|
-
DataMigrate::RailsHelper.schema_create_version(20120000000000)
|
34
|
-
migrated = migrator.load_migrated
|
35
|
-
expect(migrated.count).to eq 2
|
36
|
-
expect(migrated).to include 20090000000000
|
37
|
-
expect(migrated).to include 20110000000000
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe :create_data_schema_table do
|
42
|
-
it "creates the data_migrations table" do
|
43
|
-
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
44
|
-
described_class.create_data_schema_table
|
45
|
-
expect(
|
46
|
-
ActiveRecord::Base.connection.table_exists?("data_migrations")
|
47
|
-
).to eq true
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "#migrations_status" do
|
52
|
-
it "returns all migrations statuses" do
|
53
|
-
status = described_class.migrations_status
|
54
|
-
expect(status.length).to eq 2
|
55
|
-
expect(status.first).to eq ["down", "20091231235959", "Some name"]
|
56
|
-
expect(status.second).to eq ["down", "20171231235959", "Super update"]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe :match do
|
61
|
-
context "when the file does not match" do
|
62
|
-
it "returns nil" do
|
63
|
-
expect(described_class.match("not_a_data_migration_file")).to be_nil
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when the file doesn't end in .rb" do
|
68
|
-
it "returns nil" do
|
69
|
-
expect(described_class.match("20091231235959_some_name.rb.un~")).to be_nil
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "when the file matches" do
|
74
|
-
it "returns a valid MatchData object" do
|
75
|
-
match_data = described_class.match("20091231235959_some_name.rb")
|
76
|
-
|
77
|
-
expect(match_data[0]).to eq "20091231235959_some_name.rb"
|
78
|
-
expect(match_data[1]).to eq "20091231235959"
|
79
|
-
expect(match_data[2]).to eq "some_name"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe DataMigrate::DataSchemaMigration do
|
4
|
-
if DataMigrate::RailsHelper.rails_version_equal_to_or_higher_than_7_1
|
5
|
-
let(:connection) { double(:connection) }
|
6
|
-
let(:subject) { DataMigrate::DataSchemaMigration.new(connection) }
|
7
|
-
|
8
|
-
describe :table_name do
|
9
|
-
it "returns correct table name" do
|
10
|
-
expect(subject.table_name).to eq("data_migrations")
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe :index_name do
|
15
|
-
it "returns correct primary key name" do
|
16
|
-
expect(subject.primary_key).to eq("version")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
else
|
20
|
-
let(:subject) { DataMigrate::DataSchemaMigration }
|
21
|
-
describe :table_name do
|
22
|
-
it "returns correct table name" do
|
23
|
-
expect(subject.table_name).to eq("data_migrations")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe :index_name do
|
28
|
-
it "returns correct primary key name" do
|
29
|
-
expect(subject.primary_key).to eq("version")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe DataMigrate::Data do
|
6
|
-
let(:subject) { DataMigrate::Data }
|
7
|
-
let(:fixture_file_timestamps) do
|
8
|
-
%w[20091231235959 20101231235959 20111231235959]
|
9
|
-
end
|
10
|
-
|
11
|
-
around do |example|
|
12
|
-
Dir.mktmpdir do |temp_dir|
|
13
|
-
@temp_dir = temp_dir
|
14
|
-
|
15
|
-
# create the fake data migration files
|
16
|
-
fixture_file_timestamps.each do |timestamp|
|
17
|
-
FileUtils.touch File.join(temp_dir, "#{timestamp}_data_migration.rb")
|
18
|
-
end
|
19
|
-
|
20
|
-
example.run
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe :define do
|
25
|
-
after do
|
26
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
27
|
-
end
|
28
|
-
|
29
|
-
context "when no version is supplied" do
|
30
|
-
it "returns nil" do
|
31
|
-
expect(subject.define(version: nil)).to be_nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when a version is supplied" do
|
36
|
-
before do
|
37
|
-
allow(DataMigrate::DataMigrator).
|
38
|
-
to receive(:full_migrations_path).and_return(@temp_dir)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "sets the current version to the supplied version" do
|
42
|
-
version = fixture_file_timestamps[1]
|
43
|
-
|
44
|
-
expect(DataMigrate::DataMigrator.current_version).not_to eq version.to_i
|
45
|
-
subject.define(version: version)
|
46
|
-
expect(DataMigrate::DataMigrator.current_version).to eq version.to_i
|
47
|
-
end
|
48
|
-
|
49
|
-
it "creates entries for migration versions that come " \
|
50
|
-
"before the supplied version" do
|
51
|
-
|
52
|
-
version = fixture_file_timestamps[1]
|
53
|
-
|
54
|
-
subject.define(version: version)
|
55
|
-
|
56
|
-
sql_select = <<-SQL
|
57
|
-
SELECT version
|
58
|
-
FROM #{DataMigrate::RailsHelper.data_schema_migration.table_name}
|
59
|
-
SQL
|
60
|
-
|
61
|
-
db_list_data = ActiveRecord::Base.connection.
|
62
|
-
select_values(sql_select).map(&:to_i)
|
63
|
-
expect(db_list_data).to match_array(
|
64
|
-
[fixture_file_timestamps[0], fixture_file_timestamps[1]].map(&:to_i)
|
65
|
-
)
|
66
|
-
|
67
|
-
# The last remaining migration (fixture_file_timestamps[2]) was
|
68
|
-
# not included as part of the supplied version and so should not
|
69
|
-
# appear in the data_migrations table.
|
70
|
-
expect(db_list_data).not_to include(fixture_file_timestamps[2])
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,105 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe DataMigrate::DatabaseTasks do
|
6
|
-
let(:subject) { DataMigrate::DatabaseTasks }
|
7
|
-
let(:migration_path) { "spec/db/migrate" }
|
8
|
-
let(:data_migrations_path) {
|
9
|
-
DataMigrate.config.data_migrations_path
|
10
|
-
}
|
11
|
-
|
12
|
-
before do
|
13
|
-
# In a normal Rails installation, db_dir would defer to
|
14
|
-
# Rails.application.config.paths["db"].first
|
15
|
-
# @see https://github.com/rails/rails/blob/a7d49ef78c36df2d1ca876451f30915ada1079a5/activerecord/lib/active_record/tasks/database_tasks.rb#L54
|
16
|
-
allow(subject).to receive(:db_dir).and_return("db")
|
17
|
-
allow(ActiveRecord::Tasks::DatabaseTasks).to receive(:db_dir).and_return("db")
|
18
|
-
end
|
19
|
-
|
20
|
-
before do
|
21
|
-
allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:migrations_paths) {
|
22
|
-
data_migrations_path
|
23
|
-
}
|
24
|
-
ActiveRecord::Base.establish_connection({ adapter: "sqlite3", database: "spec/db/test.db" })
|
25
|
-
hash_config = ActiveRecord::DatabaseConfigurations::HashConfig.new('test', 'test', { adapter: "sqlite3", database: "spec/db/test.db" })
|
26
|
-
config_obj = ActiveRecord::DatabaseConfigurations.new([hash_config])
|
27
|
-
allow(ActiveRecord::Base).to receive(:configurations).and_return(config_obj)
|
28
|
-
end
|
29
|
-
|
30
|
-
context "migrations" do
|
31
|
-
after do
|
32
|
-
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
33
|
-
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
34
|
-
end
|
35
|
-
|
36
|
-
before do
|
37
|
-
DataMigrate::RailsHelper.schema_migration.create_table
|
38
|
-
|
39
|
-
allow(DataMigrate::SchemaMigration).to receive(:migrations_paths) {
|
40
|
-
migration_path
|
41
|
-
}
|
42
|
-
allow(DataMigrate::DatabaseTasks).to receive(:data_migrations_path) {
|
43
|
-
data_migrations_path
|
44
|
-
}.at_least(:once)
|
45
|
-
end
|
46
|
-
|
47
|
-
describe :past_migrations do
|
48
|
-
it "returns past migration records" do
|
49
|
-
subject.forward
|
50
|
-
migrations = subject.past_migrations
|
51
|
-
expect(migrations.count).to eq 1
|
52
|
-
expect(migrations.first[:version]).to eq 20091231235959
|
53
|
-
end
|
54
|
-
|
55
|
-
it "shows nothing without any migrations" do
|
56
|
-
migrations = subject.past_migrations
|
57
|
-
expect(migrations.count).to eq 0
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe :forward do
|
62
|
-
it "run forward default amount of times" do
|
63
|
-
subject.forward
|
64
|
-
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
65
|
-
expect(versions.count).to eq(1)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "run forward defined number of times" do
|
69
|
-
subject.forward(2)
|
70
|
-
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
71
|
-
expect(versions.count).to eq(1)
|
72
|
-
expect(versions.first).to eq "20091231235959"
|
73
|
-
versions = DataMigrate::RailsHelper.schema_migration.normalized_versions
|
74
|
-
expect(versions.count).to eq(1)
|
75
|
-
expect(versions.first).to eq "20131111111111"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
if DataMigrate::RailsHelper.rails_version_equal_to_or_higher_than_7_0
|
80
|
-
describe :schema_dump_path do
|
81
|
-
before do
|
82
|
-
allow(ActiveRecord::Base).to receive(:configurations).and_return(ActiveRecord::DatabaseConfigurations.new([db_config]))
|
83
|
-
end
|
84
|
-
|
85
|
-
context "for primary database" do
|
86
|
-
let(:db_config) { ActiveRecord::DatabaseConfigurations::HashConfig.new("development", "primary", {} ) }
|
87
|
-
|
88
|
-
context "for :ruby db format" do
|
89
|
-
it 'returns the data schema path' do
|
90
|
-
allow(ActiveRecord).to receive(:schema_format).and_return(:ruby)
|
91
|
-
expect(subject.schema_dump_path(db_config)).to eq("db/data_schema.rb")
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context "for :sql db format" do
|
96
|
-
it 'returns the data schema path' do
|
97
|
-
allow(ActiveRecord).to receive(:schema_format).and_return(:sql)
|
98
|
-
expect(subject.schema_dump_path(db_config, :sql)).to eq("db/data_schema.rb")
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe DataMigrate::Migration do
|
6
|
-
describe ".table_name" do
|
7
|
-
it "returns correct table name" do
|
8
|
-
expect(subject.table_name).to eq("data_migrations")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe ".index_name" do
|
13
|
-
it "returns correct primary key name" do
|
14
|
-
expect(subject.primary_key).to eq("version")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|