Modified models to support resource visibility. Added migration

This commit is contained in:
Paweł Malak 2021-11-08 23:39:42 +01:00
parent 08afaece2e
commit ee9aefa4fa
4 changed files with 114 additions and 60 deletions

View file

@ -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,
};

View file

@ -1,31 +1,40 @@
const { DataTypes } = require('sequelize'); const { DataTypes } = require('sequelize');
const { sequelize } = require('../db'); const { sequelize } = require('../db');
const App = sequelize.define('App', { const App = sequelize.define(
name: { 'App',
type: DataTypes.STRING, {
allowNull: false 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, tableName: 'apps',
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'
});
module.exports = App; module.exports = App;

View file

@ -1,25 +1,34 @@
const { DataTypes } = require('sequelize'); const { DataTypes } = require('sequelize');
const { sequelize } = require('../db'); const { sequelize } = require('../db');
const Bookmark = sequelize.define('Bookmark', { const Bookmark = sequelize.define(
name: { 'Bookmark',
type: DataTypes.STRING, {
allowNull: false 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, tableName: 'bookmarks',
allowNull: false
},
categoryId: {
type: DataTypes.INTEGER,
allowNull: false
},
icon: {
type: DataTypes.STRING,
defaultValue: ''
} }
}, { );
tableName: 'bookmarks'
});
module.exports = Bookmark; module.exports = Bookmark;

View file

@ -1,22 +1,31 @@
const { DataTypes } = require('sequelize'); const { DataTypes } = require('sequelize');
const { sequelize } = require('../db'); const { sequelize } = require('../db');
const Category = sequelize.define('Category', { const Category = sequelize.define(
name: { 'Category',
type: DataTypes.STRING, {
allowNull: false 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, tableName: 'categories',
defaultValue: false
},
orderId: {
type: DataTypes.INTEGER,
allowNull: true,
defaultValue: null
} }
}, { );
tableName: 'categories'
});
module.exports = Category; module.exports = Category;