-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: typeorm, typeorm-naming-strategies, mysql2 설치 * chore: TypeORM 설정 * feat: 데이터 모델 정의 * chore: redis 연결 성공시 콘솔 메시지 추가 * chore: yarn install 정리 * chore: 모든 DB 스키마에 updateAt 필드 추가 * chore: 패키지 충돌 해결
- Loading branch information
1 parent
2f73e80
commit fe1a13e
Showing
43 changed files
with
949 additions
and
17 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+4.44 KB
.yarn/cache/parse5-htmlparser2-tree-adapter-npm-6.0.1-60b4888f75-1848378b35.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+3.34 KB
.yarn/cache/typeorm-naming-strategies-npm-4.1.0-9e060d6928-9654f38691.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
import 'dotenv/config'; | ||
import '@/configs/redis'; | ||
import app from '@/configs/express'; | ||
import AppDataSource from '@/configs/database'; | ||
import router from '@/routes'; | ||
import '@/configs/redis'; | ||
|
||
const PORT = process.env.PORT; | ||
|
||
app.use('/', router); | ||
|
||
AppDataSource.initialize() | ||
.then(() => console.log('Database connected!')) | ||
.catch((err) => console.log(err)); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Server is running in ${PORT} port.`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { DataSource } from 'typeorm'; | ||
import { SnakeNamingStrategy } from 'typeorm-naming-strategies'; | ||
import { User } from '@/models/User'; | ||
import { Post } from '@/models/Post'; | ||
import { Comment } from '@/models/Comment'; | ||
|
||
const AppDataSource = new DataSource({ | ||
type: 'mysql', | ||
port: 3306, | ||
host: process.env.NODE_ENV === 'production' ? process.env.DEPLOY_DB_HOST : 'localhost', | ||
username: process.env.NODE_ENV === 'production' ? process.env.DEPLOY_DB_USERNAME : process.env.LOCAL_DB_USERNAME, | ||
password: process.env.NODE_ENV === 'production' ? process.env.DEPLOY_DB_PASSWORD : process.env.LOCAL_DB_PASSWORD, | ||
database: process.env.DB_DATABASE, | ||
synchronize: true, | ||
// logging: true, | ||
entities: [User, Post, Comment], | ||
subscribers: [], | ||
migrations: [], | ||
namingStrategy: new SnakeNamingStrategy() | ||
}); | ||
|
||
export default AppDataSource; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm'; | ||
import { Post } from './Post'; | ||
|
||
@Entity() | ||
export class Comment { | ||
@PrimaryGeneratedColumn() | ||
id!: number; | ||
|
||
@Column({ length: 50 }) | ||
author!: string; | ||
|
||
@Column({ length: 500 }) | ||
content!: string; | ||
|
||
@Column({ length: 50 }) | ||
imageName!: string; | ||
|
||
@Column() | ||
positionX!: number; | ||
|
||
@Column() | ||
positionY!: number; | ||
|
||
@Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) | ||
createdAt!: Date; | ||
|
||
@Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) | ||
updatedAt!: Date; | ||
|
||
@ManyToOne(() => Post, (post) => post.comments, { | ||
cascade: true | ||
}) | ||
post!: Post; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne } from 'typeorm'; | ||
import { User } from './User'; | ||
import { Comment } from './Comment'; | ||
|
||
@Entity() | ||
export class Post { | ||
@PrimaryGeneratedColumn() | ||
id!: number; | ||
|
||
@Column({ length: 50 }) | ||
title!: string; | ||
|
||
@Column({ length: 500 }) | ||
content!: string; | ||
|
||
@Column({ length: 50, nullable: true }) | ||
imageName!: string; | ||
|
||
@Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) | ||
createdAt!: Date; | ||
|
||
@Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) | ||
updatedAt!: Date; | ||
|
||
@ManyToOne(() => User, (user) => user.posts, { | ||
cascade: true | ||
}) | ||
author!: User; | ||
|
||
@OneToMany(() => Comment, (comment) => comment.id) | ||
comments!: Comment[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from 'typeorm'; | ||
import { Post } from './Post'; | ||
|
||
@Entity() | ||
export class User { | ||
@PrimaryGeneratedColumn() | ||
id!: number; | ||
|
||
@Column({ length: 50, unique: true }) | ||
username!: string; | ||
|
||
@Column() | ||
password!: string; | ||
|
||
@Column() | ||
salt!: string; | ||
|
||
@Column({ length: 20 }) | ||
role!: string; | ||
|
||
@Column({ length: 20 }) | ||
name!: string; | ||
|
||
@Column() | ||
introduce!: string; | ||
|
||
@Column({ length: 50 }) | ||
imageName!: string; | ||
|
||
@Column({ length: 50 }) | ||
slackId!: string; | ||
|
||
@Column({ length: 20 }) | ||
slackWorkspace!: string; | ||
|
||
@Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) | ||
createdAt!: Date; | ||
|
||
@Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) | ||
updatedAt!: Date; | ||
|
||
@OneToMany(() => Post, (post) => post.author) | ||
posts!: Post[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.