-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
products
- Loading branch information
Showing
2 changed files
with
218 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
WITH new_values ("tableName","name","fileName","nameField") as ( | ||
values | ||
('Surveys', 'Surveys', 'surveys', 'title'), | ||
('SurveyQuestions', 'Survey Questions', 'survey_questions', 'label'), | ||
('SurveyQuestionOptions', 'Survey Question Options', 'survey_question_options', 'label'), | ||
('SurveyAnswers', 'Survey Answers', 'survey_answers', 'value'), | ||
('Groups', 'Groups', 'groups', 'title'), | ||
('Organizations', 'Organizations', 'organizations', 'name'), | ||
('Tasks', 'Tasks', 'tasks', 'title'), | ||
('WorflowSteps', 'WorflowSteps', 'worflowSteps', 'title'), | ||
('Products', 'Products', 'products', 'title'), | ||
('UnitOfAnalysis', 'UnitOfAnalysis', 'uoas', 'name'), | ||
('UnitOfAnalysisType', 'UnitOfAnalysisType', 'uoatypes', 'name'), | ||
('UnitOfAnalysisClassType', 'UnitOfAnalysisClassType', 'uoaclasstypes', 'name'), | ||
('UnitOfAnalysisTag', 'UnitOfAnalysisTag', 'uoatags', 'name'), | ||
('Projects', 'projects', 'projects', 'codeName'), | ||
('Discussions', 'Discussions', 'discussions', 'name'), | ||
('Users', 'Users', 'users', 'email'), | ||
('Notifications', 'notifications', 'notifications', 'body'), | ||
('ProductUOA', 'productUoa', 'product_uoa', 'productId'), | ||
('Indexes', 'Indexes', 'indexes', 'title'), | ||
('Subindexes', 'Subindexes', 'subindexes', 'title'), | ||
('IndexQuestionWeights', 'IndexQuestionWeights', 'index_question_weights', 'type'), | ||
('IndexSubindexWeights', 'IndexSubindexWeights', 'index_subindex_weights', 'type'), | ||
('SubindexWeights', 'SubindexWeights', 'subindex_weights', 'type') | ||
), | ||
upsert as | ||
( | ||
update "Essences" m | ||
set "tableName" = nv."tableName", | ||
"fileName" = nv."fileName", | ||
"nameField" = nv."nameField" | ||
FROM new_values nv | ||
WHERE upper(m."name") = upper(nv."name") | ||
RETURNING m.* | ||
) | ||
-- select * from upsert | ||
INSERT INTO "Essences" ("tableName","name","fileName","nameField") | ||
SELECT "tableName","name","fileName","nameField" | ||
FROM new_values | ||
WHERE NOT EXISTS (SELECT 1 | ||
FROM upsert up | ||
WHERE upper(up."name") = upper(new_values."name")) |