정민우

[New] Docker Model들 추가

1 const bcrypt = require('bcrypt') 1 const bcrypt = require('bcrypt')
2 2
3 -const { sequelize, Sequelize, User, Group} = require('../models') 3 +const { sequelize, Sequelize, User} = require('../models')
4 const { sendResponse, sendError } = require('../utils/response') 4 const { sendResponse, sendError } = require('../utils/response')
5 const { logging } = require('../utils/log') 5 const { logging } = require('../utils/log')
6 const { checkRequiredExist, setValues } = require('../utils/validation') 6 const { checkRequiredExist, setValues } = require('../utils/validation')
......
1 +'use strict';
2 +module.exports = {
3 + up: async (queryInterface, Sequelize) => {
4 + await queryInterface.createTable('Dockerfiles', {
5 + id: {
6 + autoIncrement: true,
7 + primaryKey: true,
8 + type: Sequelize.INTEGER
9 + },
10 + userId: {
11 + allowNull: false,
12 + type: Sequelize.INTEGER
13 + },
14 + filepath: {
15 + allowNull: false,
16 + type: Sequelize.STRING,
17 + },
18 + content: {
19 + allowNull: false,
20 + type: Sequelize.TEXT('long'),
21 + },
22 + createdAt: {
23 + allowNull: false,
24 + type: Sequelize.DATE
25 + },
26 + updatedAt: {
27 + allowNull: false,
28 + type: Sequelize.DATE
29 + }
30 + },{
31 + charset: 'utf8mb4',
32 + collate: 'utf8mb4_unicode_ci'
33 + })
34 + },
35 + down: async (queryInterface, Sequelize) => {
36 + await queryInterface.dropTable('Dockerfiles');
37 + }
38 +};
1 +'use strict';
2 +module.exports = {
3 + up: async (queryInterface, Sequelize) => {
4 + await queryInterface.createTable('Images', {
5 + id: {
6 + autoIncrement: true,
7 + primaryKey: true,
8 + type: Sequelize.INTEGER
9 + },
10 + dockerfileId: {
11 + allowNull: false,
12 + type: Sequelize.INTEGER,
13 + onDelete: 'CASCADE',
14 + references: {
15 + model: 'Dockerfiles',
16 + key: 'id'
17 + }
18 + },
19 + name: {
20 + allowNull: false,
21 + type: Sequelize.STRING(255),
22 + },
23 + createdAt: {
24 + allowNull: false,
25 + type: Sequelize.DATE
26 + },
27 + updatedAt: {
28 + allowNull: false,
29 + type: Sequelize.DATE
30 + }
31 + },{
32 + charset: 'utf8mb4',
33 + collate: 'utf8mb4_unicode_ci'
34 + })
35 + },
36 + down: async (queryInterface, Sequelize) => {
37 + await queryInterface.dropTable('Images');
38 + }
39 +};
1 +'use strict';
2 +module.exports = {
3 + up: async (queryInterface, Sequelize) => {
4 + await queryInterface.createTable('Containers', {
5 + id: {
6 + autoIncrement: true,
7 + primaryKey: true,
8 + type: Sequelize.INTEGER
9 + },
10 + imageId: {
11 + allowNull: false,
12 + type: Sequelize.INTEGER,
13 + onDelete: 'CASCADE',
14 + references: {
15 + model: 'Images',
16 + key: 'id'
17 + }
18 + },
19 + name: {
20 + allowNull: false,
21 + type: Sequelize.STRING(255),
22 + },
23 + command: {
24 + type: Sequelize.TEXT('long')
25 + },
26 + description: {
27 + type: Sequelize.TEXT('long')
28 + },
29 + createdAt: {
30 + allowNull: false,
31 + type: Sequelize.DATE
32 + },
33 + updatedAt: {
34 + allowNull: false,
35 + type: Sequelize.DATE
36 + }
37 + },{
38 + charset: 'utf8mb4',
39 + collate: 'utf8mb4_unicode_ci'
40 + })
41 + },
42 + down: async (queryInterface, Sequelize) => {
43 + await queryInterface.dropTable('Containers');
44 + }
45 +};
1 +'use strict';
2 +module.exports = {
3 + up: async (queryInterface, Sequelize) => {
4 + await queryInterface.createTable('Ports', {
5 + id: {
6 + autoIncrement: true,
7 + primaryKey: true,
8 + type: Sequelize.INTEGER
9 + },
10 + ContainerId: {
11 + allowNull: false,
12 + type: Sequelize.INTEGER,
13 + onDelete: 'CASCADE',
14 + references: {
15 + model: 'Containers',
16 + key: 'id'
17 + }
18 + },
19 + innerPort: {
20 + allowNull: false,
21 + type: Sequelize.INTEGER
22 + },
23 + outerPort: {
24 + allowNull: false,
25 + type: Sequelize.INTEGER
26 + },
27 + description: {
28 + type: Sequelize.TEXT('long')
29 + },
30 + createdAt: {
31 + allowNull: false,
32 + type: Sequelize.DATE
33 + },
34 + updatedAt: {
35 + allowNull: false,
36 + type: Sequelize.DATE
37 + }
38 + },{
39 + charset: 'utf8mb4',
40 + collate: 'utf8mb4_unicode_ci'
41 + })
42 + },
43 + down: async (queryInterface, Sequelize) => {
44 + await queryInterface.dropTable('Ports');
45 + }
46 +};
1 +'use strict'
2 +const { Model } = require('sequelize')
3 +
4 +module.exports = (sequelize, DataTypes) => {
5 + class Container extends Model {
6 + static associate(models) {
7 + this.belongsTo(models.Image, {
8 + foreignKey: "imageId",
9 + onDelete: 'CASCADE'
10 + })
11 + this.hasMany(models.Port)
12 + }
13 + }
14 + Container.init({
15 + id: {
16 + type: DataTypes.INTEGER,
17 + primaryKey: true,
18 + autoIncrement: true
19 + },
20 + imageId: {
21 + allowNull: false,
22 + type: DataTypes.INTEGER
23 + },
24 + name: {
25 + allowNull: false,
26 + type: DataTypes.STRING(255)
27 + },
28 + command: {
29 + type: DataTypes.TEXT('long')
30 + },
31 + description: {
32 + type: DataTypes.TEXT('long')
33 + }
34 + }, {
35 + sequelize,
36 + modelName: 'Container'
37 + })
38 + return Container
39 +}
1 +'use strict'
2 +const { Model } = require('sequelize')
3 +
4 +module.exports = (sequelize, DataTypes) => {
5 + class Dockerfile extends Model {
6 + static associate(models) {
7 + this.belongsTo(models.User, {
8 + foreignKey: "userId"
9 + })
10 + this.hasMany(models.Image)
11 + }
12 + }
13 + Dockerfile.init({
14 + id: {
15 + type: DataTypes.INTEGER,
16 + primaryKey: true,
17 + autoIncrement: true
18 + },
19 + userId: {
20 + allowNull: false,
21 + type: DataTypes.INTEGER
22 + },
23 + filepath: {
24 + allowNull: false,
25 + type: DataTypes.STRING
26 + },
27 + content: {
28 + allowNull: false,
29 + type: DataTypes.TEXT('long')
30 + }
31 + }, {
32 + sequelize,
33 + modelName: 'Dockerfile'
34 + })
35 + return Dockerfile
36 +}
1 +'use strict'
2 +const { Model } = require('sequelize')
3 +
4 +module.exports = (sequelize, DataTypes) => {
5 + class Image extends Model {
6 + static associate(models) {
7 + this.belongsTo(models.Dockerfile, {
8 + foreignKey: "dockerfileId",
9 + onDelete: 'CASCADE'
10 + })
11 + this.hasMany(models.Container)
12 + }
13 + }
14 + Image.init({
15 + id: {
16 + type: DataTypes.INTEGER,
17 + primaryKey: true,
18 + autoIncrement: true
19 + },
20 + dockerfileId: {
21 + allowNull: false,
22 + type: DataTypes.INTEGER
23 + },
24 + name: {
25 + allowNull: false,
26 + type: DataTypes.STRING(255)
27 + }
28 + }, {
29 + sequelize,
30 + modelName: 'Image'
31 + })
32 + return Image
33 +}
1 'use strict' 1 'use strict'
2 -const { sequelize } = require('.')
3 const { Model } = require('sequelize') 2 const { Model } = require('sequelize')
4 module.exports = (sequelize, DataTypes) => { 3 module.exports = (sequelize, DataTypes) => {
5 class Log extends Model {} 4 class Log extends Model {}
......
1 +'use strict'
2 +const { Model } = require('sequelize')
3 +
4 +module.exports = (sequelize, DataTypes) => {
5 + class Port extends Model {
6 + static associate(models) {
7 + this.belongsTo(models.Container, {
8 + foreignKey: "ContainerId",
9 + onDelete: 'CASCADE'
10 + })
11 + }
12 + }
13 + Port.init({
14 + id: {
15 + type: DataTypes.INTEGER,
16 + primaryKey: true,
17 + autoIncrement: true
18 + },
19 + ContainerId: {
20 + allowNull: false,
21 + type: DataTypes.INTEGER
22 + },
23 + innerPort: {
24 + allowNull: false,
25 + type: DataTypes.INTEGER
26 + },
27 + outerPort: {
28 + allowNull: false,
29 + type: DataTypes.INTEGER
30 + },
31 + description: {
32 + type: DataTypes.TEXT('long')
33 + }
34 + }, {
35 + sequelize,
36 + modelName: 'Port'
37 + })
38 + return Port
39 +}
1 'use strict' 1 'use strict'
2 -const { sequelize } = require('.')
3 const { Model } = require('sequelize') 2 const { Model } = require('sequelize')
4 module.exports = (sequelize, DataTypes) => { 3 module.exports = (sequelize, DataTypes) => {
5 - class User extends Model { } 4 + class User extends Model {
5 + static associate(models) {
6 + this.hasMany(models.Dockerfile)
7 + }
8 + }
6 9
7 User.init({ 10 User.init({
8 id: { 11 id: {
...@@ -36,6 +39,5 @@ module.exports = (sequelize, DataTypes) => { ...@@ -36,6 +39,5 @@ module.exports = (sequelize, DataTypes) => {
36 paranoid: true, 39 paranoid: true,
37 modelName: 'User' 40 modelName: 'User'
38 }) 41 })
39 -
40 return User 42 return User
41 } 43 }
......