database-exporter 0.0.1

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.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +39 -0
  3. data/.travis.yml +6 -0
  4. data/CHANGELOG.md +4 -0
  5. data/Gemfile +7 -0
  6. data/Gemfile.lock +74 -0
  7. data/LICENSE +22 -0
  8. data/README.md +682 -0
  9. data/Rakefile +7 -0
  10. data/bin/database-exporter +48 -0
  11. data/database_exporter.gemspec +34 -0
  12. data/example_data/contentful_model.json +316 -0
  13. data/example_data/contentful_structure.json +89 -0
  14. data/example_data/example_settings.yml +25 -0
  15. data/example_data/mapping.json +119 -0
  16. data/lib/cli.rb +13 -0
  17. data/lib/configuration.rb +69 -0
  18. data/lib/converters/content_types_structure_creator.rb +58 -0
  19. data/lib/converters/contentful_model_to_json.rb +78 -0
  20. data/lib/database/export.rb +74 -0
  21. data/lib/database/modules/json_export.rb +79 -0
  22. data/lib/database/modules/relations_export.rb +270 -0
  23. data/lib/database/modules/utils.rb +20 -0
  24. data/lib/migrator.rb +29 -0
  25. data/lib/version.rb +3 -0
  26. data/spec/fixtures/database/data/assets/image/image_1.json +9 -0
  27. data/spec/fixtures/database/data/assets/image/image_2.json +9 -0
  28. data/spec/fixtures/database/data/assets/image/image_3.json +9 -0
  29. data/spec/fixtures/database/data/assets/image/image_4.json +9 -0
  30. data/spec/fixtures/database/data/collections/comment.json +18 -0
  31. data/spec/fixtures/database/data/collections/job_skills.json +13 -0
  32. data/spec/fixtures/database/data/collections/jobs.json +44 -0
  33. data/spec/fixtures/database/data/collections/profile.json +19 -0
  34. data/spec/fixtures/database/data/collections/user.json +36 -0
  35. data/spec/fixtures/database/data/entries/comment/comment_1.json +9 -0
  36. data/spec/fixtures/database/data/entries/comment/comment_2.json +9 -0
  37. data/spec/fixtures/database/data/entries/comment/comment_3.json +9 -0
  38. data/spec/fixtures/database/data/entries/comment/comment_4.json +9 -0
  39. data/spec/fixtures/database/data/entries/comment/comment_5.json +9 -0
  40. data/spec/fixtures/database/data/entries/job_skills/job_skills_1.json +7 -0
  41. data/spec/fixtures/database/data/entries/job_skills/job_skills_10.json +7 -0
  42. data/spec/fixtures/database/data/entries/job_skills/job_skills_2.json +7 -0
  43. data/spec/fixtures/database/data/entries/job_skills/job_skills_3.json +7 -0
  44. data/spec/fixtures/database/data/entries/job_skills/job_skills_4.json +7 -0
  45. data/spec/fixtures/database/data/entries/job_skills/job_skills_5.json +7 -0
  46. data/spec/fixtures/database/data/entries/job_skills/job_skills_6.json +7 -0
  47. data/spec/fixtures/database/data/entries/job_skills/job_skills_7.json +7 -0
  48. data/spec/fixtures/database/data/entries/job_skills/job_skills_8.json +7 -0
  49. data/spec/fixtures/database/data/entries/job_skills/job_skills_9.json +7 -0
  50. data/spec/fixtures/database/data/entries/jobs/jobs_1.json +56 -0
  51. data/spec/fixtures/database/data/entries/jobs/jobs_2.json +55 -0
  52. data/spec/fixtures/database/data/entries/jobs/jobs_4.json +49 -0
  53. data/spec/fixtures/database/data/entries/profile/profile_1.json +12 -0
  54. data/spec/fixtures/database/data/entries/profile/profile_2.json +12 -0
  55. data/spec/fixtures/database/data/entries/user/user_1.json +24 -0
  56. data/spec/fixtures/database/data/entries/user/user_2.json +20 -0
  57. data/spec/fixtures/database/data/helpers/job_add_id_comments.json +11 -0
  58. data/spec/fixtures/database/data/helpers/job_add_id_job_add_skills.json +24 -0
  59. data/spec/fixtures/database/data/helpers/user_id_job_adds.json +9 -0
  60. data/spec/fixtures/database/data/helpers/user_id_profiles.json +8 -0
  61. data/spec/fixtures/database/data/table_names.json +10 -0
  62. data/spec/fixtures/database/table_names.json +4 -0
  63. data/spec/fixtures/development.sqlite3 +0 -0
  64. data/spec/fixtures/json_responses/transformed_row.json +7 -0
  65. data/spec/fixtures/json_row/row.json +6 -0
  66. data/spec/fixtures/settings/contentful_model.json +316 -0
  67. data/spec/fixtures/settings/contentful_structure.json +89 -0
  68. data/spec/fixtures/settings/contentful_structure_test.json +82 -0
  69. data/spec/fixtures/settings/mapping.json +119 -0
  70. data/spec/fixtures/settings/settings.yml +27 -0
  71. data/spec/lib/configuration_spec.rb +17 -0
  72. data/spec/lib/database/export_spec.rb +49 -0
  73. data/spec/lib/database/json_export_spec.rb +49 -0
  74. data/spec/lib/database/relations_export_spec.rb +201 -0
  75. data/spec/lib/migrator_spec.rb +112 -0
  76. data/spec/spec_helper.rb +12 -0
  77. data/spec/support/db_rows_json.rb +9 -0
  78. data/spec/support/shared_configuration.rb +27 -0
  79. metadata +358 -0
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'escort'
4
+ require_relative '../lib/cli'
5
+
6
+ I18n.enforce_available_locales = false
7
+
8
+ fail ArgumentError, 'Set path for configuration file and define action. More details you can find in README.' if ARGF.argv.empty?
9
+ fail ArgumentError, "Missing '--config-file' argument. The correct is form: 'database-exporter --config-file PATH_TO_CONFIGURATION_FILE --action'. View README." unless ARGV.include?('--config-file')
10
+
11
+ Escort::App.create do |app|
12
+ app.summary 'Executable file of Database exporter'
13
+
14
+ app.options do |opts|
15
+ opts.opt :file, '--config-file', short: '-f', long: '--config-file', type: :string
16
+
17
+ app.command '--create-content-model-from-json' do |command|
18
+ command.summary 'Create content types files, based on contentful structure json file. View README'
19
+ command.action do |options, arguments|
20
+ Command::CLI.new(options, arguments).execute
21
+ end
22
+ end
23
+ app.command '--convert-content-model-to-json' do |command|
24
+ command.summary 'Transform content_model file into contentful_structure import form. View README'
25
+ command.action do |options, arguments|
26
+ Command::CLI.new(options, arguments).execute
27
+ end
28
+ end
29
+ app.command '--extract-to-json' do |command|
30
+ command.summary 'Query data from Database'
31
+ command.action do |options, arguments|
32
+ Command::CLI.new(options, arguments).execute
33
+ end
34
+ end
35
+ app.command '--prepare-json' do |command|
36
+ command.summary 'Prepare JSON files to Import'
37
+ command.action do |options, arguments|
38
+ Command::CLI.new(options, arguments).execute
39
+ end
40
+ end
41
+ app.command '--list-tables' do |command|
42
+ command.summary 'List all names of tables from Database and save them to JSON file. View README'
43
+ command.action do |options, arguments|
44
+ Command::CLI.new(options, arguments).execute
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,34 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require File.expand_path('../lib/version', __FILE__)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'database-exporter'
8
+ spec.version = Version::VERSION
9
+ spec.authors = ['Contentful GmbH (Andreas Tiefenthaler)']
10
+ spec.email = ['rubygems@contentful.com']
11
+ spec.description = 'Database exporter that prepares content to be imported'
12
+ spec.summary = 'Exporter for SQL based databases'
13
+ spec.homepage = 'https://github.com/contentful/database-adapter.rb'
14
+ spec.license = 'MIT'
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables << 'database-exporter'
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'http', '~> 0.6'
21
+ spec.add_dependency 'multi_json', '~> 1'
22
+ spec.add_dependency 'sequel','~> 4.15'
23
+ spec.add_dependency 'mysql2','~> 0.3'
24
+ spec.add_dependency 'activesupport','~> 4.1'
25
+ spec.add_dependency 'pg', '~> 0.17.0'
26
+ spec.add_dependency 'escort','~> 0.4.0'
27
+ spec.add_dependency 'i18n', '~> 0.6'
28
+ spec.add_dependency 'sqlite3', '~> 1.3.10'
29
+
30
+ spec.add_development_dependency 'rspec', '~> 3'
31
+ spec.add_development_dependency 'rspec-its', '~> 1.1.0'
32
+ spec.add_development_dependency 'bundler', '~> 1.6'
33
+ spec.add_development_dependency 'rake'
34
+ end
@@ -0,0 +1,316 @@
1
+ {
2
+ "sys": {
3
+ "type": "Array"
4
+ },
5
+ "total": 5,
6
+ "skip": 0,
7
+ "limit": 100,
8
+ "items": [
9
+ {
10
+ "fields": [
11
+ {
12
+ "name": "subject",
13
+ "id": "subject",
14
+ "type": "Text"
15
+ },
16
+ {
17
+ "name": "content",
18
+ "id": "content",
19
+ "type": "Text"
20
+ }
21
+ ],
22
+ "name": "Comment",
23
+ "sys": {
24
+ "id": "6H6pGAV1PUsuoAW26Iu48W",
25
+ "type": "ContentType",
26
+ "createdAt": "2014-12-16T12:43:41.232Z",
27
+ "createdBy": {
28
+ "sys": {
29
+ "type": "Link",
30
+ "linkType": "User",
31
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
32
+ }
33
+ },
34
+ "space": {
35
+ "sys": {
36
+ "type": "Link",
37
+ "linkType": "Space",
38
+ "id": "ip17s12q0ek4"
39
+ }
40
+ },
41
+ "firstPublishedAt": "2014-12-16T12:44:36.351Z",
42
+ "publishedCounter": 1,
43
+ "publishedAt": "2014-12-16T12:44:36.351Z",
44
+ "publishedBy": {
45
+ "sys": {
46
+ "type": "Link",
47
+ "linkType": "User",
48
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
49
+ }
50
+ },
51
+ "publishedVersion": 50,
52
+ "version": 51,
53
+ "updatedAt": "2014-12-16T12:44:36.360Z",
54
+ "updatedBy": {
55
+ "sys": {
56
+ "type": "Link",
57
+ "linkType": "User",
58
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
59
+ }
60
+ }
61
+ },
62
+ "displayField": "subject"
63
+ },
64
+ {
65
+ "fields": [
66
+ {
67
+ "name": "First name",
68
+ "id": "first_name",
69
+ "type": "Text"
70
+ },
71
+ {
72
+ "name": "Last name",
73
+ "id": "last_name",
74
+ "type": "Text"
75
+ },
76
+ {
77
+ "name": "Birthday",
78
+ "id": "birthday",
79
+ "type": "Date"
80
+ },
81
+ {
82
+ "name": "Job Adds",
83
+ "id": "job_adds",
84
+ "type": "Array",
85
+ "items": {
86
+ "type": "Link",
87
+ "linkType": "Entry"
88
+ }
89
+ }
90
+ ],
91
+ "name": "User",
92
+ "sys": {
93
+ "id": "1TVvxCqoRq0qUYAOQuOqys",
94
+ "type": "ContentType",
95
+ "createdAt": "2014-12-16T12:42:08.526Z",
96
+ "createdBy": {
97
+ "sys": {
98
+ "type": "Link",
99
+ "linkType": "User",
100
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
101
+ }
102
+ },
103
+ "space": {
104
+ "sys": {
105
+ "type": "Link",
106
+ "linkType": "Space",
107
+ "id": "ip17s12q0ek4"
108
+ }
109
+ },
110
+ "firstPublishedAt": "2014-12-16T12:43:37.894Z",
111
+ "publishedCounter": 1,
112
+ "publishedAt": "2014-12-16T12:43:37.894Z",
113
+ "publishedBy": {
114
+ "sys": {
115
+ "type": "Link",
116
+ "linkType": "User",
117
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
118
+ }
119
+ },
120
+ "publishedVersion": 61,
121
+ "version": 62,
122
+ "updatedAt": "2014-12-16T12:43:37.919Z",
123
+ "updatedBy": {
124
+ "sys": {
125
+ "type": "Link",
126
+ "linkType": "User",
127
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
128
+ }
129
+ }
130
+ },
131
+ "displayField": "first_name"
132
+ },
133
+ {
134
+ "fields": [
135
+ {
136
+ "name": "title",
137
+ "id": "title",
138
+ "type": "Text"
139
+ },
140
+ {
141
+ "name": "description",
142
+ "id": "description",
143
+ "type": "Text"
144
+ },
145
+ {
146
+ "name": "image",
147
+ "id": "image",
148
+ "type": "Link",
149
+ "linkType": "Asset"
150
+ },
151
+ {
152
+ "name": "creator",
153
+ "id": "creator",
154
+ "type": "Link",
155
+ "linkType": "Entry"
156
+ },
157
+ {
158
+ "name": "comments",
159
+ "id": "comments",
160
+ "type": "Array",
161
+ "items": {
162
+ "type": "Link",
163
+ "linkType": "Entry"
164
+ }
165
+ }
166
+ ],
167
+ "name": "Jobs",
168
+ "sys": {
169
+ "id": "4L1bg4WQ5aWQMiE82ouag",
170
+ "type": "ContentType",
171
+ "createdAt": "2014-12-16T12:44:42.037Z",
172
+ "createdBy": {
173
+ "sys": {
174
+ "type": "Link",
175
+ "linkType": "User",
176
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
177
+ }
178
+ },
179
+ "space": {
180
+ "sys": {
181
+ "type": "Link",
182
+ "linkType": "Space",
183
+ "id": "ip17s12q0ek4"
184
+ }
185
+ },
186
+ "firstPublishedAt": "2014-12-16T12:45:51.836Z",
187
+ "publishedCounter": 2,
188
+ "publishedAt": "2014-12-16T13:17:50.310Z",
189
+ "publishedBy": {
190
+ "sys": {
191
+ "type": "Link",
192
+ "linkType": "User",
193
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
194
+ }
195
+ },
196
+ "publishedVersion": 58,
197
+ "version": 59,
198
+ "updatedAt": "2014-12-16T13:17:50.330Z",
199
+ "updatedBy": {
200
+ "sys": {
201
+ "type": "Link",
202
+ "linkType": "User",
203
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
204
+ }
205
+ }
206
+ },
207
+ "displayField": "title"
208
+ },
209
+ {
210
+ "fields": [
211
+ {
212
+ "name": "Nickname",
213
+ "id": "nickname",
214
+ "type": "Link",
215
+ "linkType": "Entry"
216
+ },
217
+ {
218
+ "name": "User",
219
+ "id": "user",
220
+ "type": "Link",
221
+ "linkType": "Entry"
222
+ }
223
+ ],
224
+ "name": "Profile",
225
+ "sys": {
226
+ "id": "4WFZh4MwC4Mc0EQWAeOY8A",
227
+ "type": "ContentType",
228
+ "createdAt": "2014-12-16T12:47:07.624Z",
229
+ "createdBy": {
230
+ "sys": {
231
+ "type": "Link",
232
+ "linkType": "User",
233
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
234
+ }
235
+ },
236
+ "space": {
237
+ "sys": {
238
+ "type": "Link",
239
+ "linkType": "Space",
240
+ "id": "ip17s12q0ek4"
241
+ }
242
+ },
243
+ "firstPublishedAt": "2014-12-16T12:47:33.866Z",
244
+ "publishedCounter": 1,
245
+ "publishedAt": "2014-12-16T12:47:33.866Z",
246
+ "publishedBy": {
247
+ "sys": {
248
+ "type": "Link",
249
+ "linkType": "User",
250
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
251
+ }
252
+ },
253
+ "publishedVersion": 29,
254
+ "version": 30,
255
+ "updatedAt": "2014-12-16T12:47:33.878Z",
256
+ "updatedBy": {
257
+ "sys": {
258
+ "type": "Link",
259
+ "linkType": "User",
260
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
261
+ }
262
+ }
263
+ }
264
+ },
265
+ {
266
+ "fields": [
267
+ {
268
+ "name": "name",
269
+ "id": "name",
270
+ "type": "Text"
271
+ }
272
+ ],
273
+ "name": "Job Skills",
274
+ "sys": {
275
+ "id": "2soCP557HGKoOOK0SqmMOm",
276
+ "type": "ContentType",
277
+ "createdAt": "2014-12-16T12:46:03.311Z",
278
+ "createdBy": {
279
+ "sys": {
280
+ "type": "Link",
281
+ "linkType": "User",
282
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
283
+ }
284
+ },
285
+ "space": {
286
+ "sys": {
287
+ "type": "Link",
288
+ "linkType": "Space",
289
+ "id": "ip17s12q0ek4"
290
+ }
291
+ },
292
+ "firstPublishedAt": "2014-12-16T12:47:00.429Z",
293
+ "publishedCounter": 1,
294
+ "publishedAt": "2014-12-16T12:47:00.429Z",
295
+ "publishedBy": {
296
+ "sys": {
297
+ "type": "Link",
298
+ "linkType": "User",
299
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
300
+ }
301
+ },
302
+ "publishedVersion": 18,
303
+ "version": 19,
304
+ "updatedAt": "2014-12-16T12:47:00.444Z",
305
+ "updatedBy": {
306
+ "sys": {
307
+ "type": "Link",
308
+ "linkType": "User",
309
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
310
+ }
311
+ }
312
+ },
313
+ "displayField": "name"
314
+ }
315
+ ]
316
+ }
@@ -0,0 +1,89 @@
1
+ {
2
+ "Comment": {
3
+ "id": "6H6pGAV1PUsuoAW26Iu48W",
4
+ "name": "Comment",
5
+ "description": null,
6
+ "displayField": "subject",
7
+ "fields": {
8
+ "subject": "Text",
9
+ "content": "Text"
10
+ }
11
+ },
12
+ "User": {
13
+ "id": "1TVvxCqoRq0qUYAOQuOqys",
14
+ "name": "User",
15
+ "description": null,
16
+ "displayField": "first_name",
17
+ "fields": {
18
+ "first_name": "Text",
19
+ "last_name": "Text",
20
+ "birthday": "Date",
21
+ "Jobs": {
22
+ "id": "job_adds",
23
+ "type": "Array",
24
+ "link_type": "Entry",
25
+ "link": "Link"
26
+ },
27
+ "Profile": {
28
+ "id": "profile",
29
+ "type": "Entry",
30
+ "link": "Link"
31
+ }
32
+ }
33
+ },
34
+ "Jobs": {
35
+ "id": "4L1bg4WQ5aWQMiE82ouag",
36
+ "name": "Jobs",
37
+ "description": null,
38
+ "displayField": "title",
39
+ "fields": {
40
+ "title": "Text",
41
+ "description": "Text",
42
+ "Image": {
43
+ "id": "image",
44
+ "type": "Asset",
45
+ "link": "Link"
46
+ },
47
+ "User": {
48
+ "id": "creator",
49
+ "type": "Entry",
50
+ "link": "Link"
51
+ },
52
+ "Comment": {
53
+ "id": "comments",
54
+ "type": "Array",
55
+ "link_type": "Entry",
56
+ "link": "Link"
57
+ },
58
+ "Job Skills": {
59
+ "id": "skills",
60
+ "type": "Array",
61
+ "link_type": "Entry",
62
+ "link": "Link"
63
+ }
64
+ }
65
+ },
66
+ "Profile": {
67
+ "id": "4WFZh4MwC4Mc0EQWAeOY8A",
68
+ "name": "Profile",
69
+ "description": null,
70
+ "displayField": null,
71
+ "fields": {
72
+ "nickname": "Text",
73
+ "User": {
74
+ "id": "user",
75
+ "type": "Entry",
76
+ "link": "Link"
77
+ }
78
+ }
79
+ },
80
+ "Job Skills": {
81
+ "id": "2soCP557HGKoOOK0SqmMOm",
82
+ "name": "Job Skills",
83
+ "description": null,
84
+ "displayField": "name",
85
+ "fields": {
86
+ "name": "Text"
87
+ }
88
+ }
89
+ }