index.js 1.57 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
import { Sequelize } from "sequelize";
2
3
import UserModel from "../models/user.model.js";
import RoleModel from "../models/role.model.js";
Kim, Subin's avatar
Model    
Kim, Subin committed
4
import MovieModel from "../models/movie.model.js";
Kim, Subin's avatar
Kim, Subin committed
5
import CinemaModel from "../models/cinema.model.js";
Kim, Subin's avatar
Kim, Subin committed
6
import TheaterModel from "../models/theater.model.js";
Kim, Subin's avatar
theater    
Kim, Subin committed
7
import TheaterTypeModel from "../models/theatertype.model.js";
Kim, Subin's avatar
Kim, Subin committed
8
import TicketFeeModel from "../models/ticketfee.model.js";
Jiwon Yoon's avatar
Jiwon Yoon committed
9
10
import TimeTableModel from '../models/role.model.js';
import ReservationModel from '../models/reservation.model.js';
Kim, Subin's avatar
Kim, Subin committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import dbConfig from "../config/db.config.js";

const sequelize = new Sequelize(
    String(dbConfig.database),
    String(dbConfig.username),
    dbConfig.password,
    {
        host: dbConfig.host,
        dialect: dbConfig.dialect,
        pool: {
            max: dbConfig.pool?.max,
            min: dbConfig.pool?.min,
            acquire: dbConfig.pool?.acquire,
            idle: dbConfig.pool?.idle,
        },
    }
);

29
30
const User = UserModel(sequelize)
const Role = RoleModel(sequelize)
Kim, Subin's avatar
Model    
Kim, Subin committed
31
const Movie = MovieModel(sequelize)
Kim, Subin's avatar
Kim, Subin committed
32
const Cinema = CinemaModel(sequelize)
Kim, Subin's avatar
Kim, Subin committed
33
const Theater = TheaterModel(sequelize)
Kim, Subin's avatar
theater    
Kim, Subin committed
34
const TheaterType = TheaterTypeModel(sequelize)
Kim, Subin's avatar
Kim, Subin committed
35
const TicketFee = TicketFeeModel(sequelize)
Jiwon Yoon's avatar
Jiwon Yoon committed
36
37
const TimeTable = TimeTableModel(sequelize)
const Reservation = ReservationModel(sequelize)
Kim, Subin's avatar
Model    
Kim, Subin committed
38

39
40
41
User.belongsTo(Role);
Role.hasOne(User);

Kim, Subin's avatar
theater    
Kim, Subin committed
42
43
44
Theater.belongsTo(TheaterType);

TicketFee.belongsTo(TheaterType, { onDelete: 'CASCADE' });
한규민's avatar
한규민 committed
45

Kim, Subin's avatar
Kim, Subin committed
46
47
export {
    sequelize,
48
49
    User,
    Role,
Kim, Subin's avatar
Kim, Subin committed
50
    Movie,
Kim, Subin's avatar
Kim, Subin committed
51
    Cinema,
Jiwon Yoon's avatar
Jiwon Yoon committed
52
    Theater,
Kim, Subin's avatar
theater    
Kim, Subin committed
53
    TheaterType,
Kim, Subin's avatar
Kim, Subin committed
54
    TicketFee,
Jiwon Yoon's avatar
Jiwon Yoon committed
55
56
    TimeTable,
    Reservation
Kim, Subin's avatar
Kim, Subin committed
57
}