정민우

Merge branch 'backend' into 'master'

[New] Docker Model들 추가



See merge request !4
const bcrypt = require('bcrypt')
const { sequelize, Sequelize, User, Group} = require('../models')
const { sequelize, Sequelize, User} = require('../models')
const { sendResponse, sendError } = require('../utils/response')
const { logging } = require('../utils/log')
const { checkRequiredExist, setValues } = require('../utils/validation')
......
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('Dockerfiles', {
id: {
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
userId: {
allowNull: false,
type: Sequelize.INTEGER
},
filepath: {
allowNull: false,
type: Sequelize.STRING,
},
content: {
allowNull: false,
type: Sequelize.TEXT('long'),
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
},{
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci'
})
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Dockerfiles');
}
};
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('Images', {
id: {
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
dockerfileId: {
allowNull: false,
type: Sequelize.INTEGER,
onDelete: 'CASCADE',
references: {
model: 'Dockerfiles',
key: 'id'
}
},
name: {
allowNull: false,
type: Sequelize.STRING(255),
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
},{
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci'
})
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Images');
}
};
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('Containers', {
id: {
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
imageId: {
allowNull: false,
type: Sequelize.INTEGER,
onDelete: 'CASCADE',
references: {
model: 'Images',
key: 'id'
}
},
name: {
allowNull: false,
type: Sequelize.STRING(255),
},
command: {
type: Sequelize.TEXT('long')
},
description: {
type: Sequelize.TEXT('long')
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
},{
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci'
})
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Containers');
}
};
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('Ports', {
id: {
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
ContainerId: {
allowNull: false,
type: Sequelize.INTEGER,
onDelete: 'CASCADE',
references: {
model: 'Containers',
key: 'id'
}
},
innerPort: {
allowNull: false,
type: Sequelize.INTEGER
},
outerPort: {
allowNull: false,
type: Sequelize.INTEGER
},
description: {
type: Sequelize.TEXT('long')
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
},{
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci'
})
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Ports');
}
};
'use strict'
const { Model } = require('sequelize')
module.exports = (sequelize, DataTypes) => {
class Container extends Model {
static associate(models) {
this.belongsTo(models.Image, {
foreignKey: "imageId",
onDelete: 'CASCADE'
})
this.hasMany(models.Port)
}
}
Container.init({
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
imageId: {
allowNull: false,
type: DataTypes.INTEGER
},
name: {
allowNull: false,
type: DataTypes.STRING(255)
},
command: {
type: DataTypes.TEXT('long')
},
description: {
type: DataTypes.TEXT('long')
}
}, {
sequelize,
modelName: 'Container'
})
return Container
}
'use strict'
const { Model } = require('sequelize')
module.exports = (sequelize, DataTypes) => {
class Dockerfile extends Model {
static associate(models) {
this.belongsTo(models.User, {
foreignKey: "userId"
})
this.hasMany(models.Image)
}
}
Dockerfile.init({
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
userId: {
allowNull: false,
type: DataTypes.INTEGER
},
filepath: {
allowNull: false,
type: DataTypes.STRING
},
content: {
allowNull: false,
type: DataTypes.TEXT('long')
}
}, {
sequelize,
modelName: 'Dockerfile'
})
return Dockerfile
}
'use strict'
const { Model } = require('sequelize')
module.exports = (sequelize, DataTypes) => {
class Image extends Model {
static associate(models) {
this.belongsTo(models.Dockerfile, {
foreignKey: "dockerfileId",
onDelete: 'CASCADE'
})
this.hasMany(models.Container)
}
}
Image.init({
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
dockerfileId: {
allowNull: false,
type: DataTypes.INTEGER
},
name: {
allowNull: false,
type: DataTypes.STRING(255)
}
}, {
sequelize,
modelName: 'Image'
})
return Image
}
'use strict'
const { sequelize } = require('.')
const { Model } = require('sequelize')
module.exports = (sequelize, DataTypes) => {
class Log extends Model {}
......
'use strict'
const { Model } = require('sequelize')
module.exports = (sequelize, DataTypes) => {
class Port extends Model {
static associate(models) {
this.belongsTo(models.Container, {
foreignKey: "ContainerId",
onDelete: 'CASCADE'
})
}
}
Port.init({
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
ContainerId: {
allowNull: false,
type: DataTypes.INTEGER
},
innerPort: {
allowNull: false,
type: DataTypes.INTEGER
},
outerPort: {
allowNull: false,
type: DataTypes.INTEGER
},
description: {
type: DataTypes.TEXT('long')
}
}, {
sequelize,
modelName: 'Port'
})
return Port
}
'use strict'
const { sequelize } = require('.')
const { Model } = require('sequelize')
module.exports = (sequelize, DataTypes) => {
class User extends Model { }
class User extends Model {
static associate(models) {
this.hasMany(models.Dockerfile)
}
}
User.init({
id: {
......@@ -36,6 +39,5 @@ module.exports = (sequelize, DataTypes) => {
paranoid: true,
modelName: 'User'
})
return User
}
......