Unable to export nested HABT data in project export

I'm unable to work out how to export and import nested HABTM data in our ~"project import" ~"project export"er .

Problem

We want to export/import the following three new models in the project export/importer:

  • DesignManagement::Design
  • DesignManagement::DesignsVersion (a HABTM model)
  • DesignManagement::Version

Some things:

  • Issues have many versions (and also have many designs)
  • versions have many designs
  • designs have many versions
  • designs_versions is the HABTM join table, and has some extra data on it that we need

Example data

When a user uploads 2 designs at the same time, they create 2 new Designs which share the same Version.

graph TD;
Version1-->Design1;
Version1-->Design2;

When a user changes the designs and uploads the same 2 designs at the same time again, they create a new Version which links to the existing Designs.

graph TD;
Version2-->Design1;
Version2 --- Design2;

We end up with:

graph TD;
Version1 --- Design1;
Version1 --- Design2;
Version2 --- Design1;
Version2 --- Design2;

Or if we export as JSON, trees like this:

graph TD;
Version1 --- Design1;
Version1 --- Design2;
graph TD;
Version2 --- Design1;
Version2 --- Design2;

Or another view of the same data:

graph TD;
Design1 --- Version1;
Design1 --- Version2;
graph TD;
Design2 --- Version1;
Design2 --- Version2;

Exporting this

The import_export.yml file lets us describe the relations (stemming from Project) to include in the export.

Currently, I can't find a way to export this data in a way that can successfully be imported:

Attempt 1

 project_tree:
    - issues:
      - versions:
        - design_versions:
          - design:

This leads to duplicate Designs being exported (which can't be imported because of unique constraints on model and db)

Attempt 2

 project_tree:
    - issues:
      - designs:
        - design_versions:
          - version:

Same as above, but leads to duplicate Versions.

Attempt 3

  project_tree:
    - issues:
      - versions:
        - design_versions:
      - designs:

This leads to DesignVersions with null design_ids

Edited Aug 04, 2019 by Luke Duncalfe
Assignee Loading
Time tracking Loading