{"size": 3033, "ext": "js", "max_stars_repo_path": "models.js", "max_stars_repo_name": "gotojmp/xx-comic", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "models.js", "max_issues_repo_name": "gotojmp/xx-comic", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "models.js", "max_forks_repo_name": "gotojmp/xx-comic", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 37.4444444444, "max_line_length": 100, "alphanum_fraction": 0.6472139796}
'use strict';

var Sequelize = require('sequelize');
var DB = require('./db');

var Cat = DB.define('cat', {
    id: {type: Sequelize.INTEGER.UNSIGNED, allowNull: false, primaryKey: true, autoIncrement: true},
    name: {type: Sequelize.STRING(20), allowNull: false, defaultValue: ''}
}, {
    timestamps: false
});
var Book = DB.define('book', {
    id: {type: Sequelize.INTEGER.UNSIGNED, allowNull: false, primaryKey: true, autoIncrement: true},
    name: {type: Sequelize.STRING(50), allowNull: false, defaultValue: ''},
    author: {type: Sequelize.STRING(100), allowNull: false, defaultValue: ''},
    cat: {type: Sequelize.STRING(50), allowNull: false, defaultValue: ''},
    area: {type: Sequelize.STRING(50), allowNull: false, defaultValue: ''},
    cover: {type: Sequelize.STRING(100), allowNull: false, defaultValue: ''},
    desc: {type: Sequelize.TEXT, allowNull: false, defaultValue: ''},
    url: {type: Sequelize.STRING(100), allowNull: false, defaultValue: ''},
    finished: {type: Sequelize.BOOLEAN, allowNull: false, defaultValue: false},
    type: {type: Sequelize.INTEGER.UNSIGNED, allowNull: false, defaultValue: 0},
    status: {type: Sequelize.INTEGER.UNSIGNED, allowNull: false, defaultValue: 0}
}, {
    indexes: [{
        unique: false,
        fields: ['name']
    }, {
        unique: true,
        fields: ['url']
    }]
});
var Chapter = DB.define('chapter', {
    id: {type: Sequelize.INTEGER.UNSIGNED, allowNull: false, primaryKey: true, autoIncrement: true},
    sn: {type: Sequelize.INTEGER.UNSIGNED, allowNull: false, defaultValue: 1},
    num: {type: Sequelize.INTEGER.UNSIGNED, allowNull: false, defaultValue: 1},
    name: {type: Sequelize.STRING(50), allowNull: false, defaultValue: ''},
    title: {type: Sequelize.STRING(100), allowNull: false, defaultValue: ''},
    url: {type: Sequelize.STRING(100), allowNull: false, defaultValue: ''},
    status: {type: Sequelize.INTEGER.UNSIGNED, allowNull: false, defaultValue: 0}
}, {
    indexes: [{
        unique: true,
        fields: ['url']
    }, {
        unique: false,
        fields: ['book_id']
    }]
});
var Page = DB.define('page', {
    id: {type: Sequelize.INTEGER.UNSIGNED, allowNull: false, primaryKey: true, autoIncrement: true},
    num: {type: Sequelize.INTEGER.UNSIGNED, allowNull: false, defaultValue: 1},
    img: {type: Sequelize.STRING(100), allowNull: false, defaultValue: ''},
    url: {type: Sequelize.STRING(100), allowNull: false, defaultValue: ''},
    status: {type: Sequelize.INTEGER.UNSIGNED, allowNull: false, defaultValue: 0}
}, {
    indexes: [{
        unique: true,
        fields: ['url']
    }, {
        unique: false,
        fields: ['chapter_id']
    }]
});
Book.hasMany(Chapter);
Chapter.belongsTo(Book);

Chapter.hasMany(Page);
Page.belongsTo(Chapter);

// DB.sync().then(() => console.log('sync ok')).catch(err => console.log(err));

/**
 * @type {object}
 * @property {object} cat
 * @property {object} book
 * @property {object} chapter
 * @property {object} page
 */
module.exports = DB.models;
