Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Commit bca678a

Browse files
committed
support for field name
1 parent 2498871 commit bca678a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

example/models/account.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = function (DB, { INTEGER, BIGINT, DATE, STRING, ENUM, BOOLEAN, D
55
{
66
id: { type: INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
77
test_param: { type: BIGINT, allowNull: false, defaultValue: 1000 },
8-
first_name: { type: STRING, allowNull: false, defaultValue: '' },
8+
first_name: { type: STRING, allowNull: true, defaultValue: 'abc', field: 'first-name' },
99
last_name: { type: STRING, allowNull: false, defaultValue: '' },
1010
nickname: { type: STRING, allowNull: false, defaultValue: '' },
1111
gender: { type: ENUM, allowNull: false, values: ['male', 'female', 'unknown'], defaultValue: 'unknown' },

lib/migrate.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ const reverseModels = function(sequelize, models)
177177
{
178178
delete attributes[column].Model;
179179
delete attributes[column].fieldName;
180-
delete attributes[column].field;
180+
// delete attributes[column].field;
181181

182182
for(let property in attributes[column])
183183
{
@@ -400,7 +400,8 @@ const parseDifference = function(previousState, currentState)
400400
actionType: 'removeColumn',
401401
tableName: tableName,
402402
columnName: df.path[2],
403-
depends: [ tableName ]
403+
depends: [ tableName ],
404+
options: df.lhs
404405
});
405406
break;
406407
}
@@ -633,7 +634,7 @@ let resUp =`{ fn: "createTable", params: [
633634
{
634635
let resUp = `{ fn: "addColumn", params: [
635636
"${action.tableName}",
636-
"${action.attributeName}",
637+
"${(action.options && action.options.field) ? action.options.field : action.attributeName}",
637638
${propertyToStr(action.options)}
638639
] }`;
639640

@@ -645,18 +646,18 @@ let resUp = `{ fn: "addColumn", params: [
645646

646647
case 'removeColumn':
647648
{
648-
let res = `{ fn: "removeColumn", params: ["${action.tableName}", "${action.columnName}"] }`;
649+
let res = `{ fn: "removeColumn", params: ["${action.tableName}", "${(action.options && action.options.field) ? action.options.field : action.columnName}"] }`;
649650
commandsUp.push(res);
650651

651-
consoleOut.push(`removeColumn "${action.columnName}" from table "${action.tableName}"`);
652+
consoleOut.push(`removeColumn "${(action.options && action.options.field) ? action.options.field : action.columnName}" from table "${action.tableName}"`);
652653
}
653654
break;
654655

655656
case 'changeColumn':
656657
{
657658
let res = `{ fn: "changeColumn", params: [
658659
"${action.tableName}",
659-
"${action.attributeName}",
660+
"${(action.options && action.options.field) ? action.options.field : action.attributeName}",
660661
${propertyToStr(action.options)}
661662
] }`;
662663
commandsUp.push(res);

0 commit comments

Comments
 (0)