From 77a0b280668c415116d414bb2d3f303055ba8496 Mon Sep 17 00:00:00 2001 From: thanhbao922003 Date: Mon, 7 Oct 2024 15:31:46 +0700 Subject: [PATCH] Setup Database --- .gitignore | 2 - env/development.env.example | 2 +- eslint.config.mjs | 2 +- package.json | 6 +- src/entity/Comment.ts | 38 ++++++++++++ src/entity/Component.ts | 38 ++++++++++++ src/entity/Course.ts | 44 ++++++++++++++ src/entity/Enrollment.ts | 49 ++++++++++++++++ src/entity/EnrollmentLesson.ts | 46 +++++++++++++++ src/entity/Lesson.ts | 41 +++++++++++++ src/entity/Payment.ts | 52 +++++++++++++++++ src/entity/Review.ts | 43 ++++++++++++++ src/entity/Section.ts | 41 +++++++++++++ src/entity/User.ts | 38 ++++++++++++ src/index.ts | 2 +- .../1728392492258-first_migration.ts | 58 +++++++++++++++++++ tsconfig.json | 2 +- 17 files changed, 497 insertions(+), 7 deletions(-) create mode 100644 src/entity/Comment.ts create mode 100644 src/entity/Component.ts create mode 100644 src/entity/Course.ts create mode 100644 src/entity/Enrollment.ts create mode 100644 src/entity/EnrollmentLesson.ts create mode 100644 src/entity/Lesson.ts create mode 100644 src/entity/Payment.ts create mode 100644 src/entity/Review.ts create mode 100644 src/entity/Section.ts create mode 100644 src/entity/User.ts create mode 100644 src/migration/1728392492258-first_migration.ts diff --git a/.gitignore b/.gitignore index db0883a6..4f788c1f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ -node_modules/ dist/ **/**/*.log env/*.env -src/migration/*.ts # Logs logs diff --git a/env/development.env.example b/env/development.env.example index e50b1d1e..90935c5b 100644 --- a/env/development.env.example +++ b/env/development.env.example @@ -3,4 +3,4 @@ DB_HOST='' DB_PORT='' DB_USERNAME='' DB_PASSWORD='' -DB_DATABASE='' \ No newline at end of file +DB_DATABASE='' diff --git a/eslint.config.mjs b/eslint.config.mjs index f1cc6793..4367d9ed 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -32,7 +32,7 @@ export default tseslint.config( { files: ['**/*.ts'] }, { rules: { - '@typescript-eslint/explicit-member-accessibility': 'warn', + '@typescript-eslint/explicit-member-accessibility': 'off', '@typescript-eslint/no-misused-promises': 0, '@typescript-eslint/no-floating-promises': 0, '@typescript-eslint/no-confusing-void-expression': 0, diff --git a/package.json b/package.json index 6e0827bf..ca7b6191 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,11 @@ "lint:tests": "npx eslint ./spec", "start": "NODE_ENV=development node -r ./preload.js ./dist", "test": "NODE_ENV=test npx ts-node ./spec", - "test:hot": "nodemon --exec \"npm run test\" --watch ./src --watch ./spec -e ts" + "test:hot": "nodemon --exec \"npm run test\" --watch ./src --watch ./spec -e ts", + "add:migration": "npm run typeorm -- -d ./src/repos/db.ts migration:generate ./src/migration/$npm_config_name", + "revert:migration": "npm run typeorm migration:revert -- -d ./src/repos/db.ts", + "apply:migration": "npm run typeorm migration:run -- -d ./src/repos/db.ts", + "typeorm": "ts-node --transpile-only -r tsconfig-paths/register ./node_modules/typeorm/cli.js" }, "engines": { "node": ">=16.0.0" diff --git a/src/entity/Comment.ts b/src/entity/Comment.ts new file mode 100644 index 00000000..a7ad31ad --- /dev/null +++ b/src/entity/Comment.ts @@ -0,0 +1,38 @@ +import { Entity, + Column, + PrimaryGeneratedColumn, + ManyToOne, + JoinColumn, + CreateDateColumn, + UpdateDateColumn, +} from 'typeorm'; +import { Review } from './Review'; + +@Entity('comments') +export class Comment { + @PrimaryGeneratedColumn('increment', { type: 'bigint' }) + id!: number; + + @ManyToOne(() => Review) + @JoinColumn({ name: 'review_id' }) + review!: Review; + + @Column({ type: 'bigint' }) + parent_id!: number; + + @Column('text') + comment_text!: string; + + @Column({ type: 'bigint' }) + review_id!: number; + + @CreateDateColumn({ type: 'datetime' }) + created_at!: Date; + + @UpdateDateColumn({ type: 'datetime' }) + updated_at!: Date; + + constructor(commentData?: Partial) { + commentData && Object.assign(this, commentData); + } +} diff --git a/src/entity/Component.ts b/src/entity/Component.ts new file mode 100644 index 00000000..3025784f --- /dev/null +++ b/src/entity/Component.ts @@ -0,0 +1,38 @@ +import { Entity, + Column, + PrimaryGeneratedColumn, + ManyToOne, + CreateDateColumn, + UpdateDateColumn, + JoinColumn +} from 'typeorm'; +import { Lesson } from './Lesson'; + +@Entity('components') +export class Component { + @PrimaryGeneratedColumn('increment', { type: 'bigint' }) + id!: number; + + @ManyToOne(() => Lesson) + @JoinColumn({ name: 'lesson_id' }) + lesson!: Lesson; + + @Column({ + type: 'enum', + enum: ['video', 'url', 'pdf', 'text'], + }) + type!: string; + + @Column('text') + content!: string; + + @CreateDateColumn({ type: 'datetime' }) + created_at!: Date; + + @UpdateDateColumn({ type: 'datetime' }) + updated_at!: Date; + + constructor(componentData?: Partial) { + componentData && Object.assign(this, componentData); + } +} diff --git a/src/entity/Course.ts b/src/entity/Course.ts new file mode 100644 index 00000000..fd6fa3d0 --- /dev/null +++ b/src/entity/Course.ts @@ -0,0 +1,44 @@ +import { Entity, + Column, + PrimaryGeneratedColumn, + ManyToOne, + CreateDateColumn, + UpdateDateColumn, + JoinColumn +} from 'typeorm'; +import { User } from './User'; + +@Entity('courses') +export class Course { + @PrimaryGeneratedColumn('increment', { type: 'bigint' }) + id!: number; + + @ManyToOne(() => User) + @JoinColumn({ name: 'professor_id' }) + professor!: User; + + @Column() + name!: string; + + @Column('double') + price!: number; + + @Column('text') + description!: string; + + @Column('float') + average_rating!: number; + + @Column({ type: 'bigint' }) + professor_id!: number; + + @CreateDateColumn({ type: 'datetime' }) + created_at!: Date; + + @UpdateDateColumn({ type: 'datetime' }) + updated_at!: Date; + + constructor(courseData?: Partial) { + courseData && Object.assign(this, courseData); + } +} diff --git a/src/entity/Enrollment.ts b/src/entity/Enrollment.ts new file mode 100644 index 00000000..abbb8be6 --- /dev/null +++ b/src/entity/Enrollment.ts @@ -0,0 +1,49 @@ +import { Entity, + Column, + PrimaryGeneratedColumn, + ManyToOne, + CreateDateColumn, + UpdateDateColumn, + JoinColumn +} from 'typeorm'; +import { User } from './User'; +import { Course } from './Course'; + +@Entity('enrollments') +export class Enrollment { + @PrimaryGeneratedColumn('increment', { type: 'bigint' }) + id!: number; + + @ManyToOne(() => User) + @JoinColumn({ name: 'user_id' }) + user!: User; + + @ManyToOne(() => Course) + @JoinColumn({ name: 'course_id' }) + course!: Course; + + @Column({ type: 'datetime' }) + enrollment_date!: Date; + + @Column('integer') + progress!: number; + + @Column({ type: 'datetime' }) + completion_date!: Date; + + @Column({ type: 'bigint' }) + user_id!: number; + + @Column({ type: 'bigint' }) + course_id!: number; + + @CreateDateColumn({ type: 'datetime' }) + created_at!: Date; + + @UpdateDateColumn({ type: 'datetime' }) + updated_at!: Date; + + constructor(enrollmentData?: Partial) { + enrollmentData && Object.assign(this, enrollmentData); + } +} diff --git a/src/entity/EnrollmentLesson.ts b/src/entity/EnrollmentLesson.ts new file mode 100644 index 00000000..49485173 --- /dev/null +++ b/src/entity/EnrollmentLesson.ts @@ -0,0 +1,46 @@ +import { Entity, + Column, + PrimaryGeneratedColumn, + ManyToOne, + CreateDateColumn, + UpdateDateColumn, + JoinColumn +} from 'typeorm'; +import { Enrollment } from './Enrollment'; +import { Lesson } from './Lesson'; + +@Entity('enrollments_lessons') +export class EnrollmentLesson { + @PrimaryGeneratedColumn('increment', { type: 'bigint' }) + id!: number; + + @ManyToOne(() => Enrollment) + @JoinColumn({ name: 'enrollment_id' }) + enrollment!: Enrollment; + + @ManyToOne(() => Lesson) + @JoinColumn({ name: 'lesson_id' }) + lesson!: Lesson; + + @Column('integer') + progress!: number; + + @Column({ type: 'datetime' }) + completion_date!: Date; + + @Column({ type: 'bigint' }) + enrollment_id!: number; + + @Column({ type: 'bigint' }) + lesson_id!: number; + + @CreateDateColumn({ type: 'datetime' }) + created_at!: Date; + + @UpdateDateColumn({ type: 'datetime' }) + updated_at!: Date; + + constructor(enrollmentLessonData?: Partial) { + enrollmentLessonData && Object.assign(this, enrollmentLessonData); + } +} diff --git a/src/entity/Lesson.ts b/src/entity/Lesson.ts new file mode 100644 index 00000000..0791c4ff --- /dev/null +++ b/src/entity/Lesson.ts @@ -0,0 +1,41 @@ +import { Entity, + Column, + PrimaryGeneratedColumn, + ManyToOne, + CreateDateColumn, + UpdateDateColumn, + JoinColumn +} from 'typeorm'; +import { Section } from './Section'; + +@Entity('lessons') +export class Lesson { + @PrimaryGeneratedColumn('increment', { type: 'bigint' }) + id!: number; + + @ManyToOne(() => Section) + @JoinColumn({ name: 'section_id' }) + section!: Section; + + @Column() + name!: string; + + @Column('text') + description!: string; + + @Column('integer') + time!: number; + + @Column({ type: 'bigint' }) + section_id!: number; + + @CreateDateColumn({ type: 'datetime' }) + created_at!: Date; + + @UpdateDateColumn({ type: 'datetime' }) + updated_at!: Date; + + constructor(lessonData?: Partial) { + lessonData && Object.assign(this, lessonData); + } +} diff --git a/src/entity/Payment.ts b/src/entity/Payment.ts new file mode 100644 index 00000000..b632f04c --- /dev/null +++ b/src/entity/Payment.ts @@ -0,0 +1,52 @@ +import { Entity, + Column, + PrimaryGeneratedColumn, + ManyToOne, + CreateDateColumn, + UpdateDateColumn, + JoinColumn +} from 'typeorm'; +import { User } from './User'; +import { Course } from './Course'; + +@Entity('payments') +export class Payment { + @PrimaryGeneratedColumn('increment', { type: 'bigint' }) + id!: number; + + @ManyToOne(() => User) + @JoinColumn({ name: 'user_id' }) + user!: User; + + @ManyToOne(() => Course) + @JoinColumn({ name: 'course_id' }) + course!: Course; + + @Column('double') + amount!: number; + + @Column({ type: 'date' }) + payment_date!: Date; + + @Column({ + type: 'enum', + enum: ['pending', 'done'], + }) + status!: string; + + @Column({ type: 'bigint' }) + user_id!: number; + + @Column({ type: 'bigint' }) + course_id!: number; + + @CreateDateColumn({ type: 'datetime' }) + created_at!: Date; + + @UpdateDateColumn({ type: 'datetime' }) + updated_at!: Date; + + constructor(paymentData?: Partial) { + paymentData && Object.assign(this, paymentData); + } +} diff --git a/src/entity/Review.ts b/src/entity/Review.ts new file mode 100644 index 00000000..2c26bd78 --- /dev/null +++ b/src/entity/Review.ts @@ -0,0 +1,43 @@ +import { Entity, + Column, + PrimaryGeneratedColumn, + ManyToOne, + CreateDateColumn, + UpdateDateColumn, + JoinColumn +} from 'typeorm'; +import { User } from './User'; +import { Course } from './Course'; + +@Entity('reviews') +export class Review { + @PrimaryGeneratedColumn('increment', { type: 'bigint' }) + id!: number; + + @ManyToOne(() => User) + @JoinColumn({ name: 'user_id' }) + user!: User; + + @ManyToOne(() => Course) + @JoinColumn({ name: 'course_id' }) + course!: Course; + + @Column('integer') + rating!: number; + + @Column({ type: 'bigint' }) + user_id!: number; + + @Column({ type: 'bigint' }) + course_id!: number; + + @CreateDateColumn({ type: 'datetime' }) + created_at!: Date; + + @UpdateDateColumn({ type: 'datetime' }) + updated_at!: Date; + + constructor(reviewData?: Partial) { + reviewData && Object.assign(this, reviewData); + } +} diff --git a/src/entity/Section.ts b/src/entity/Section.ts new file mode 100644 index 00000000..e8ae1b7a --- /dev/null +++ b/src/entity/Section.ts @@ -0,0 +1,41 @@ +import { Entity, + Column, + PrimaryGeneratedColumn, + ManyToOne, + CreateDateColumn, + UpdateDateColumn, + JoinColumn +} from 'typeorm'; +import { Course } from './Course'; + +@Entity('sections') +export class Section { + @PrimaryGeneratedColumn('increment', { type: 'bigint' }) + id!: number; + + @ManyToOne(() => Course) + @JoinColumn({ name: 'course_id' }) + course!: Course; + + @Column() + name!: string; + + @Column('integer') + total_time!: number; + + @Column('integer') + total_lesson!: number; + + @Column({ type: 'bigint' }) + course_id!: number; + + @CreateDateColumn({ type: 'datetime' }) + created_at!: Date; + + @UpdateDateColumn({ type: 'datetime' }) + updated_at!: Date; + + constructor(sectionData?: Partial
) { + sectionData && Object.assign(this, sectionData); + } +} diff --git a/src/entity/User.ts b/src/entity/User.ts new file mode 100644 index 00000000..ed1811c3 --- /dev/null +++ b/src/entity/User.ts @@ -0,0 +1,38 @@ +import { Entity, + Column, + PrimaryGeneratedColumn, + CreateDateColumn, + UpdateDateColumn +} from 'typeorm'; + +@Entity('users') +export class User { + @PrimaryGeneratedColumn('increment', { type: 'bigint' }) + id!: number; + + @Column() + name!: string; + + @Column() + email!: string; + + @Column() + password!: string; + + @Column({ + type: 'enum', + enum: ['user', 'professor', 'admin'], + default: 'user', + }) + role!: string; + + @CreateDateColumn({ type: 'datetime' }) + created_at!: Date; + + @UpdateDateColumn({ type: 'datetime' }) + updated_at!: Date; + + constructor(userData?: Partial) { + userData && Object.assign(this, userData); + } +} diff --git a/src/index.ts b/src/index.ts index 2b57255f..4b7e430e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,4 +7,4 @@ AppDataSource.initialize() }) .catch((error: unknown) => { console.log('Error during Data Source initialization:', error); - }); \ No newline at end of file + }); diff --git a/src/migration/1728392492258-first_migration.ts b/src/migration/1728392492258-first_migration.ts new file mode 100644 index 00000000..b6a99fc0 --- /dev/null +++ b/src/migration/1728392492258-first_migration.ts @@ -0,0 +1,58 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class FirstMigration1728392492258 implements MigrationInterface { + name = 'FirstMigration1728392492258'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query('CREATE TABLE `users` (`id` bigint NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `email` varchar(255) NOT NULL, `password` varchar(255) NOT NULL, `role` enum (\'user\', \'professor\', \'admin\') NOT NULL DEFAULT \'user\', `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB'); + await queryRunner.query('CREATE TABLE `courses` (`id` bigint NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `price` double NOT NULL, `description` text NOT NULL, `average_rating` float NOT NULL, `professor_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB'); + await queryRunner.query('CREATE TABLE `reviews` (`id` bigint NOT NULL AUTO_INCREMENT, `rating` int NOT NULL, `user_id` bigint NOT NULL, `course_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB'); + await queryRunner.query('CREATE TABLE `sections` (`id` bigint NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `total_time` int NOT NULL, `total_lesson` int NOT NULL, `course_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB'); + await queryRunner.query('CREATE TABLE `payments` (`id` bigint NOT NULL AUTO_INCREMENT, `amount` double NOT NULL, `payment_date` date NOT NULL, `status` enum (\'pending\', \'done\') NOT NULL, `user_id` bigint NOT NULL, `course_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB'); + await queryRunner.query('CREATE TABLE `lessons` (`id` bigint NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `description` text NOT NULL, `time` int NOT NULL, `section_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB'); + await queryRunner.query('CREATE TABLE `enrollments` (`id` bigint NOT NULL AUTO_INCREMENT, `enrollment_date` datetime NOT NULL, `progress` int NOT NULL, `completion_date` datetime NOT NULL, `user_id` bigint NOT NULL, `course_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB'); + await queryRunner.query('CREATE TABLE `enrollments_lessons` (`id` bigint NOT NULL AUTO_INCREMENT, `progress` int NOT NULL, `completion_date` datetime NOT NULL, `enrollment_id` bigint NOT NULL, `lesson_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB'); + await queryRunner.query('CREATE TABLE `components` (`id` bigint NOT NULL AUTO_INCREMENT, `type` enum (\'video\', \'url\', \'pdf\', \'text\') NOT NULL, `content` text NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `lesson_id` bigint NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB'); + await queryRunner.query('CREATE TABLE `comments` (`id` bigint NOT NULL AUTO_INCREMENT, `parent_id` bigint NOT NULL, `comment_text` text NOT NULL, `review_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB'); + await queryRunner.query('ALTER TABLE `courses` ADD CONSTRAINT `FK_7722a465aa381126eb553158c73` FOREIGN KEY (`professor_id`) REFERENCES `users`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION'); + await queryRunner.query('ALTER TABLE `reviews` ADD CONSTRAINT `FK_728447781a30bc3fcfe5c2f1cdf` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION'); + await queryRunner.query('ALTER TABLE `reviews` ADD CONSTRAINT `FK_f99062f36181ab42863facfaea3` FOREIGN KEY (`course_id`) REFERENCES `courses`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION'); + await queryRunner.query('ALTER TABLE `sections` ADD CONSTRAINT `FK_53ccbd6e2fa20dac9062f4f4c36` FOREIGN KEY (`course_id`) REFERENCES `courses`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION'); + await queryRunner.query('ALTER TABLE `payments` ADD CONSTRAINT `FK_427785468fb7d2733f59e7d7d39` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION'); + await queryRunner.query('ALTER TABLE `payments` ADD CONSTRAINT `FK_c5fa169d2de9407d99f2c6e4fab` FOREIGN KEY (`course_id`) REFERENCES `courses`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION'); + await queryRunner.query('ALTER TABLE `lessons` ADD CONSTRAINT `FK_19261e484ffd22b40ea596ece4d` FOREIGN KEY (`section_id`) REFERENCES `sections`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION'); + await queryRunner.query('ALTER TABLE `enrollments` ADD CONSTRAINT `FK_ff997f5a39cd24a491b9aca45c9` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION'); + await queryRunner.query('ALTER TABLE `enrollments` ADD CONSTRAINT `FK_b79d0bf01779fdf9cfb6b092af3` FOREIGN KEY (`course_id`) REFERENCES `courses`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION'); + await queryRunner.query('ALTER TABLE `enrollments_lessons` ADD CONSTRAINT `FK_8c1f7f99b8fd21076b8ae547bba` FOREIGN KEY (`enrollment_id`) REFERENCES `enrollments`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION'); + await queryRunner.query('ALTER TABLE `enrollments_lessons` ADD CONSTRAINT `FK_a0b2d6a99bbb3ab51916259b3c1` FOREIGN KEY (`lesson_id`) REFERENCES `lessons`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION'); + await queryRunner.query('ALTER TABLE `components` ADD CONSTRAINT `FK_1184609d2ce4aec53e82e051051` FOREIGN KEY (`lesson_id`) REFERENCES `lessons`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION'); + await queryRunner.query('ALTER TABLE `comments` ADD CONSTRAINT `FK_0fe168752ce3bb4e7376d81f7ad` FOREIGN KEY (`review_id`) REFERENCES `reviews`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION'); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query('ALTER TABLE `comments` DROP FOREIGN KEY `FK_0fe168752ce3bb4e7376d81f7ad`'); + await queryRunner.query('ALTER TABLE `components` DROP FOREIGN KEY `FK_1184609d2ce4aec53e82e051051`'); + await queryRunner.query('ALTER TABLE `enrollments_lessons` DROP FOREIGN KEY `FK_a0b2d6a99bbb3ab51916259b3c1`'); + await queryRunner.query('ALTER TABLE `enrollments_lessons` DROP FOREIGN KEY `FK_8c1f7f99b8fd21076b8ae547bba`'); + await queryRunner.query('ALTER TABLE `enrollments` DROP FOREIGN KEY `FK_b79d0bf01779fdf9cfb6b092af3`'); + await queryRunner.query('ALTER TABLE `enrollments` DROP FOREIGN KEY `FK_ff997f5a39cd24a491b9aca45c9`'); + await queryRunner.query('ALTER TABLE `lessons` DROP FOREIGN KEY `FK_19261e484ffd22b40ea596ece4d`'); + await queryRunner.query('ALTER TABLE `payments` DROP FOREIGN KEY `FK_c5fa169d2de9407d99f2c6e4fab`'); + await queryRunner.query('ALTER TABLE `payments` DROP FOREIGN KEY `FK_427785468fb7d2733f59e7d7d39`'); + await queryRunner.query('ALTER TABLE `sections` DROP FOREIGN KEY `FK_53ccbd6e2fa20dac9062f4f4c36`'); + await queryRunner.query('ALTER TABLE `reviews` DROP FOREIGN KEY `FK_f99062f36181ab42863facfaea3`'); + await queryRunner.query('ALTER TABLE `reviews` DROP FOREIGN KEY `FK_728447781a30bc3fcfe5c2f1cdf`'); + await queryRunner.query('ALTER TABLE `courses` DROP FOREIGN KEY `FK_7722a465aa381126eb553158c73`'); + await queryRunner.query('DROP TABLE `comments`'); + await queryRunner.query('DROP TABLE `components`'); + await queryRunner.query('DROP TABLE `enrollments_lessons`'); + await queryRunner.query('DROP TABLE `enrollments`'); + await queryRunner.query('DROP TABLE `lessons`'); + await queryRunner.query('DROP TABLE `payments`'); + await queryRunner.query('DROP TABLE `sections`'); + await queryRunner.query('DROP TABLE `reviews`'); + await queryRunner.query('DROP TABLE `courses`'); + await queryRunner.query('DROP TABLE `users`'); + } + +} diff --git a/tsconfig.json b/tsconfig.json index 4d11ee7a..a524eb02 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -84,4 +84,4 @@ "exclude": [ "src/public/*" ] -} \ No newline at end of file +}