-
Notifications
You must be signed in to change notification settings - Fork 0
/
migration-recorder.js
70 lines (60 loc) · 1.78 KB
/
migration-recorder.js
1
2
3
4
5
6
7
8
9
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
const { SequelizeRecorder } = require('./sequelize-recorder');
class MigrationRecorder {
constructor() {
this.changes = [];
this.sequelize = new SequelizeRecorder(this.changes);
}
addIndex(tableName, columns) {
this.changes.push(
`Added an index on columns "${columns}" to table "${tableName}"`,
);
return Promise.resolve();
}
removeColumn(tableName, columnName) {
this.changes.push(
`Removed column "${columnName}" from table "${tableName}"`,
);
return Promise.resolve();
}
renameColumn(tableName, oldColumnName, newColumnName) {
this.changes.push(
`Renamed column "${oldColumnName}" to "${newColumnName}" in table "${tableName}"`,
);
return Promise.resolve();
}
addColumn(tableName, columnName) {
this.changes.push(`Added column "${columnName}" to table "${tableName}"`);
return Promise.resolve();
}
changeColumn(tableName, columnName) {
this.changes.push(`Changed column "${columnName}" in table "${tableName}"`);
return Promise.resolve();
}
createTable(tableName, columns) {
const columnList = Object.values(columns)
.map((col) => {
const item = `<li>Name: ${col.field}, Type: ${col.type}</li>`;
return item;
})
.join('');
this.changes.push(
`Added table "${tableName}" with columns: <ul>${columnList}</ul>`,
);
return Promise.resolve();
}
addConstraint(tableName, columns) {
this.changes.push(
`Added constraint to columns "${columns}" in table "${tableName}"`,
);
return Promise.resolve();
}
removeConstraint(tableName, constraintName) {
this.changes.push(
`Removed constraint "${constraintName}" from table "${tableName}"`,
);
return Promise.resolve();
}
}
module.exports = {
MigrationRecorder,
};