Skip to content

Commit e26bb05

Browse files
committed
fix: Support SQlite
Move 'unique' constraint to another statement (SQLite don't support set unique when addColumn)
1 parent 6f14822 commit e26bb05

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

lib/migrations/20150702001020-update-to-0_3_1.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@ module.exports = {
33
up: function (queryInterface, Sequelize) {
44
return queryInterface.addColumn('Notes', 'shortid', {
55
type: Sequelize.STRING,
6-
unique: true,
6+
defaultValue: '0000000000',
77
allowNull: false
8+
}).then(function () {
9+
return queryInterface.addIndex('Notes', ['shortid'], {
10+
indicesType: 'UNIQUE'
11+
})
812
}).then(function () {
913
return queryInterface.addColumn('Notes', 'permission', {
1014
type: Sequelize.STRING,
11-
allowNull: false,
12-
defaultValue: 0
15+
defaultValue: 'private',
16+
allowNull: false
1317
})
1418
}).then(function () {
1519
return queryInterface.addColumn('Notes', 'viewcount', {
16-
type: Sequelize.INTEGER
20+
type: Sequelize.INTEGER,
21+
defaultValue: 0
1722
})
1823
})
1924
},
@@ -23,6 +28,9 @@ module.exports = {
2328
.then(function () {
2429
return queryInterface.removeColumn('Notes', 'permission')
2530
})
31+
.then(function () {
32+
return queryInterface.removeIndex('Notes', ['shortid'])
33+
})
2634
.then(function () {
2735
return queryInterface.removeColumn('Notes', 'shortid')
2836
})

lib/migrations/20150915153700-change-notes-title-to-text.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ module.exports = {
33
up: function (queryInterface, Sequelize) {
44
return queryInterface.changeColumn('Notes', 'title', {
55
type: Sequelize.TEXT
6+
}).then(function () {
7+
// manual added index will be removed in sqlite
8+
return queryInterface.addIndex('Notes', ['shortid'])
69
})
710
},
811

912
down: function (queryInterface, Sequelize) {
1013
return queryInterface.changeColumn('Notes', 'title', {
1114
type: Sequelize.STRING
15+
}).then(function () {
16+
return queryInterface.addIndex('Notes', ['shortid'])
1217
})
1318
}
1419
}

lib/migrations/20160420180355-note-add-alias.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
module.exports = {
33
up: function (queryInterface, Sequelize) {
44
return queryInterface.addColumn('Notes', 'alias', {
5-
type: Sequelize.STRING,
6-
unique: true
5+
type: Sequelize.STRING
6+
}).then(function () {
7+
return queryInterface.addIndex('Notes', ['alias'], {
8+
indicesType: 'UNIQUE'
9+
})
710
})
811
},
912

1013
down: function (queryInterface, Sequelize) {
11-
return queryInterface.removeColumn('Notes', 'alias')
14+
return queryInterface.removeColumn('Notes', 'alias').then(function () {
15+
return queryInterface.removeIndex('Notes', ['alias'])
16+
})
1217
}
1318
}

0 commit comments

Comments
 (0)