diff --git a/db/migrations/02_resource-access.js b/db/migrations/02_resource-access.js new file mode 100644 index 0000000..717ac38 --- /dev/null +++ b/db/migrations/02_resource-access.js @@ -0,0 +1,27 @@ +const { DataTypes } = require('sequelize'); +const { INTEGER } = DataTypes; + +const tables = ['categories', 'bookmarks', 'apps']; + +const up = async (query) => { + const template = { + type: INTEGER, + allowNull: true, + defaultValue: 0, + }; + + for await (let table of tables) { + await query.addColumn(table, 'isPublic', template); + } +}; + +const down = async (query) => { + for await (let table of tables) { + await query.removeColumn(table, 'isPublic'); + } +}; + +module.exports = { + up, + down, +}; diff --git a/models/App.js b/models/App.js index f521955..c71d350 100644 --- a/models/App.js +++ b/models/App.js @@ -1,31 +1,40 @@ const { DataTypes } = require('sequelize'); const { sequelize } = require('../db'); -const App = sequelize.define('App', { - name: { - type: DataTypes.STRING, - allowNull: false +const App = sequelize.define( + 'App', + { + name: { + type: DataTypes.STRING, + allowNull: false, + }, + url: { + type: DataTypes.STRING, + allowNull: false, + }, + icon: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: 'cancel', + }, + isPinned: { + type: DataTypes.BOOLEAN, + defaultValue: false, + }, + orderId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + }, + isPublic: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: 0, + }, }, - url: { - type: DataTypes.STRING, - allowNull: false - }, - icon: { - type: DataTypes.STRING, - allowNull: false, - defaultValue: 'cancel' - }, - isPinned: { - type: DataTypes.BOOLEAN, - defaultValue: false - }, - orderId: { - type: DataTypes.INTEGER, - allowNull: true, - defaultValue: null + { + tableName: 'apps', } -}, { - tableName: 'apps' -}); +); -module.exports = App; \ No newline at end of file +module.exports = App; diff --git a/models/Bookmark.js b/models/Bookmark.js index 6c7d27b..652c119 100644 --- a/models/Bookmark.js +++ b/models/Bookmark.js @@ -1,25 +1,34 @@ const { DataTypes } = require('sequelize'); const { sequelize } = require('../db'); -const Bookmark = sequelize.define('Bookmark', { - name: { - type: DataTypes.STRING, - allowNull: false +const Bookmark = sequelize.define( + 'Bookmark', + { + name: { + type: DataTypes.STRING, + allowNull: false, + }, + url: { + type: DataTypes.STRING, + allowNull: false, + }, + categoryId: { + type: DataTypes.INTEGER, + allowNull: false, + }, + icon: { + type: DataTypes.STRING, + defaultValue: '', + }, + isPublic: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: 0, + }, }, - url: { - type: DataTypes.STRING, - allowNull: false - }, - categoryId: { - type: DataTypes.INTEGER, - allowNull: false - }, - icon: { - type: DataTypes.STRING, - defaultValue: '' + { + tableName: 'bookmarks', } -}, { - tableName: 'bookmarks' -}); +); -module.exports = Bookmark; \ No newline at end of file +module.exports = Bookmark; diff --git a/models/Category.js b/models/Category.js index 9c9eda6..582a6c2 100644 --- a/models/Category.js +++ b/models/Category.js @@ -1,22 +1,31 @@ const { DataTypes } = require('sequelize'); const { sequelize } = require('../db'); -const Category = sequelize.define('Category', { - name: { - type: DataTypes.STRING, - allowNull: false +const Category = sequelize.define( + 'Category', + { + name: { + type: DataTypes.STRING, + allowNull: false, + }, + isPinned: { + type: DataTypes.BOOLEAN, + defaultValue: false, + }, + orderId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + }, + isPublic: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: 0, + }, }, - isPinned: { - type: DataTypes.BOOLEAN, - defaultValue: false - }, - orderId: { - type: DataTypes.INTEGER, - allowNull: true, - defaultValue: null + { + tableName: 'categories', } -}, { - tableName: 'categories' -}); +); -module.exports = Category; \ No newline at end of file +module.exports = Category;