Merge pull request #406 from hackmdio/feature/add_missing_migration

fix: Add missing migration
This commit is contained in:
Raccoon 2017-03-28 16:48:30 +08:00 committed by GitHub
commit 0b4dac74ed
8 changed files with 168 additions and 0 deletions

View file

@ -0,0 +1,24 @@
'use strict'
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.createTable('Users', {
id: {
type: Sequelize.UUID,
primaryKey: true,
defaultValue: Sequelize.UUIDV4
},
profileid: {
type: Sequelize.STRING,
unique: true
},
profile: Sequelize.TEXT,
history: Sequelize.TEXT,
createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE
})
},
down: function (queryInterface, Sequelize) {
return queryInterface.dropTable('Users')
}
}

View file

@ -0,0 +1,21 @@
'use strict'
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.createTable('Notes', {
id: {
type: Sequelize.UUID,
primaryKey: true,
defaultValue: Sequelize.UUIDV4
},
ownerId: Sequelize.UUID,
content: Sequelize.TEXT,
title: Sequelize.STRING,
createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE
})
},
down: function (queryInterface, Sequelize) {
return queryInterface.dropTable('Notes')
}
}

View file

@ -0,0 +1,18 @@
'use strict'
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.createTable('Temp', {
id: {
type: Sequelize.STRING,
primaryKey: true
},
date: Sequelize.TEXT,
createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE
})
},
down: function (queryInterface, Sequelize) {
return queryInterface.dropTable('Temp')
}
}

View file

@ -0,0 +1,38 @@
'use strict'
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.addColumn('Notes', 'shortid', {
type: Sequelize.STRING,
defaultValue: '0000000000',
allowNull: false
}).then(function () {
return queryInterface.addIndex('Notes', ['shortid'], {
indicesType: 'UNIQUE'
})
}).then(function () {
return queryInterface.addColumn('Notes', 'permission', {
type: Sequelize.STRING,
defaultValue: 'private',
allowNull: false
})
}).then(function () {
return queryInterface.addColumn('Notes', 'viewcount', {
type: Sequelize.INTEGER,
defaultValue: 0
})
})
},
down: function (queryInterface, Sequelize) {
return queryInterface.removeColumn('Notes', 'viewcount')
.then(function () {
return queryInterface.removeColumn('Notes', 'permission')
})
.then(function () {
return queryInterface.removeIndex('Notes', ['shortid'])
})
.then(function () {
return queryInterface.removeColumn('Notes', 'shortid')
})
}
}

View file

@ -0,0 +1,25 @@
'use strict'
const isSQLite = require('../utils').isSQLite
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.changeColumn('Notes', 'title', {
type: Sequelize.TEXT
}).then(function () {
if (isSQLite(queryInterface.sequelize)) {
// manual added index will be removed in sqlite
return queryInterface.addIndex('Notes', ['shortid'])
}
})
},
down: function (queryInterface, Sequelize) {
return queryInterface.changeColumn('Notes', 'title', {
type: Sequelize.STRING
}).then(function () {
if (isSQLite(queryInterface.sequelize)) {
// manual added index will be removed in sqlite
return queryInterface.addIndex('Notes', ['shortid'])
}
})
}
}

View file

@ -0,0 +1,19 @@
'use strict'
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.addColumn('Notes', 'lastchangeuserId', {
type: Sequelize.UUID
}).then(function () {
return queryInterface.addColumn('Notes', 'lastchangeAt', {
type: Sequelize.DATE
})
})
},
down: function (queryInterface, Sequelize) {
return queryInterface.removeColumn('Notes', 'lastchangeAt')
.then(function () {
return queryInterface.removeColumn('Notes', 'lastchangeuserId')
})
}
}

View file

@ -0,0 +1,18 @@
'use strict'
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.addColumn('Notes', 'alias', {
type: Sequelize.STRING
}).then(function () {
return queryInterface.addIndex('Notes', ['alias'], {
indicesType: 'UNIQUE'
})
})
},
down: function (queryInterface, Sequelize) {
return queryInterface.removeColumn('Notes', 'alias').then(function () {
return queryInterface.removeIndex('Notes', ['alias'])
})
}
}

5
lib/utils.js Normal file
View file

@ -0,0 +1,5 @@
'use strict'
exports.isSQLite = function isSQLite (sequelize) {
return sequelize.options.dialect === 'sqlite'
}