masterrecord 0.0.23 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Entity/EntityModel.js +128 -120
- package/Entity/EntityModelBuilder.js +63 -63
- package/Entity/EntityTrackerModel.js +42 -42
- package/Masterrecord.js +173 -178
- package/Migrations/cli.js +105 -105
- package/Migrations/migrationTemplate.js +63 -63
- package/Migrations/migrations.js +46 -22
- package/Migrations/schema.js +42 -42
- package/QueryLanguage/_Expression.js +321 -321
- package/QueryLanguage/_LogicalQuery.js +22 -22
- package/QueryLanguage/_OperatorList.js +87 -87
- package/QueryLanguage/_QueryModel.js +441 -441
- package/QueryLanguage/_Tokenization.js +172 -172
- package/QueryLanguage/__Query.js +385 -385
- package/QueryLanguage/_simpleQuery.js +183 -183
- package/QueryLanguage/queryBuilder.js +51 -51
- package/{SQLEngine.js → SQLiteEngine.js} +56 -52
- package/Tools.js +55 -55
- package/package.json +27 -27
package/Masterrecord.js
CHANGED
|
@@ -1,179 +1,174 @@
|
|
|
1
|
-
|
|
2
|
-
// https://github.com/kriasoft/node-sqlite
|
|
3
|
-
// https://www.learnentityframeworkcore.com/dbset/deleting-data
|
|
4
|
-
// version 1.0.14
|
|
5
|
-
|
|
6
|
-
var modelBuilder = require('masterrecord/Entity/EntityModelBuilder');
|
|
7
|
-
var query = require('masterrecord/QueryLanguage/queryBuilder');
|
|
8
|
-
var tools = require('./Tools');
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
class Context {
|
|
12
|
-
|
|
13
|
-
_isModelValid = {
|
|
14
|
-
isValid: true,
|
|
15
|
-
errors: []
|
|
16
|
-
}
|
|
17
|
-
__allContexts = [];
|
|
18
|
-
__trackedEntities = [];
|
|
19
|
-
__relationshipModels = []
|
|
20
|
-
|
|
21
|
-
constructor(){
|
|
22
|
-
this._SQLEngine =
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
var
|
|
142
|
-
var sqlUpdate = {tableName:
|
|
143
|
-
this._SQLEngine.
|
|
144
|
-
break;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
this.__trackedEntities
|
|
158
|
-
return
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
1
|
+
|
|
2
|
+
// https://github.com/kriasoft/node-sqlite
|
|
3
|
+
// https://www.learnentityframeworkcore.com/dbset/deleting-data
|
|
4
|
+
// version 1.0.14
|
|
5
|
+
|
|
6
|
+
var modelBuilder = require('masterrecord/Entity/EntityModelBuilder');
|
|
7
|
+
var query = require('masterrecord/QueryLanguage/queryBuilder');
|
|
8
|
+
var tools = require('./Tools');
|
|
9
|
+
var SQLiteEngine = require('./SQLiteEngine');
|
|
10
|
+
|
|
11
|
+
class Context {
|
|
12
|
+
|
|
13
|
+
_isModelValid = {
|
|
14
|
+
isValid: true,
|
|
15
|
+
errors: []
|
|
16
|
+
}
|
|
17
|
+
__allContexts = [];
|
|
18
|
+
__trackedEntities = [];
|
|
19
|
+
__relationshipModels = []
|
|
20
|
+
|
|
21
|
+
constructor(){
|
|
22
|
+
this._SQLEngine = null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// IMPORTANT: SQLITE has no date so use text
|
|
26
|
+
// MUST MAP TYPES TO INTERGER, TEXT, BLOB, REAL, NUMERIC
|
|
27
|
+
setup(rootFolderLocation, env){
|
|
28
|
+
/*
|
|
29
|
+
expected model {
|
|
30
|
+
"type": "better-sqlite3",
|
|
31
|
+
"connection" : "/db/",
|
|
32
|
+
"password": "",
|
|
33
|
+
"username": ""
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
*/
|
|
37
|
+
if(env.type !== undefined){
|
|
38
|
+
switch(env.type) {
|
|
39
|
+
case "better-sqlite3":
|
|
40
|
+
// set the engine for everyone to use
|
|
41
|
+
this._SQLEngine = new new SQLiteEngine();
|
|
42
|
+
env.connection = rootFolderLocation + env.connection;
|
|
43
|
+
this.db = this._SQLiteEngine.setDB(env, env.type);
|
|
44
|
+
return this;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
returnCopywithoutPrimaryKeyAndVirtual(currentModel){
|
|
51
|
+
var newCurrentModel = Object.create(currentModel);
|
|
52
|
+
for(var entity in newCurrentModel.__entity) {
|
|
53
|
+
var currentEntity = newCurrentModel.__entity[entity];
|
|
54
|
+
if (newCurrentModel.__entity.hasOwnProperty(entity)) {
|
|
55
|
+
if(currentEntity.primary === true){
|
|
56
|
+
newCurrentModel[`__primaryKey`] = newCurrentModel[entity];
|
|
57
|
+
delete newCurrentModel[`_${entity}`];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if(currentEntity.virtual === true){
|
|
61
|
+
// skip it from the insert
|
|
62
|
+
delete newCurrentModel[`_${entity}`];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
return newCurrentModel;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// loop through all the enitities and check if required
|
|
70
|
+
validateEntity(currentModel){
|
|
71
|
+
for(var entity in currentModel.__entity) {
|
|
72
|
+
var currentEntity = currentModel.__entity[entity];
|
|
73
|
+
if (currentModel.__entity.hasOwnProperty(entity)) {
|
|
74
|
+
// TODO: // check if types are correct
|
|
75
|
+
if(currentEntity.default){
|
|
76
|
+
if(!currentModel[entity]){
|
|
77
|
+
currentModel[entity] = currentEntity.default;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if(currentEntity.required === true){
|
|
82
|
+
if(!currentModel[entity]){
|
|
83
|
+
this._isModelValid.isValid = false;
|
|
84
|
+
this._isModelValid.errors.push( `Entity ${entity} is a required Field`);
|
|
85
|
+
console.log(`Entity ${entity} is a required Field`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
dbset(model){
|
|
94
|
+
var validModel = modelBuilder.init(model);
|
|
95
|
+
validModel.__name = model.name;
|
|
96
|
+
this.__allContexts.push(validModel);
|
|
97
|
+
this.createNewInstance(validModel);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
createNewInstance(validModel){
|
|
101
|
+
this[validModel.__name] = new query(validModel, this);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
modelState(){
|
|
105
|
+
return this._isModelValid;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
saveChanges(){
|
|
109
|
+
|
|
110
|
+
for (var model in this.__trackedEntities) {
|
|
111
|
+
var currentModel = this.__trackedEntities[model];
|
|
112
|
+
// validate required fields
|
|
113
|
+
this.validateEntity(currentModel);
|
|
114
|
+
if(this._isModelValid.valid === false){
|
|
115
|
+
// everything great
|
|
116
|
+
console.log(JSON.stringify(this._isModelValid.valid.errors));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
try{
|
|
120
|
+
switch(currentModel.__state) {
|
|
121
|
+
case "modified":
|
|
122
|
+
if(currentModel.__dirtyFields.length <= 0){
|
|
123
|
+
throw "Tracked entity modified with no values being changed";
|
|
124
|
+
}
|
|
125
|
+
var cleanCurrentModel = this.returnCopywithoutPrimaryKeyAndVirtual(currentModel);
|
|
126
|
+
// build columns equal to value string
|
|
127
|
+
var argu = tools.buildSQLEqualTo(cleanCurrentModel);
|
|
128
|
+
var primaryKey = tools.getPrimaryKeyObject(cleanCurrentModel.__entity);
|
|
129
|
+
var sqlUpdate = {tableName: cleanCurrentModel.__entity.__name, arg: argu, primaryKey : primaryKey, value : cleanCurrentModel[`__primaryKey`] };
|
|
130
|
+
this._SQLEngine.update(sqlUpdate);
|
|
131
|
+
// code block
|
|
132
|
+
break;
|
|
133
|
+
case "insert":
|
|
134
|
+
|
|
135
|
+
var cleanCurrentModel = this.returnCopywithoutPrimaryKeyAndVirtual(currentModel);
|
|
136
|
+
var insertObj = tools.getInsertObj(cleanCurrentModel);
|
|
137
|
+
var sqlUpdate = {tableName: cleanCurrentModel.__entity.__name, columns: insertObj.columns, values: insertObj.values };
|
|
138
|
+
this._SQLEngine.insert(sqlUpdate);
|
|
139
|
+
break;
|
|
140
|
+
case "delete":
|
|
141
|
+
var primaryKey = tools.getPrimaryKeyObject(currentModel.__entity);
|
|
142
|
+
var sqlUpdate = {tableName: currentModel.__entity.__name, primaryKey : primaryKey, value : currentModel[primaryKey] };
|
|
143
|
+
this._SQLEngine.delete(sqlUpdate);
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch(error){
|
|
148
|
+
this.__trackedEntities = [];
|
|
149
|
+
console.log("error", error);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
this.__trackedEntities = [];
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
__Track(model){
|
|
157
|
+
this.__trackedEntities.push(model);
|
|
158
|
+
return model;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
__FindTracked(id){
|
|
162
|
+
if(id){
|
|
163
|
+
for (var model in this.__trackedEntities) {
|
|
164
|
+
if(this.__trackedEntities[model].__ID === id){
|
|
165
|
+
return this.__trackedEntities[model];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
179
174
|
module.exports = Context;
|
package/Migrations/cli.js
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/
|
|
3
|
-
const program = require('commander');
|
|
4
|
-
let fs = require('fs');
|
|
5
|
-
let path = require('path');
|
|
6
|
-
var Migration = require('./migrations');
|
|
7
|
-
|
|
8
|
-
const [,, ...args] = process.argv
|
|
9
|
-
|
|
10
|
-
program
|
|
11
|
-
.version('0.0.1')
|
|
12
|
-
.option('-v, --version', '0.0.1')
|
|
13
|
-
.description('A ORM framework that facilitates the creation and use of business objects whose data requires persistent storage to a database');
|
|
14
|
-
|
|
15
|
-
// Instructions : to run command you must go to folder where contaxt file is located and run command with context file name.
|
|
16
|
-
program
|
|
17
|
-
.command('enable-migrations <contextFileName>')
|
|
18
|
-
.alias('am')
|
|
19
|
-
.description('Enables the migration in your project by creating a Configuration class called ContextModelSnapShot.json')
|
|
20
|
-
.action(function(contextFileName){
|
|
21
|
-
// location of folder where command is being executed..
|
|
22
|
-
var executedLocation = process.cwd();
|
|
23
|
-
// go back 1 folder level
|
|
24
|
-
let previousFolder = path.join(executedLocation, '../');
|
|
25
|
-
var migrationsDirectory = `${previousFolder}/Migrations`;
|
|
26
|
-
if (!fs.existsSync(migrationsDirectory)){
|
|
27
|
-
fs.mkdirSync(migrationsDirectory);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var content = {
|
|
31
|
-
contextLocation: `${executedLocation}/${contextFileName}.js`,
|
|
32
|
-
migrationLocation: `${executedLocation}/Migrations`,
|
|
33
|
-
schema : {}
|
|
34
|
-
};
|
|
35
|
-
const jsonContent = JSON.stringify(content, null, 2);
|
|
36
|
-
try{
|
|
37
|
-
// will replace the whole file if it exist
|
|
38
|
-
fs.writeFileSync(`${migrationsDirectory}/ContextSnapShot.json`, jsonContent);
|
|
39
|
-
}catch (e){
|
|
40
|
-
console.log("Cannot write file ", e);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
program
|
|
45
|
-
.command('add-migration <name>')
|
|
46
|
-
.alias('am')
|
|
47
|
-
.description('Creates a new migration class')
|
|
48
|
-
.action(function(name){
|
|
49
|
-
|
|
50
|
-
try{
|
|
51
|
-
var contextSnapshot = fs.readFileSync(`./ContextSnapShot.json`, 'utf8');
|
|
52
|
-
var migration = new Migration();
|
|
53
|
-
var context = require(contextSnapshot.contextLocation);
|
|
54
|
-
var newEntity = migration.EDMModelDiffer(contextSnapshot.schema, context);
|
|
55
|
-
if(newEntity !== -1){
|
|
56
|
-
var migrationDate = Date.now();
|
|
57
|
-
migration.migrationCodeGenerator(name, newEntity, migrationDate);
|
|
58
|
-
console.log(`migration ${name}_${migrationDate} created`);
|
|
59
|
-
}
|
|
60
|
-
}catch (e){
|
|
61
|
-
console.log("Cannot read or find file ", e);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// will use the database settings to call and get the schema_migration table
|
|
67
|
-
// we will get the list of all migrations that have been ran
|
|
68
|
-
// we will compare that list with the folder of migrations to see if we ran everything
|
|
69
|
-
// the migrations we missed we will call the up method
|
|
70
|
-
// the up method will run the create database functions
|
|
71
|
-
// then update the database.js schema
|
|
72
|
-
|
|
73
|
-
program
|
|
74
|
-
.command('update-database <databaseSettingLocation> <migrationFolderLocation> ')
|
|
75
|
-
.alias('ud')
|
|
76
|
-
.description('Apply pending migrations to database')
|
|
77
|
-
.action(function(cmd){
|
|
78
|
-
var dir = process.cwd();
|
|
79
|
-
console.log("starting server");
|
|
80
|
-
require(dir + '/server.js');
|
|
81
|
-
//return "node c:\node\server.js"
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// we will find the migration folder inside the nearest app folder if no migration folder is location is added
|
|
85
|
-
program
|
|
86
|
-
.command('remove-migration <name> <migrationFolderLocation>')
|
|
87
|
-
.alias('rm')
|
|
88
|
-
.description('Removes the last migration that has not been applied')
|
|
89
|
-
.action(function(name){
|
|
90
|
-
// find migration file using name and delete it.
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// we will find the migration folder inside the nearest app folder if no migration folder is location is added
|
|
95
|
-
program
|
|
96
|
-
.command('revert-migration <name> <migrationFolderLocation>')
|
|
97
|
-
.alias('rm')
|
|
98
|
-
.description('Reverts back to the last migration with given name')
|
|
99
|
-
.action(function(cmd){
|
|
100
|
-
var dir = process.cwd();
|
|
101
|
-
console.log("starting server");
|
|
102
|
-
require(dir + '/server.js');
|
|
103
|
-
//return "node c:\node\server.js"
|
|
104
|
-
});
|
|
105
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/
|
|
3
|
+
const program = require('commander');
|
|
4
|
+
let fs = require('fs');
|
|
5
|
+
let path = require('path');
|
|
6
|
+
var Migration = require('./migrations');
|
|
7
|
+
|
|
8
|
+
const [,, ...args] = process.argv
|
|
9
|
+
|
|
10
|
+
program
|
|
11
|
+
.version('0.0.1')
|
|
12
|
+
.option('-v, --version', '0.0.1')
|
|
13
|
+
.description('A ORM framework that facilitates the creation and use of business objects whose data requires persistent storage to a database');
|
|
14
|
+
|
|
15
|
+
// Instructions : to run command you must go to folder where contaxt file is located and run command with context file name.
|
|
16
|
+
program
|
|
17
|
+
.command('enable-migrations <contextFileName>')
|
|
18
|
+
.alias('am')
|
|
19
|
+
.description('Enables the migration in your project by creating a Configuration class called ContextModelSnapShot.json')
|
|
20
|
+
.action(function(contextFileName){
|
|
21
|
+
// location of folder where command is being executed..
|
|
22
|
+
var executedLocation = process.cwd();
|
|
23
|
+
// go back 1 folder level
|
|
24
|
+
let previousFolder = path.join(executedLocation, '../');
|
|
25
|
+
var migrationsDirectory = `${previousFolder}/Migrations`;
|
|
26
|
+
if (!fs.existsSync(migrationsDirectory)){
|
|
27
|
+
fs.mkdirSync(migrationsDirectory);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var content = {
|
|
31
|
+
contextLocation: `${executedLocation}/${contextFileName}.js`,
|
|
32
|
+
migrationLocation: `${executedLocation}/Migrations`,
|
|
33
|
+
schema : {}
|
|
34
|
+
};
|
|
35
|
+
const jsonContent = JSON.stringify(content, null, 2);
|
|
36
|
+
try{
|
|
37
|
+
// will replace the whole file if it exist
|
|
38
|
+
fs.writeFileSync(`${migrationsDirectory}/ContextSnapShot.json`, jsonContent);
|
|
39
|
+
}catch (e){
|
|
40
|
+
console.log("Cannot write file ", e);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
program
|
|
45
|
+
.command('add-migration <name>')
|
|
46
|
+
.alias('am')
|
|
47
|
+
.description('Creates a new migration class')
|
|
48
|
+
.action(function(name){
|
|
49
|
+
|
|
50
|
+
try{
|
|
51
|
+
var contextSnapshot = fs.readFileSync(`./ContextSnapShot.json`, 'utf8');
|
|
52
|
+
var migration = new Migration();
|
|
53
|
+
var context = require(contextSnapshot.contextLocation);
|
|
54
|
+
var newEntity = migration.EDMModelDiffer(contextSnapshot.schema, context);
|
|
55
|
+
if(newEntity !== -1){
|
|
56
|
+
var migrationDate = Date.now();
|
|
57
|
+
migration.migrationCodeGenerator(name, newEntity, migrationDate);
|
|
58
|
+
console.log(`migration ${name}_${migrationDate} created`);
|
|
59
|
+
}
|
|
60
|
+
}catch (e){
|
|
61
|
+
console.log("Cannot read or find file ", e);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// will use the database settings to call and get the schema_migration table
|
|
67
|
+
// we will get the list of all migrations that have been ran
|
|
68
|
+
// we will compare that list with the folder of migrations to see if we ran everything
|
|
69
|
+
// the migrations we missed we will call the up method
|
|
70
|
+
// the up method will run the create database functions
|
|
71
|
+
// then update the database.js schema
|
|
72
|
+
|
|
73
|
+
program
|
|
74
|
+
.command('update-database <databaseSettingLocation> <migrationFolderLocation> ')
|
|
75
|
+
.alias('ud')
|
|
76
|
+
.description('Apply pending migrations to database')
|
|
77
|
+
.action(function(cmd){
|
|
78
|
+
var dir = process.cwd();
|
|
79
|
+
console.log("starting server");
|
|
80
|
+
require(dir + '/server.js');
|
|
81
|
+
//return "node c:\node\server.js"
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// we will find the migration folder inside the nearest app folder if no migration folder is location is added
|
|
85
|
+
program
|
|
86
|
+
.command('remove-migration <name> <migrationFolderLocation>')
|
|
87
|
+
.alias('rm')
|
|
88
|
+
.description('Removes the last migration that has not been applied')
|
|
89
|
+
.action(function(name){
|
|
90
|
+
// find migration file using name and delete it.
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
// we will find the migration folder inside the nearest app folder if no migration folder is location is added
|
|
95
|
+
program
|
|
96
|
+
.command('revert-migration <name> <migrationFolderLocation>')
|
|
97
|
+
.alias('rm')
|
|
98
|
+
.description('Reverts back to the last migration with given name')
|
|
99
|
+
.action(function(cmd){
|
|
100
|
+
var dir = process.cwd();
|
|
101
|
+
console.log("starting server");
|
|
102
|
+
require(dir + '/server.js');
|
|
103
|
+
//return "node c:\node\server.js"
|
|
104
|
+
});
|
|
105
|
+
|
|
106
106
|
program.parse(process.argv);
|