Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 refactor the importer #8473

Merged
merged 21 commits into from
May 23, 2017

Conversation

kirrg001
Copy link
Contributor

@kirrg001 kirrg001 commented May 21, 2017

refs #5422

🎊 ✌🏻

goals

  1. we have two importer implementations, get rid of the old importer and continue with the new importer logic

  2. remove unneeded logic to import specific cases (the specific cases are still supported, just a little bit smarter)

notes

  • most of the specific import cases are handled via the model layer
  • we have many importer tests, the main goal here was to keep them as is and they should pass with the new logic
  • there is a clearer differentiation between real error and problems/warnings (which we can show in the UI)
  • the logic of importing apps was ignored, it never actually imported apps
  • see more detailed descriptions in the commits

todo's

  • go over data importers and check if something is missing e.g. apps, clients, permissions!
  • test some exports of 1.0
  • import a large (~100mb) database
  • make a sanity check: compare an import carefully (tags, attached tags, posts, users, roles, images)
  • wait for confirmation: Can't import my backupΒ #8365 (comment)
  • update the commit messages again
  • can i import null dates? yes, but they are transformed
  • more edge case testing

@kirrg001 kirrg001 force-pushed the 1.0.0-dev/fix-the-importer-logic branch 2 times, most recently from fca228e to 12a3056 Compare May 22, 2017 11:21
kirrg001 added 6 commits May 22, 2017 13:22
refs TryGhost#5422

- the new editor added the support for none null titles (null -> `(untitled)`)
- all import tests relied on post.title null -> fails
- we can support null titles after this PR if we want
no issue

- this implementation was wrong
refs TryGhost#5422

- it was only supported to add roles by id e.g. roles = [1] or by object e.g. roles = [{....}]
- we use the name strategy also for tags e.g. tags = ['my-tag']
- we support this for roles as well, this makes it easier when importing related user roles (because usually roles already exists in the database and the related id's are wrong e.g. roles_users)
refs TryGhost#5422

- if the json file contains null values for created_at/updated_at
- can be handled on model layer and not on the importer layer
refs TryGhost#5422

- post or tag slugs are always safe strings
- if e.g. you import a null slug, we can handle this, no need to crash or to cover this on import layer
refs TryGhost#5422

- basically nothing has changed here, just the none usage of the old importer and the result of problems/warnings while importing
@kirrg001 kirrg001 force-pushed the 1.0.0-dev/fix-the-importer-logic branch from 12a3056 to f9c2691 Compare May 22, 2017 11:24
kirrg001 added 4 commits May 22, 2017 13:25
refs TryGhost#5422

- this is the new integration of the importer
- i have used a class inheritance mechanismn to achieve an easier readability and maintenace
- most of the logic bits were copied from the old importer or modified/easified
- here a list:
    - schema validation (happens on model layer) was ignored
    - allow to import unknown user id's (see TryGhost#8365)
    - most of the duplication handling happens on model layer (we can use the power of unique fields and errors from the database)
- this PR has not concentrated on clear error messages or logs (this comes tomorrow)
- i've added debug messages
- the import is splitted into three steps:
  - beforeImport
    --> prepares the data to import, sorts out relations (roles, tags), detects fields (for LTS)
  - doImport
    --> does the actual import
  - afterImport
    --> updates the data after successful import e.g. update all user reference fields e.g. published_by (compares the imported data with the current state of the database)
    --> the background why we are doing it after the import is that we don't have to write complicated logic to detect outdated user references before we know which user get's which id
    --> plus: we don't care about the order of inserting the data
    --> keep in mind: we never ever import id's, that's why user references are usually outdated
    --> e.g. you import a post with `published_by:2`, but user 2 get's a new ObjectId 'X', we have to update the reference
refs TryGhost#5422

- simply move to the correct folder
refs TryGhost#5422

- the markdown field will be removed soon, see TryGhost#8479
- if you import images the importer crashes if markdown is null e.g. the welcome post has no markdown field anymore (results in null)
@kirrg001 kirrg001 force-pushed the 1.0.0-dev/fix-the-importer-logic branch from f9c2691 to 81be4e3 Compare May 22, 2017 11:25
@kirrg001 kirrg001 changed the title [WIP] 🎨 refactor the importer 🎨 refactor the importer May 22, 2017
@kirrg001
Copy link
Contributor Author

kirrg001 commented May 22, 2017

@cobbspur

This is ready for review.

I hope you find some issues with my PR, hard to cover every case alone.
I have imported lot's of exports, everything worked well for me.

Everything should work like before (+ even more cases are supported).

Don't be confused about the missing menu when importing a database, see #8307

@kirrg001 kirrg001 force-pushed the 1.0.0-dev/fix-the-importer-logic branch from ef84651 to 95df9ab Compare May 23, 2017 05:03
kirrg001 added 4 commits May 23, 2017 07:33
- will show the user why entries weren't imported
- e.g. Entry was ignored. We found a duplicate.
- return entry context objects as pretty json
- do not return warnings for role duplications, no helpful information
@kirrg001 kirrg001 force-pushed the 1.0.0-dev/fix-the-importer-logic branch from 95df9ab to 367cddf Compare May 23, 2017 05:33
- we show the affected json entries as one line in the UI
@kirrg001 kirrg001 force-pushed the 1.0.0-dev/fix-the-importer-logic branch from 812bd48 to 957099a Compare May 23, 2017 11:31
Copy link
Member

@cobbspur cobbspur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and LGTM

@cobbspur cobbspur merged commit 1f37ff6 into TryGhost:master May 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants