masterrecord 0.0.23 → 0.0.25
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/DeleteManager.js +51 -0
- package/Entity/EntityModel.js +192 -120
- package/Entity/EntityModelBuilder.js +41 -63
- package/Entity/EntityTrackerModel.js +222 -42
- package/InsertManager.js +138 -0
- package/MYSQLEngine.js +409 -0
- package/Masterrecord.js +233 -179
- package/Migrations/cli.js +106 -105
- package/Migrations/migrationTemplate.js +63 -63
- package/Migrations/migrations.js +65 -22
- package/Migrations/schema.js +42 -42
- package/QueryLanguage/queryManager.js +66 -0
- package/QueryLanguage/queryMethods.js +171 -0
- package/QueryLanguage/queryScript.js +331 -0
- package/SQLLiteEngine.js +409 -0
- package/Tools.js +118 -55
- package/package.json +23 -27
- package/QueryLanguage/_Expression.js +0 -322
- package/QueryLanguage/_LogicalQuery.js +0 -23
- package/QueryLanguage/_OperatorList.js +0 -88
- package/QueryLanguage/_QueryModel.js +0 -442
- package/QueryLanguage/_Tokenization.js +0 -173
- package/QueryLanguage/__Query.js +0 -386
- package/QueryLanguage/_simpleQuery.js +0 -184
- package/QueryLanguage/queryBuilder.js +0 -52
- package/SQLEngine.js +0 -52
package/Masterrecord.js
CHANGED
|
@@ -1,179 +1,233 @@
|
|
|
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('
|
|
7
|
-
var query = require('masterrecord/QueryLanguage/
|
|
8
|
-
var tools = require('./Tools');
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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('./Entity/EntityModelBuilder');
|
|
7
|
+
var query = require('masterrecord/QueryLanguage/queryMethods');
|
|
8
|
+
var tools = require('./Tools');
|
|
9
|
+
var SQLLiteEngine = require('masterrecord/SQLLiteEngine');
|
|
10
|
+
var MYSQLEngine = require('masterrecord/MYSQLEngine');
|
|
11
|
+
var insertManager = require('./InsertManager');
|
|
12
|
+
var deleteManager = require('./DeleteManager');
|
|
13
|
+
|
|
14
|
+
class Context {
|
|
15
|
+
_isModelValid = {
|
|
16
|
+
isValid: true,
|
|
17
|
+
errors: []
|
|
18
|
+
};
|
|
19
|
+
__entities = [];
|
|
20
|
+
__builderEntities = [];
|
|
21
|
+
__trackedEntities = [];
|
|
22
|
+
__relationshipModels = [];
|
|
23
|
+
|
|
24
|
+
constructor(){
|
|
25
|
+
// TODO when we build the sql engine it depends on the which type.
|
|
26
|
+
|
|
27
|
+
this._SQLEngine = "";
|
|
28
|
+
this.__name = this.constructor.name;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
SQLite expected model
|
|
33
|
+
{
|
|
34
|
+
"type": "better-sqlite3",
|
|
35
|
+
"connection" : "/db/",
|
|
36
|
+
"password": "",
|
|
37
|
+
"username": ""
|
|
38
|
+
}
|
|
39
|
+
*/
|
|
40
|
+
__SQLiteInit(env, sqlName){
|
|
41
|
+
try{
|
|
42
|
+
const sqlite3 = require(sqlName);
|
|
43
|
+
let DBAddress = `${env.completeConnection}${env.env}.sqlite3`;
|
|
44
|
+
var db = new sqlite3(DBAddress, env);
|
|
45
|
+
db.__name = sqlName;
|
|
46
|
+
this._SQLEngine = new SQLLiteEngine();
|
|
47
|
+
return db;
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
console.log("error SQL", e);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/*
|
|
55
|
+
mysql expected model
|
|
56
|
+
{
|
|
57
|
+
"type": "mysql",
|
|
58
|
+
host : 'localhost',
|
|
59
|
+
user : 'me',
|
|
60
|
+
password : 'secret',
|
|
61
|
+
database : 'my_db'
|
|
62
|
+
}
|
|
63
|
+
*/
|
|
64
|
+
__mysqlInit(env, sqlName){
|
|
65
|
+
try{
|
|
66
|
+
const mysql = require(sqlName);
|
|
67
|
+
const connection = mysql.createConnection(env);
|
|
68
|
+
connection.connect();
|
|
69
|
+
db.__name = sqlName;
|
|
70
|
+
this._SQLEngine = new MYSQLEngine();
|
|
71
|
+
return connection;
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
console.log("error SQL", e);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
__clearErrorHandler(){
|
|
82
|
+
this._isModelValid = {
|
|
83
|
+
isValid: true,
|
|
84
|
+
errors: []
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
setup(options, rootFolderLocation){
|
|
89
|
+
|
|
90
|
+
if(options !== undefined){
|
|
91
|
+
if(options.type !== undefined){
|
|
92
|
+
switch(options.type) {
|
|
93
|
+
case "better-sqlite3":
|
|
94
|
+
options.completeConnection = rootFolderLocation + options.connection;
|
|
95
|
+
this.db = this.__SQLiteInit(options, options.type);
|
|
96
|
+
this._SQLEngine.setDB(this.db, "better-sqlite3");
|
|
97
|
+
return this;
|
|
98
|
+
break;
|
|
99
|
+
case "mysql":
|
|
100
|
+
this.db = this.__mysqlInit(options, options.type);
|
|
101
|
+
this._SQLEngine.setDB(this.db, "mysql");
|
|
102
|
+
return this;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else{
|
|
107
|
+
console.log("database type not defined - Master Record");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else{
|
|
111
|
+
console.log("database information not added - Master Record");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
dbset(model, name){
|
|
117
|
+
var validModel = modelBuilder.create(model);
|
|
118
|
+
validModel.__name = name === undefined ? model.name : name;
|
|
119
|
+
this.__entities.push(validModel); // model object
|
|
120
|
+
var buildMod = tools.createNewInstance(validModel, query, this);
|
|
121
|
+
this.__builderEntities.push(buildMod); // query builder entites
|
|
122
|
+
this[validModel.__name] = buildMod;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
modelState(){
|
|
126
|
+
return this._isModelValid;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
saveChanges(){
|
|
130
|
+
try{
|
|
131
|
+
var tracked = this.__trackedEntities;
|
|
132
|
+
// start transaction
|
|
133
|
+
this._SQLEngine.startTransaction();
|
|
134
|
+
for (var model in tracked) {
|
|
135
|
+
var currentModel = tracked[model];
|
|
136
|
+
switch(currentModel.__state) {
|
|
137
|
+
case "insert":
|
|
138
|
+
var insert = new insertManager(this._SQLEngine, this._isModelValid, this.__entities);
|
|
139
|
+
insert.init(currentModel);
|
|
140
|
+
|
|
141
|
+
break;
|
|
142
|
+
case "modified":
|
|
143
|
+
if(currentModel.__dirtyFields.length > 0){
|
|
144
|
+
var cleanCurrentModel = tools.removePrimarykeyandVirtual(currentModel, currentModel._entity);
|
|
145
|
+
// build columns equal to value string
|
|
146
|
+
var argu = this._SQLEngine._buildSQLEqualTo(cleanCurrentModel);
|
|
147
|
+
var primaryKey = tools.getPrimaryKeyObject(cleanCurrentModel.__entity);
|
|
148
|
+
var sqlUpdate = {tableName: cleanCurrentModel.__entity.__name, arg: argu, primaryKey : primaryKey, primaryKeyValue : cleanCurrentModel[primaryKey] };
|
|
149
|
+
this._SQLEngine.update(sqlUpdate);
|
|
150
|
+
}
|
|
151
|
+
else{
|
|
152
|
+
console.log("Tracked entity modified with no values being changed");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// code block
|
|
156
|
+
break;
|
|
157
|
+
case "delete":
|
|
158
|
+
var deleteObject = new deleteManager(this._SQLEngine, this.__entities);
|
|
159
|
+
deleteObject.init(currentModel);
|
|
160
|
+
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
this.__clearErrorHandler();
|
|
165
|
+
this._SQLEngine.endTransaction();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
catch(error){
|
|
169
|
+
this.__clearErrorHandler();
|
|
170
|
+
this._SQLEngine.errorTransaction();
|
|
171
|
+
console.log("error", error);
|
|
172
|
+
this.__clearTracked();
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
this.__clearTracked();
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// TODO: WHY WE HAVE DOUBLE TRACKED OBJECTS - LOOP THROUGH ALL TRACKED OBJECTS
|
|
181
|
+
__track(model){
|
|
182
|
+
this.__trackedEntities.push(model);
|
|
183
|
+
return model;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
__findTracked(id){
|
|
187
|
+
if(id){
|
|
188
|
+
for (var model in this.__trackedEntities) {
|
|
189
|
+
if(this.__trackedEntities[model].__ID === id){
|
|
190
|
+
return this.__trackedEntities[model];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
__clearTracked(){
|
|
198
|
+
this.__trackedEntities = [];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
module.exports = Context;
|
|
204
|
+
|
|
205
|
+
/*
|
|
206
|
+
|
|
207
|
+
//Create new standard
|
|
208
|
+
var standard = new Standard();
|
|
209
|
+
standard.StandardName = "Standard1";
|
|
210
|
+
|
|
211
|
+
//create three new teachers
|
|
212
|
+
var teacher1 = new Teacher();
|
|
213
|
+
teacher1.TeacherName = "New Teacher1";
|
|
214
|
+
|
|
215
|
+
var teacher2 = new Teacher();
|
|
216
|
+
teacher2.TeacherName = "New Teacher2";
|
|
217
|
+
|
|
218
|
+
var teacher3 = new Teacher();
|
|
219
|
+
teacher3.TeacherName = "New Teacher3";
|
|
220
|
+
|
|
221
|
+
//add teachers for new standard
|
|
222
|
+
standard.Teachers.Add(teacher1);
|
|
223
|
+
standard.Teachers.Add(teacher2);
|
|
224
|
+
standard.Teachers.Add(teacher3);
|
|
225
|
+
|
|
226
|
+
using (var dbCtx = new SchoolDBEntities())
|
|
227
|
+
{
|
|
228
|
+
//add standard entity into standards entitySet
|
|
229
|
+
dbCtx.Standards.Add(standard);
|
|
230
|
+
//Save whole entity graph to the database
|
|
231
|
+
dbCtx.SaveChanges();
|
|
232
|
+
}
|
|
233
|
+
*/
|
package/Migrations/cli.js
CHANGED
|
@@ -1,106 +1,107 @@
|
|
|
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
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
.
|
|
47
|
-
.
|
|
48
|
-
.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
// we will
|
|
69
|
-
// the migrations
|
|
70
|
-
// the
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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 context 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
|
+
// Instructions : to run command you must go to folder where migration file is located.
|
|
45
|
+
program
|
|
46
|
+
.command('add-migration <name>')
|
|
47
|
+
.alias('am')
|
|
48
|
+
.description('Creates a new migration class')
|
|
49
|
+
.action(function(name){
|
|
50
|
+
|
|
51
|
+
try{
|
|
52
|
+
var contextSnapshot = fs.readFileSync(`./ContextSnapShot.json`, 'utf8');
|
|
53
|
+
var migration = new Migration();
|
|
54
|
+
var context = require(contextSnapshot.contextLocation);
|
|
55
|
+
var newEntity = migration.EDMModelDiffer(contextSnapshot.schema, context);
|
|
56
|
+
if(newEntity.length > 0){
|
|
57
|
+
var migrationDate = Date.now();
|
|
58
|
+
migration.migrationCodeGenerator(name, newEntity, migrationDate);
|
|
59
|
+
console.log(`migration ${name}_${migrationDate} created`);
|
|
60
|
+
}
|
|
61
|
+
}catch (e){
|
|
62
|
+
console.log("Cannot read or find file ", e);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// will use the database settings to call and get the schema_migration table
|
|
68
|
+
// we will get the list of all migrations that have been ran
|
|
69
|
+
// we will compare that list with the folder of migrations to see if we ran everything
|
|
70
|
+
// the migrations we missed we will call the up method
|
|
71
|
+
// the up method will run the create database functions
|
|
72
|
+
// then update the database.js schema
|
|
73
|
+
|
|
74
|
+
program
|
|
75
|
+
.command('update-database <databaseSettingLocation> <migrationFolderLocation> ')
|
|
76
|
+
.alias('ud')
|
|
77
|
+
.description('Apply pending migrations to database')
|
|
78
|
+
.action(function(cmd){
|
|
79
|
+
var dir = process.cwd();
|
|
80
|
+
console.log("starting server");
|
|
81
|
+
require(dir + '/server.js');
|
|
82
|
+
//return "node c:\node\server.js"
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// we will find the migration folder inside the nearest app folder if no migration folder is location is added
|
|
86
|
+
program
|
|
87
|
+
.command('remove-migration <name> <migrationFolderLocation>')
|
|
88
|
+
.alias('rm')
|
|
89
|
+
.description('Removes the last migration that has not been applied')
|
|
90
|
+
.action(function(name){
|
|
91
|
+
// find migration file using name and delete it.
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
// we will find the migration folder inside the nearest app folder if no migration folder is location is added
|
|
96
|
+
program
|
|
97
|
+
.command('revert-migration <name> <migrationFolderLocation>')
|
|
98
|
+
.alias('rm')
|
|
99
|
+
.description('Reverts back to the last migration with given name')
|
|
100
|
+
.action(function(cmd){
|
|
101
|
+
var dir = process.cwd();
|
|
102
|
+
console.log("starting server");
|
|
103
|
+
require(dir + '/server.js');
|
|
104
|
+
//return "node c:\node\server.js"
|
|
105
|
+
});
|
|
106
|
+
|
|
106
107
|
program.parse(process.argv);
|