Skip to content

Commit b78f9c3

Browse files
committed
Project migration challenge
1 parent 47c3667 commit b78f9c3

File tree

12 files changed

+978
-106
lines changed

12 files changed

+978
-106
lines changed

.babelrc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"presets": ["es2015"],
3-
"plugins": [
4-
["transform-runtime", {
5-
"polyfill": false,
6-
"regenerator": true
2+
"presets": [
3+
["env", {
4+
"targets": {
5+
"node": "current"
6+
}
77
}]
88
]
99
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- make sure to update existing projects to have this field set to "v2"
2+
ALTER TABLE projects ADD COLUMN "version" varchar(3) NOT NULL DEFAULT 'v2';
3+
-- make sure new projects from now on have "v3" as default value
4+
ALTER TABLE projects ALTER COLUMN "version" SET DEFAULT 'v3'

package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
"scripts": {
1010
"lint": "./node_modules/.bin/eslint .",
1111
"lint:fix": "./node_modules/.bin/eslint . --fix || true",
12-
"build": "babel src -d dist --presets es2015",
12+
"build": "babel src -d dist",
1313
"sync:db": "./node_modules/.bin/babel-node migrations/sync.js",
1414
"sync:es": "./node_modules/.bin/babel-node migrations/elasticsearch_sync.js",
1515
"migrate:es": "./node_modules/.bin/babel-node migrations/seedElasticsearchIndex.js",
1616
"prestart": "npm run -s build",
1717
"start": "node dist",
18-
"start:dev": "NODE_ENV=development PORT=8001 nodemon -w src --exec \"babel-node src --presets es2015\" | ./node_modules/.bin/bunyan",
18+
"start:dev": "NODE_ENV=development PORT=8001 nodemon -w src --exec \"babel-node src\" | ./node_modules/.bin/bunyan",
1919
"test": "NODE_ENV=test npm run lint && NODE_ENV=test npm run sync:es && NODE_ENV=test ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- --compilers js:babel-core/register $(find src -path '*spec.js*')",
2020
"test:watch": "NODE_ENV=test ./node_modules/.bin/mocha -w --compilers js:babel-core/register $(find src -path '*spec.js*')",
21-
"seed": "babel-node src/tests/seed.js --presets es2015"
21+
"seed": "babel-node src/tests/seed.js"
2222
},
2323
"repository": {
2424
"type": "git",
@@ -53,7 +53,7 @@
5353
"lodash": "^4.16.4",
5454
"method-override": "^2.3.9",
5555
"pg": "^4.5.5",
56-
"pg-native": "^1.10.0",
56+
"pg-native": "^1.10.1",
5757
"sequelize": "^3.23.0",
5858
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.3",
5959
"traverse": "^0.6.6",
@@ -63,9 +63,7 @@
6363
"babel-cli": "^6.9.0",
6464
"babel-core": "^6.11.4",
6565
"babel-eslint": "^7.1.1",
66-
"babel-plugin-add-module-exports": "^0.2.1",
67-
"babel-plugin-transform-runtime": "^6.23.0",
68-
"babel-preset-es2015": "^6.9.0",
66+
"babel-preset-env": "^1.7.0",
6967
"bunyan": "^1.8.1",
7068
"chai": "^3.5.0",
7169
"eslint": "^3.16.1",

postman.json

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2905,6 +2905,104 @@
29052905
"response": []
29062906
}
29072907
]
2908+
},
2909+
{
2910+
"name": "Project upgrade",
2911+
"description": "Request to migrate projects.",
2912+
"item": [
2913+
{
2914+
"name": "Migrate project",
2915+
"request": {
2916+
"method": "POST",
2917+
"header": [
2918+
{
2919+
"key": "Authorization",
2920+
"value": "Bearer {{jwt-token}}"
2921+
},
2922+
{
2923+
"key": "Content-Type",
2924+
"value": "application/json"
2925+
}
2926+
],
2927+
"body": {
2928+
"mode": "raw",
2929+
"raw": "{\n\t\"param\": {\n\t\t\"targetVersion\": \"v3\",\n\t\t\"defaultProductTemplateId\": 3\n\t}\n}"
2930+
},
2931+
"url": "{{api-url}}/v4/projects/6/upgrade",
2932+
"description": ""
2933+
},
2934+
"response": []
2935+
},
2936+
{
2937+
"name": "Migrate project (completed)",
2938+
"request": {
2939+
"method": "POST",
2940+
"header": [
2941+
{
2942+
"key": "Authorization",
2943+
"value": "Bearer {{jwt-token}}"
2944+
},
2945+
{
2946+
"key": "Content-Type",
2947+
"value": "application/json"
2948+
}
2949+
],
2950+
"body": {
2951+
"mode": "raw",
2952+
"raw": "{\n\t\"param\": {\n\t\t\"targetVersion\": \"v3\",\n\t\t\"defaultProductTemplateId\": 3\n\t}\n}"
2953+
},
2954+
"url": "{{api-url}}/v4/projects/7/upgrade",
2955+
"description": ""
2956+
},
2957+
"response": []
2958+
},
2959+
{
2960+
"name": "Migrate project with phase name",
2961+
"request": {
2962+
"method": "POST",
2963+
"header": [
2964+
{
2965+
"key": "Authorization",
2966+
"value": "Bearer {{jwt-token}}"
2967+
},
2968+
{
2969+
"key": "Content-Type",
2970+
"value": "application/json"
2971+
}
2972+
],
2973+
"body": {
2974+
"mode": "raw",
2975+
"raw": "{\n\t\"param\": {\n\t\t\"targetVersion\": \"v3\",\n\t\t\"defaultProductTemplateId\": 3,\n\t\t\"phaseName\": \"Custom phase name\"\n\t}\n}"
2976+
},
2977+
"url": "{{api-url}}/v4/projects/6/upgrade",
2978+
"description": ""
2979+
},
2980+
"response": []
2981+
},
2982+
{
2983+
"name": "Migrate project with phase name (completed)",
2984+
"request": {
2985+
"method": "POST",
2986+
"header": [
2987+
{
2988+
"key": "Authorization",
2989+
"value": "Bearer {{jwt-token}}"
2990+
},
2991+
{
2992+
"key": "Content-Type",
2993+
"value": "application/json"
2994+
}
2995+
],
2996+
"body": {
2997+
"mode": "raw",
2998+
"raw": "{\n\t\"param\": {\n\t\t\"targetVersion\": \"v3\",\n\t\t\"defaultProductTemplateId\": 3,\n\t\t\"phaseName\": \"Custom phase name\"\n\t}\n}"
2999+
},
3000+
"url": "{{api-url}}/v4/projects/7/upgrade",
3001+
"description": ""
3002+
},
3003+
"response": []
3004+
}
3005+
]
29083006
}
29093007
]
2910-
}
3008+
}

src/models/project.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module.exports = function defineProject(sequelize, DataTypes) {
4141
updatedAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
4242
createdBy: { type: DataTypes.INTEGER, allowNull: false },
4343
updatedBy: { type: DataTypes.INTEGER, allowNull: false },
44+
version: { type: DataTypes.STRING(3), allowNull: false, defaultValue: 'v3' },
4445
}, {
4546
tableName: 'projects',
4647
timestamps: true,

src/routes/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ router.route('/v4/projects/:projectId(\\d+)/attachments/:id(\\d+)')
6767
.patch(require('./attachments/update'))
6868
.delete(require('./attachments/delete'));
6969

70+
router.route('/v4/projects/:projectId(\\d+)/upgrade')
71+
.post(require('./projectUpgrade/create'));
72+
7073
router.route('/v4/projectTemplates')
7174
.post(require('./projectTemplates/create'))
7275
.get(require('./projectTemplates/list'));

0 commit comments

Comments
 (0)