contentful-importer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +38 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +87 -0
- data/LICENSE +22 -0
- data/README.md +327 -0
- data/Rakefile +7 -0
- data/bin/contentful-importer +85 -0
- data/contentful_importer.gemspec +38 -0
- data/example_settings/contentful_model.json +288 -0
- data/example_settings/contentful_structure.json +78 -0
- data/example_settings/files_meaning.txt +15 -0
- data/example_settings/settings.yml +16 -0
- data/lib/cli.rb +13 -0
- data/lib/configuration.rb +36 -0
- data/lib/converters/content_types_structure_creator.rb +60 -0
- data/lib/converters/contentful_model_to_json.rb +109 -0
- data/lib/importer/data_organizer.rb +117 -0
- data/lib/importer/mime_content_type.rb +564 -0
- data/lib/importer/parallel_importer.rb +429 -0
- data/lib/json_schema_validator.rb +64 -0
- data/lib/migrator.rb +39 -0
- data/lib/version.rb +3 -0
- data/spec/fixtures/import_files/assets/image/image_1.json +9 -0
- data/spec/fixtures/import_files/assets/image/image_2.json +9 -0
- data/spec/fixtures/import_files/assets/image/image_3.json +9 -0
- data/spec/fixtures/import_files/assets/image/image_4.json +9 -0
- data/spec/fixtures/import_files/collections/job_skills.json +13 -0
- data/spec/fixtures/import_files/collections/jobs.json +37 -0
- data/spec/fixtures/import_files/collections/profile.json +19 -0
- data/spec/fixtures/import_files/collections/user.json +36 -0
- data/spec/fixtures/import_files/entries/job_skills/job_skills_1.json +7 -0
- data/spec/fixtures/import_files/entries/job_skills/job_skills_10.json +7 -0
- data/spec/fixtures/import_files/entries/job_skills/job_skills_2.json +7 -0
- data/spec/fixtures/import_files/entries/job_skills/job_skills_3.json +7 -0
- data/spec/fixtures/import_files/entries/job_skills/job_skills_4.json +7 -0
- data/spec/fixtures/import_files/entries/job_skills/job_skills_5.json +7 -0
- data/spec/fixtures/import_files/entries/job_skills/job_skills_6.json +7 -0
- data/spec/fixtures/import_files/entries/job_skills/job_skills_7.json +7 -0
- data/spec/fixtures/import_files/entries/job_skills/job_skills_8.json +7 -0
- data/spec/fixtures/import_files/entries/job_skills/job_skills_9.json +7 -0
- data/spec/fixtures/import_files/entries/jobs/jobs_1.json +56 -0
- data/spec/fixtures/import_files/entries/jobs/jobs_2.json +55 -0
- data/spec/fixtures/import_files/entries/jobs/jobs_4.json +49 -0
- data/spec/fixtures/import_files/entries/profile/profile_1.json +12 -0
- data/spec/fixtures/import_files/entries/profile/profile_2.json +12 -0
- data/spec/fixtures/import_files/entries/user/user_1.json +24 -0
- data/spec/fixtures/import_files/entries/user/user_2.json +20 -0
- data/spec/fixtures/import_files/logs/log_published_assets.csv +4 -0
- data/spec/fixtures/import_files/logs/log_published_entries.csv +23 -0
- data/spec/fixtures/import_files/logs/success_assets.csv +4 -0
- data/spec/fixtures/import_files/logs/success_published_assets.csv +0 -0
- data/spec/fixtures/import_files/logs/success_published_entries.csv +22 -0
- data/spec/fixtures/import_files/logs/success_thread_0.csv +12 -0
- data/spec/fixtures/import_files/logs/success_thread_1.csv +11 -0
- data/spec/fixtures/import_files/threads/0/1TVvxCqoRq0qUYAOQuOqys_2.json +20 -0
- data/spec/fixtures/import_files/threads/0/2soCP557HGKoOOK0SqmMOm_1.json +7 -0
- data/spec/fixtures/import_files/threads/0/2soCP557HGKoOOK0SqmMOm_10.json +7 -0
- data/spec/fixtures/import_files/threads/0/2soCP557HGKoOOK0SqmMOm_2.json +7 -0
- data/spec/fixtures/import_files/threads/0/2soCP557HGKoOOK0SqmMOm_3.json +7 -0
- data/spec/fixtures/import_files/threads/0/2soCP557HGKoOOK0SqmMOm_4.json +7 -0
- data/spec/fixtures/import_files/threads/0/2soCP557HGKoOOK0SqmMOm_5.json +7 -0
- data/spec/fixtures/import_files/threads/0/2soCP557HGKoOOK0SqmMOm_6.json +7 -0
- data/spec/fixtures/import_files/threads/0/2soCP557HGKoOOK0SqmMOm_7.json +7 -0
- data/spec/fixtures/import_files/threads/0/6H6pGAV1PUsuoAW26Iu48W_1.json +9 -0
- data/spec/fixtures/import_files/threads/0/6H6pGAV1PUsuoAW26Iu48W_2.json +9 -0
- data/spec/fixtures/import_files/threads/0/6H6pGAV1PUsuoAW26Iu48W_3.json +9 -0
- data/spec/fixtures/import_files/threads/0/6H6pGAV1PUsuoAW26Iu48W_4.json +9 -0
- data/spec/fixtures/import_files/threads/0/6H6pGAV1PUsuoAW26Iu48W_5.json +9 -0
- data/spec/fixtures/import_files/threads/1/1TVvxCqoRq0qUYAOQuOqys_1.json +24 -0
- data/spec/fixtures/import_files/threads/1/1TVvxCqoRq0qUYAOQuOqys_2.json +20 -0
- data/spec/fixtures/import_files/threads/1/2soCP557HGKoOOK0SqmMOm_6.json +7 -0
- data/spec/fixtures/import_files/threads/1/2soCP557HGKoOOK0SqmMOm_7.json +7 -0
- data/spec/fixtures/import_files/threads/1/2soCP557HGKoOOK0SqmMOm_8.json +7 -0
- data/spec/fixtures/import_files/threads/1/2soCP557HGKoOOK0SqmMOm_9.json +7 -0
- data/spec/fixtures/import_files/threads/1/4L1bg4WQ5aWQMiE82ouag_1.json +56 -0
- data/spec/fixtures/import_files/threads/1/4L1bg4WQ5aWQMiE82ouag_2.json +55 -0
- data/spec/fixtures/import_files/threads/1/4L1bg4WQ5aWQMiE82ouag_4.json +49 -0
- data/spec/fixtures/import_files/threads/1/4WFZh4MwC4Mc0EQWAeOY8A_1.json +12 -0
- data/spec/fixtures/import_files/threads/1/4WFZh4MwC4Mc0EQWAeOY8A_2.json +12 -0
- data/spec/fixtures/import_files/threads/assets/0/image_1.json +9 -0
- data/spec/fixtures/import_files/threads/assets/0/image_2.json +9 -0
- data/spec/fixtures/import_files/threads/assets/0/image_3.json +9 -0
- data/spec/fixtures/import_files/threads/assets/0/image_4.json +9 -0
- data/spec/fixtures/settings/contentful_model.json +252 -0
- data/spec/fixtures/settings/contentful_structure.json +73 -0
- data/spec/fixtures/settings/contentful_structure_test.json +66 -0
- data/spec/fixtures/settings/settings.yml +12 -0
- data/spec/fixtures/vcr_cassettes/create_asset.yml +621 -0
- data/spec/fixtures/vcr_cassettes/create_entry.yml +122 -0
- data/spec/fixtures/vcr_cassettes/create_space.yml +87 -0
- data/spec/fixtures/vcr_cassettes/import_assets.yml +2822 -0
- data/spec/fixtures/vcr_cassettes/import_content_types.yml +1915 -0
- data/spec/fixtures/vcr_cassettes/import_entries.yml +5066 -0
- data/spec/fixtures/vcr_cassettes/import_entry.yml +363 -0
- data/spec/fixtures/vcr_cassettes/invalid_credentials.yml +69 -0
- data/spec/fixtures/vcr_cassettes/publish_an_entry.yml +214 -0
- data/spec/fixtures/vcr_cassettes/publish_asset.yml +895 -0
- data/spec/fixtures/vcr_cassettes/publish_entries.yml +5121 -0
- data/spec/fixtures/vcr_cassettes/valid_credentials.yml +7360 -0
- data/spec/lib/configuration_spec.rb +22 -0
- data/spec/lib/importer/parallel_importer_spec.rb +161 -0
- data/spec/lib/json_schema_validator_spec.rb +63 -0
- data/spec/lib/migrator_spec.rb +99 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/db_rows_json.rb +9 -0
- data/spec/support/shared_configuration.rb +22 -0
- data/spec/support/vcr.rb +16 -0
- metadata +436 -0
data/lib/migrator.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative 'importer/parallel_importer'
|
2
|
+
require_relative 'configuration'
|
3
|
+
require_relative 'converters/contentful_model_to_json'
|
4
|
+
require_relative 'json_schema_validator'
|
5
|
+
|
6
|
+
class Migrator
|
7
|
+
|
8
|
+
attr_reader :importer, :converter, :config, :json_validator
|
9
|
+
|
10
|
+
def initialize(settings)
|
11
|
+
@config = Contentful::Configuration.new(settings)
|
12
|
+
@importer = Contentful::ParallelImporter.new(@config)
|
13
|
+
@converter = Contentful::Converter::ContentfulModelToJson.new(@config)
|
14
|
+
@json_validator = Contentful::JsonSchemaValidator.new(@config)
|
15
|
+
end
|
16
|
+
|
17
|
+
def run(action, options = {})
|
18
|
+
case action.to_s
|
19
|
+
when '--create-contentful-model-from-json'
|
20
|
+
converter.create_content_type_json
|
21
|
+
when '--import-content-types'
|
22
|
+
importer.create_contentful_model(options)
|
23
|
+
when '--import'
|
24
|
+
importer.import_data(options[:threads])
|
25
|
+
when '--convert-content-model-to-json'
|
26
|
+
converter.convert_to_import_form
|
27
|
+
when '--publish-entries'
|
28
|
+
importer.publish_entries_in_threads
|
29
|
+
when '--test-credentials'
|
30
|
+
importer.test_credentials
|
31
|
+
when '--import-assets'
|
32
|
+
importer.import_only_assets
|
33
|
+
when '--publish-assets'
|
34
|
+
importer.publish_assets_in_threads(options[:threads])
|
35
|
+
when '--validate-schema'
|
36
|
+
json_validator.validate_schemas
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
{
|
2
|
+
"id": "image_1",
|
3
|
+
"name": "Image 1",
|
4
|
+
"url": "http://new1.fjcdn.com/thumbnails/comments/4019311+_9f47119b44b5043d82c74008dc40397d.jpg",
|
5
|
+
"description": "Fire",
|
6
|
+
"created_at": "2014-12-16T10:22:19+00:00",
|
7
|
+
"updated_at": "2014-12-16T10:22:19+00:00",
|
8
|
+
"database_id": 1
|
9
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
{
|
2
|
+
"id": "image_2",
|
3
|
+
"name": "Image 2 - water",
|
4
|
+
"url": "http://csironewsblog.files.wordpress.com/2013/06/water_cover1.jpg",
|
5
|
+
"description": "water",
|
6
|
+
"created_at": "2014-12-16T10:23:17+00:00",
|
7
|
+
"updated_at": "2014-12-16T10:23:17+00:00",
|
8
|
+
"database_id": 2
|
9
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
{
|
2
|
+
"id": "image_3",
|
3
|
+
"name": "Ruby on rails",
|
4
|
+
"url": "http://dhwlijwe9jil7.cloudfront.net/files/2012/07/4/companies-using-ruby-on-rails.jpg",
|
5
|
+
"description": "RoR logo",
|
6
|
+
"created_at": "2014-12-16T10:23:57+00:00",
|
7
|
+
"updated_at": "2014-12-16T10:23:57+00:00",
|
8
|
+
"database_id": 3
|
9
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
{
|
2
|
+
"id": "image_4",
|
3
|
+
"name": "Ruby",
|
4
|
+
"url": "http://factormedia.com/wp-content/uploads/2012/04/ruby-on-rails_internship.png",
|
5
|
+
"description": "Ruby on 'rails'",
|
6
|
+
"created_at": "2014-12-16T10:24:32+00:00",
|
7
|
+
"updated_at": "2014-12-16T10:24:32+00:00",
|
8
|
+
"database_id": 4
|
9
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"id": "4L1bg4WQ5aWQMiE82ouag",
|
3
|
+
"name": "Jobs",
|
4
|
+
"description": null,
|
5
|
+
"displayField": "title",
|
6
|
+
"fields": [
|
7
|
+
{
|
8
|
+
"name": "Title",
|
9
|
+
"id": "title",
|
10
|
+
"type": "Text"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"name": "Description",
|
14
|
+
"id": "description",
|
15
|
+
"type": "Text"
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"name": "Image",
|
19
|
+
"id": "image",
|
20
|
+
"type": "Asset",
|
21
|
+
"link": "Link"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"name": "Creator",
|
25
|
+
"id": "creator",
|
26
|
+
"type": "Entry",
|
27
|
+
"link": "Link"
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"name": "Skills",
|
31
|
+
"id": "skills",
|
32
|
+
"type": "Array",
|
33
|
+
"link_type": "Entry",
|
34
|
+
"link": "Link"
|
35
|
+
}
|
36
|
+
]
|
37
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"id": "4WFZh4MwC4Mc0EQWAeOY8A",
|
3
|
+
"name": "Profile",
|
4
|
+
"description": null,
|
5
|
+
"displayField": null,
|
6
|
+
"fields": [
|
7
|
+
{
|
8
|
+
"name": "Nickname",
|
9
|
+
"id": "nickname",
|
10
|
+
"type": "Text"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"name": "User",
|
14
|
+
"id": "user",
|
15
|
+
"type": "Entry",
|
16
|
+
"link": "Link"
|
17
|
+
}
|
18
|
+
]
|
19
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
{
|
2
|
+
"id": "1TVvxCqoRq0qUYAOQuOqys",
|
3
|
+
"name": "User",
|
4
|
+
"description": null,
|
5
|
+
"displayField": "first_name",
|
6
|
+
"fields": [
|
7
|
+
{
|
8
|
+
"name": "First_name",
|
9
|
+
"id": "first_name",
|
10
|
+
"type": "Text"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"name": "Last_name",
|
14
|
+
"id": "last_name",
|
15
|
+
"type": "Text"
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"name": "Birthday",
|
19
|
+
"id": "birthday",
|
20
|
+
"type": "Date"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"name": "Job_adds",
|
24
|
+
"id": "job_adds",
|
25
|
+
"type": "Array",
|
26
|
+
"link_type": "Entry",
|
27
|
+
"link": "Link"
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"name": "Profile",
|
31
|
+
"id": "profile",
|
32
|
+
"type": "Entry",
|
33
|
+
"link": "Link"
|
34
|
+
}
|
35
|
+
]
|
36
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
{
|
2
|
+
"id": "jobs_1",
|
3
|
+
"name": "First new Job",
|
4
|
+
"specification": "Job description",
|
5
|
+
"created_at": "2014-12-16T10:26:03+00:00",
|
6
|
+
"updated_at": "2014-12-16T10:26:03+00:00",
|
7
|
+
"image_id": 3,
|
8
|
+
"user_id": 1,
|
9
|
+
"database_id": 1,
|
10
|
+
"first_name": "FirstName",
|
11
|
+
"subjects_comments": [
|
12
|
+
"Title comment 1",
|
13
|
+
"Title comment 2",
|
14
|
+
"Title comment 3"
|
15
|
+
],
|
16
|
+
"image": {
|
17
|
+
"type": "File",
|
18
|
+
"id": "image_3"
|
19
|
+
},
|
20
|
+
"creator": {
|
21
|
+
"type": "Entry",
|
22
|
+
"id": "user_1"
|
23
|
+
},
|
24
|
+
"comments": [
|
25
|
+
{
|
26
|
+
"type": "comment",
|
27
|
+
"id": "comment_1"
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"type": "comment",
|
31
|
+
"id": "comment_2"
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"type": "comment",
|
35
|
+
"id": "comment_3"
|
36
|
+
}
|
37
|
+
],
|
38
|
+
"skills": [
|
39
|
+
{
|
40
|
+
"type": "job_skills",
|
41
|
+
"id": "job_skills_1"
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"type": "job_skills",
|
45
|
+
"id": "job_skills_3"
|
46
|
+
},
|
47
|
+
{
|
48
|
+
"type": "job_skills",
|
49
|
+
"id": "job_skills_8"
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"type": "job_skills",
|
53
|
+
"id": "job_skills_10"
|
54
|
+
}
|
55
|
+
]
|
56
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
{
|
2
|
+
"id": "jobs_2",
|
3
|
+
"name": "Nice job!",
|
4
|
+
"specification": "Nice job description",
|
5
|
+
"created_at": "2014-12-16T10:53:28+00:00",
|
6
|
+
"updated_at": "2014-12-16T10:53:28+00:00",
|
7
|
+
"image_id": 4,
|
8
|
+
"user_id": 1,
|
9
|
+
"database_id": 2,
|
10
|
+
"first_name": "FirstName",
|
11
|
+
"subjects_comments": [
|
12
|
+
"Comment 1",
|
13
|
+
"Comment 2"
|
14
|
+
],
|
15
|
+
"image": {
|
16
|
+
"type": "File",
|
17
|
+
"id": "image_4"
|
18
|
+
},
|
19
|
+
"creator": {
|
20
|
+
"type": "Entry",
|
21
|
+
"id": "user_1"
|
22
|
+
},
|
23
|
+
"comments": [
|
24
|
+
{
|
25
|
+
"type": "comment",
|
26
|
+
"id": "comment_4"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"type": "comment",
|
30
|
+
"id": "comment_5"
|
31
|
+
}
|
32
|
+
],
|
33
|
+
"skills": [
|
34
|
+
{
|
35
|
+
"type": "job_skills",
|
36
|
+
"id": "job_skills_2"
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"type": "job_skills",
|
40
|
+
"id": "job_skills_4"
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"type": "job_skills",
|
44
|
+
"id": "job_skills_7"
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"type": "job_skills",
|
48
|
+
"id": "job_skills_8"
|
49
|
+
},
|
50
|
+
{
|
51
|
+
"type": "job_skills",
|
52
|
+
"id": "job_skills_9"
|
53
|
+
}
|
54
|
+
]
|
55
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
{
|
2
|
+
"id": "jobs_4",
|
3
|
+
"name": "Awesome job",
|
4
|
+
"specification": "One word - awesome!",
|
5
|
+
"created_at": "2014-12-16T12:00:28+00:00",
|
6
|
+
"updated_at": "2014-12-16T12:00:28+00:00",
|
7
|
+
"image_id": 2,
|
8
|
+
"user_id": 2,
|
9
|
+
"database_id": 4,
|
10
|
+
"first_name": "FirstName User 2",
|
11
|
+
"image": {
|
12
|
+
"type": "File",
|
13
|
+
"id": "image_2"
|
14
|
+
},
|
15
|
+
"creator": {
|
16
|
+
"type": "Entry",
|
17
|
+
"id": "user_2"
|
18
|
+
},
|
19
|
+
"skills": [
|
20
|
+
{
|
21
|
+
"type": "job_skills",
|
22
|
+
"id": "job_skills_2"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"type": "job_skills",
|
26
|
+
"id": "job_skills_3"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"type": "job_skills",
|
30
|
+
"id": "job_skills_4"
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"type": "job_skills",
|
34
|
+
"id": "job_skills_7"
|
35
|
+
},
|
36
|
+
{
|
37
|
+
"type": "job_skills",
|
38
|
+
"id": "job_skills_8"
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"type": "job_skills",
|
42
|
+
"id": "job_skills_9"
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"type": "job_skills",
|
46
|
+
"id": "job_skills_10"
|
47
|
+
}
|
48
|
+
]
|
49
|
+
}
|