index.js 1.46 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
Kim, Subin committed
7
import TicketFeeModel from "../models/ticketfee.model.js";
Jiwon Yoon's avatar
Jiwon Yoon committed
8
9
import TimeTableModel from '../models/role.model.js';
import ReservationModel from '../models/reservation.model.js';
Kim, Subin's avatar
Kim, Subin committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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,
        },
    }
);

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

37
38
39
User.belongsTo(Role);
Role.hasOne(User);

Kim, Subin's avatar
Kim, Subin committed
40
TicketFee.hasOne(Theater, { foreignKey: "theaterType", targetKey: "theaterType", onDelete : "Cascade" });
한규민's avatar
한규민 committed
41

Kim, Subin's avatar
Kim, Subin committed
42
43
export {
    sequelize,
44
45
    User,
    Role,
Kim, Subin's avatar
Kim, Subin committed
46
    Movie,
Kim, Subin's avatar
Kim, Subin committed
47
    Cinema,
Jiwon Yoon's avatar
Jiwon Yoon committed
48
    Theater,
Kim, Subin's avatar
Kim, Subin committed
49
    TicketFee,
Jiwon Yoon's avatar
Jiwon Yoon committed
50
51
    TimeTable,
    Reservation
Kim, Subin's avatar
Kim, Subin committed
52
}