Skip to content

Commit

Permalink
Easi 3774/existing model link refactor (#916)
Browse files Browse the repository at this point in the history
* feat: update the schema for a high level existing models structure

* feat: add field_name to existing model link in database and go model

* chore: fix migration syntax

* feat: work in progress first pass to add field name to loader and merge statement

* chore: make existing model modelName field not null in GQL

* chore: add missing comma to merge statement

* feat: add constraints and update audit table config

* feat: add upcoming field enum to test constraints

* feat: update data loader to return data by compound key

* feat: update postman collection for existing model links

* feat: expose fieldName and modelPlanID on ExistingModelLinks type

* chore: rename migration

* feat: first pass return an array of names for a collection of Existing Model Links

* feat: correct bad unit test, add first unit test for getting names

* feat: add ordering to the names query

* feat: add unit test to make sure only relevant fields are returned

* chore: remove old comments

* chore: remove old todo

* update queries and ran scripts/dev gql

* udpated query and update payload

* renamed migration due to conflict

* chore: correct capitalization of table alias

* Update schema and translation files to make sure data goes to CSV

* udpate tests and snaps

* remove .only in test

* adding one more conditional

---------

Co-authored-by: Gary Zhao <[email protected]>
Co-authored-by: Gary Zhao <[email protected]>
  • Loading branch information
3 people authored Jan 30, 2024
1 parent 4cef085 commit 56ce40a
Show file tree
Hide file tree
Showing 44 changed files with 1,452 additions and 620 deletions.
29 changes: 25 additions & 4 deletions MINT.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@
"body": {
"mode": "graphql",
"graphql": {
"query": "mutation updateExistingModelLinks{\n \n updateExistingModelLinks(modelPlanID:\"{{modelPlanID}}\", existingModelIDs:\n# null\n [100014,100015] \n currentModelPlanIDs: \n null,\n# [\"{{modelPlanID}}\" ]\n )\n {\n id\n\n currentModelPlan {\n id\n modelName\n }\n existingModel{\n id\n modelName\n }\n\n }\n \n \n}",
"query": "mutation updateExistingModelLinks {\n updateExistingModelLinks(\n modelPlanID: \"{{modelPlanID}}\"\n fieldName: \n # GEN_CHAR_PARTICIPATION_EXISTING_MODEL_WHICH\n GEN_CHAR_RESEMBLES_EXISTING_MODEL_WHICH\n existingModelIDs:\n null\n # [100014,100015]\n currentModelPlanIDs:\n # null\n [\"{{modelPlanID}}\"]\n ) {\n links {\n id\n modelPlanID\n existingModelID\n currentModelPlanID\n fieldName\n model {\n __typename\n\n ... on ExistingModel {\n modelName\n stage\n numberOfParticipants\n keywords\n }\n ... on ModelPlan {\n modelName\n abbreviation\n }\n }\n }\n }\n}\n",
"variables": ""
}
},
Expand All @@ -1966,7 +1966,7 @@
"body": {
"mode": "graphql",
"graphql": {
"query": "query existingModelLink{\n \n existingModelLink(id:\"{{existingModelLinkID}}\"){\n\n currentModelPlan {\n modelName\n }\n existingModel{\n modelName\n }\n\n }\n \n \n}",
"query": "query existingModelLink {\n existingModelLink(id: \"{{existingModelLinkID}}\") {\n id\n modelPlanID\n currentModelPlanID\n existingModelID\n fieldName\n model {\n __typename\n\n ... on ExistingModel {\n modelName\n stage\n numberOfParticipants\n keywords\n }\n ... on ModelPlan {\n modelName\n abbreviation\n }\n }\n }\n}\n",
"variables": ""
}
},
Expand All @@ -1980,14 +1980,35 @@
"response": []
},
{
"name": "ModelPlanGetExisting ModelLinks",
"name": "ModelPlanGetExisting ModelLinks (Gen Characteristics)",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "graphql",
"graphql": {
"query": "query ModelPlan{\n \n modelPlan(id:\"{{modelPlanID}}\"){\n id\n modelName\n nameHistory\n existingModelLinks{\n currentModelPlan {\n modelName\n }\n existingModel{\n modelName\n }\n }\n }\n \n \n}",
"query": "query ModelPlan {\n modelPlan(id: \"{{modelPlanID}}\") {\n id\n modelName\n nameHistory\n generalCharacteristics {\n resemblesExistingModelWhich {\n links {\n id\n modelPlanID\n existingModelID\n currentModelPlanID\n fieldName\n model {\n __typename\n\n ... on ExistingModel {\n modelName\n stage\n numberOfParticipants\n keywords\n }\n ... on ModelPlan {\n modelName\n abbreviation\n }\n }\n }\n }\n }\n }\n}\n",
"variables": ""
}
},
"url": {
"raw": "{{url}}",
"host": [
"{{url}}"
]
}
},
"response": []
},
{
"name": "ModelPlanCollection ModelLinks (Gen Characteristics)",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "graphql",
"graphql": {
"query": "query modelPlanCollection {\n modelPlanCollection(filter: INCLUDE_ALL) {\n id\n modelName\n nameHistory\n generalCharacteristics {\n resemblesExistingModelWhich {\n links {\n id\n modelPlanID\n existingModelID\n currentModelPlanID\n fieldName\n model {\n __typename\n\n ... on ExistingModel {\n modelName\n stage\n numberOfParticipants\n keywords\n }\n ... on ModelPlan {\n modelName\n abbreviation\n }\n }\n }\n }\n }\n }\n}\n",
"variables": ""
}
},
Expand Down
6 changes: 3 additions & 3 deletions cmd/dbseed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (s *Seeder) SeedData() {
"highLevelNote": "Some high level note",
},
)
s.existingModelLinkCreate(planWithBasics, []int{links[3].ID, links[4].ID}, nil)
s.existingModelLinkCreate(planWithBasics, models.EMLFTGeneralCharacteristicsResemblesExistingModelWhich, []int{links[3].ID, links[4].ID}, nil)

// Seed a plan with collaborators
planWithCollaborators := s.createModelPlan("Plan With Collaborators", "MINT")
Expand All @@ -141,7 +141,7 @@ func (s *Seeder) SeedData() {
TeamRoles: []models.TeamRole{models.TeamRoleLeadership},
})

s.existingModelLinkCreate(planWithCollaborators, []int{links[4].ID}, nil)
s.existingModelLinkCreate(planWithCollaborators, models.EMLFTGeneralCharacteristicsResemblesExistingModelWhich, []int{links[4].ID}, nil)

// Seed a plan with CRs / TDLs
planWithCrTDLs := s.createModelPlan("Plan With CRs and TDLs", "MINT")
Expand All @@ -161,7 +161,7 @@ func (s *Seeder) SeedData() {
Title: "My TDL",
Note: &tdlNote,
})
s.existingModelLinkCreate(planWithCrTDLs, nil, []uuid.UUID{planWithCollaborators.ID, planWithBasics.ID})
s.existingModelLinkCreate(planWithCrTDLs, models.EMLFTGeneralCharacteristicsResemblesExistingModelWhich, nil, []uuid.UUID{planWithCollaborators.ID, planWithBasics.ID})

// Seed a plan that is already archived
archivedPlan := s.createModelPlan("Archived Plan", "MINT")
Expand Down
4 changes: 3 additions & 1 deletion cmd/dbseed/resolver_wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,18 @@ func (s *Seeder) operationalSolutionSubtasksCreate(
// It will panic if an error occurs, rather than bubbling the error up
func (s *Seeder) existingModelLinkCreate(
mp *models.ModelPlan,
fieldName models.ExisitingModelLinkFieldType,
existingModelIDs []int,
currentModelPlanIDs []uuid.UUID,
) []*models.ExistingModelLink {
) *models.ExistingModelLinks {

principal := s.getTestPrincipalByUUID(mp.CreatedBy)
links, err := resolvers.ExistingModelLinksUpdate(
s.Config.Logger,
s.Config.Store,
principal,
mp.ID,
fieldName,
existingModelIDs,
currentModelPlanIDs,
)
Expand Down
46 changes: 46 additions & 0 deletions migrations/V143__Add_Field_Name_To_Existing_Model_Link.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- Create the new type
CREATE TYPE EXISITING_MODEL_LINK_FIELD_TYPE AS ENUM (
'GEN_CHAR_RESEMBLES_EXISTING_MODEL_WHICH',
'GEN_CHAR_PARTICIPATION_EXISTING_MODEL_WHICH'
);

-- add the column to the table
ALTER TABLE existing_model_link
ADD COLUMN field_name EXISITING_MODEL_LINK_FIELD_TYPE;

-- Update existing data to point to the new column (this is the only field in use currently)
UPDATE existing_model_link
SET field_name = 'GEN_CHAR_RESEMBLES_EXISTING_MODEL_WHICH',
modified_by = '00000001-0001-0001-0001-000000000001',
modified_dts = CURRENT_TIMESTAMP;


ALTER TABLE existing_model_link
ALTER COLUMN field_name SET NOT NULL;

/* Update Audit table to insert the field when link is created*/
UPDATE audit.table_config
SET
insert_fields = '{existing_model_id,current_model_plan_id,field_name}',
modified_by = '00000001-0001-0001-0001-000000000001', --system_account
modified_dts = CURRENT_TIMESTAMP
WHERE name = 'existing_model_link';




ALTER TABLE existing_model_link
DROP CONSTRAINT unique_existing_model_link_existing;

/* Add constraint requiring that you can only link a model and existing model once per field*/
ALTER TABLE existing_model_link
ADD CONSTRAINT unique_existing_model_link_existing_field_name UNIQUE (model_plan_id, existing_model_id, field_name);
COMMENT ON CONSTRAINT unique_existing_model_link_existing_field_name ON existing_model_link IS 'This constraint requires that there is not a duplicate link per model_plan, existing model, and field name';


ALTER TABLE existing_model_link
DROP CONSTRAINT unique_existing_model_link_current_model;
/* Add constraint requiring that you can only link a model and current model once per field*/
ALTER TABLE existing_model_link
ADD CONSTRAINT unique_existing_model_link_current_model_field_name UNIQUE (model_plan_id, current_model_plan_id, field_name);
COMMENT ON CONSTRAINT unique_existing_model_link_current_model_field_name ON existing_model_link IS 'This constraint requires that there is not a duplicate link per model_plan, current_model, and field name';
Loading

0 comments on commit 56ce40a

Please sign in to comment.