image.js 786 Bytes
'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
}