summaryrefslogtreecommitdiffstats
path: root/utils/test/vnfcatalogue
diff options
context:
space:
mode:
authorMorgan Richomme <morgan.richomme@orange.com>2017-02-03 14:57:44 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-02-03 14:57:44 +0000
commit3302a2a6d341b6e8df8a96a29e0543a4bc7fd057 (patch)
treebaabea52d4d97b86db02ed4e9b30cf25041862a5 /utils/test/vnfcatalogue
parent0bc0837faa8a942b5b2158e0c307cd4c1f09a3ac (diff)
parenta305ee3192280867b40d5294d3cb48b189924cc5 (diff)
Merge "Added helper scripts"
Diffstat (limited to 'utils/test/vnfcatalogue')
-rw-r--r--utils/test/vnfcatalogue/helpers/README.md22
-rw-r--r--utils/test/vnfcatalogue/helpers/migrate.js78
-rw-r--r--utils/test/vnfcatalogue/helpers/schema.js51
3 files changed, 151 insertions, 0 deletions
diff --git a/utils/test/vnfcatalogue/helpers/README.md b/utils/test/vnfcatalogue/helpers/README.md
new file mode 100644
index 000000000..6c0ca78c3
--- /dev/null
+++ b/utils/test/vnfcatalogue/helpers/README.md
@@ -0,0 +1,22 @@
+# Helper Directory
+
+## Helper to migrate database
+
+First make sure nodejs and mysql are installed. Then use
+
+```bash
+npm install bookshelf mysql knex when lodash --save
+```
+
+Create a database named **vnf_catalogue**.
+Enter the mysql credentials in migrate.js.
+
+Then use
+
+```bash
+node migrate
+```
+
+If successful the script will return success message. The current script is
+idempotent is nature, if run twice it will just return error and write nothing.
+
diff --git a/utils/test/vnfcatalogue/helpers/migrate.js b/utils/test/vnfcatalogue/helpers/migrate.js
new file mode 100644
index 000000000..ec209053c
--- /dev/null
+++ b/utils/test/vnfcatalogue/helpers/migrate.js
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Kumar Rishabh(penguinRaider) and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Apache License, Version 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *******************************************************************************/
+
+var knex = require('knex')({
+ client: 'mysql',
+ connection: {
+ host : 'localhost',
+ user : '*',
+ password : '*',
+ database : 'vnf_catalogue',
+ charset : 'utf8'
+ }
+});
+var Schema = require('./schema');
+var sequence = require('when/sequence');
+var _ = require('lodash');
+function createTable(tableName) {
+ return knex.schema.createTable(tableName, function (table) {
+ var column;
+ var columnKeys = _.keys(Schema[tableName]);
+ _.each(columnKeys, function (key) {
+ if (Schema[tableName][key].type === 'text' && Schema[tableName][key].hasOwnProperty('fieldtype')) {
+ column = table[Schema[tableName][key].type](key, Schema[tableName][key].fieldtype);
+ }
+ else if (Schema[tableName][key].type === 'string' && Schema[tableName][key].hasOwnProperty('maxlength')) {
+ column = table[Schema[tableName][key].type](key, Schema[tableName][key].maxlength);
+ }
+ else {
+ column = table[Schema[tableName][key].type](key);
+ }
+ if (Schema[tableName][key].hasOwnProperty('nullable') && Schema[tableName][key].nullable === true) {
+ column.nullable();
+ }
+ else {
+ column.notNullable();
+ }
+ if (Schema[tableName][key].hasOwnProperty('primary') && Schema[tableName][key].primary === true) {
+ column.primary();
+ }
+ if (Schema[tableName][key].hasOwnProperty('unique') && Schema[tableName][key].unique) {
+ column.unique();
+ }
+ if (Schema[tableName][key].hasOwnProperty('unsigned') && Schema[tableName][key].unsigned) {
+ column.unsigned();
+ }
+ if (Schema[tableName][key].hasOwnProperty('references')) {
+ column.references(Schema[tableName][key].references);
+ }
+ if (Schema[tableName][key].hasOwnProperty('defaultTo')) {
+ column.defaultTo(Schema[tableName][key].defaultTo);
+ }
+ });
+ });
+}
+function createTables () {
+ var tables = [];
+ var tableNames = _.keys(Schema);
+ tables = _.map(tableNames, function (tableName) {
+ return function () {
+ return createTable(tableName);
+ };
+ });
+ return sequence(tables);
+}
+createTables()
+.then(function() {
+ console.log('Tables created!!');
+ process.exit(0);
+})
+.catch(function (error) {
+ throw error;
+});
diff --git a/utils/test/vnfcatalogue/helpers/schema.js b/utils/test/vnfcatalogue/helpers/schema.js
new file mode 100644
index 000000000..2aaf99ae2
--- /dev/null
+++ b/utils/test/vnfcatalogue/helpers/schema.js
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Kumar Rishabh(penguinRaider) and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Apache License, Version 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *******************************************************************************/
+var Schema = {
+ photo: {
+ photo_id: {type: 'increments', nullable: false, primary: true},
+ photo_url: {type: 'string', maxlength: 254, nullable: false}
+ },
+ user: {
+ user_id: {type: 'increments', nullable: false, primary: true},
+ user_name: {type: 'string', maxlength: 254, nullable: false},
+ password: {type: 'string', maxlength: 150, nullable: false},
+ email_id: {type: 'string', maxlength: 254, nullable: false, unique: true, validations: {isEmail: true}},
+ photo_id: {type: 'integer', nullable: true, unsigned: true, references: 'photo.photo_id'},
+ company: {type: 'string', maxlength: 254, nullable: false},
+ introduction: {type: 'string', maxlength: 510, nullable: false},
+ last_login: {type: 'dateTime', nullable: true},
+ created_at: {type: 'dateTime', nullable: false},
+ },
+ vnf: {
+ vnf_id: {type: 'increments', nullable: false, primary: true},
+ vnf_name: {type: 'string', maxlength: 254, nullable: false},
+ repo_url: {type: 'string', maxlength: 254, nullable: false},
+ photo_id: {type: 'integer', nullable: true, unsigned: true, references: 'photo.photo_id'},
+ submitter_id: {type: 'integer', nullable: false, unsigned: true, references: 'user.user_id'},
+ lines_of_code: {type: 'integer', nullable: true, unsigned: true},
+ versions: {type: 'integer', nullable: true, unsigned: true},
+ no_of_developers: {type: 'integer', nullable: true, unsigned: true},
+ },
+ tag: {
+ tag_id: {type: 'increments', nullable: false, primary: true},
+ name: {type: 'string', maxlength: 150, nullable: false}
+ },
+ vnf_tags: {
+ vnf_tag_id: {type: 'increments', nullable: false, primary: true},
+ tag_id: {type: 'integer', nullable: false, unsigned: true, references: 'tag.tag_id'},
+ vnf_id: {type: 'integer', nullable: false, unsigned: true, references: 'vnf.vnf_id'},
+ },
+ vnf_contributors: {
+ vnf_contributors_id: {type: 'increments', nullable: false, primary: true},
+ user_id: {type: 'integer', nullable: false, unsigned: true, references: 'user.user_id'},
+ vnf_id: {type: 'integer', nullable: false, unsigned: true, references: 'vnf.vnf_id'},
+ created_at: {type: 'dateTime', nullable: false},
+ }
+};
+module.exports = Schema;