Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/migration history #54

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@
"start:dev": "NODE_ENV=dev nest start --config src/bootstrap/nest-cli.json",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"prisma-push:local": "dotenv -e env/.env.local -- npx prisma db push",
"prisma-push:dev": "dotenv -e env/.env.dev -- npx prisma db push",
"prisma-pull:local": "dotenv -e env/.env.local -- npx prisma db pull --schema src/prisma/schema.prisma",
"prisma-pull:dev": "dotenv -e env/.env.dev -- npx prisma db pull --schema src/prisma/schema.prisma",
"prisma-migrate-create-dev:local": "dotenv -e env/.env.local -- npx prisma migrate dev --schema src/prisma/schema.prisma --create-only ",
"prisma-migrate-dev:local": "dotenv -e env/.env.local -- npx prisma migrate dev --schema src/prisma/schema.prisma",
"prisma-migrate-dev:dev": "dotenv -e env/.env.dev -- npx prisma migrate dev --schema src/prisma/schema.prisma",
"prisma-generate": "npx prisma generate --schema src/prisma/schema.prisma",
"prisma-status:local": "dotenv -e env/.env.local npx prisma migrate status",
"prisma-status:dev": "dotenv -e env/.env.dev npx prisma migrate status",
"prisma-resolve:local": "dotenv -e env/.env.local npx prisma migrate resolve",
"prisma-resolve:dev": "dotenv -e env/.env.dev npx prisma migrate resolve",
"db:push": "dotenv -e env/.env.local -- npx prisma db push",
"db:pull": "dotenv -e env/.env.local -- npx prisma db pull --schema src/prisma/schema.prisma",
"db:init": "dotenv -e env/.env.local -- npx prisma db execute --file src/prisma/migrations/0_init/migration.sql --schema src/prisma/schema.prisma && dotenv -e env/.env.local npx prisma migrate resolve --applied 0_init",
"migrate:dev-create": "dotenv -e env/.env.local -- npx prisma migrate dev --schema src/prisma/schema.prisma --create-only ",
"migrate:dev": "dotenv -e env/.env.local -- npx prisma migrate dev --schema src/prisma/schema.prisma",
"migrate:deploy": "dotenv -e env/.env.local -- npx prisma migrate deploy --schema src/prisma/schema.prisma",
"migrate:status": "dotenv -e env/.env.local npx prisma migrate status",
"migrate:resolve": "dotenv -e env/.env.local npx prisma migrate resolve '--applied' '0_init'",
"client:generate": "npx prisma generate --schema src/prisma/schema.prisma",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"lint:check": "eslint .",
"test": "jest",
Expand Down
630 changes: 322 additions & 308 deletions src/prisma/migrations/0_init/migration.sql

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { normalizeArray } from '../../../common/utils/method.utils';
import settings from '../../../settings';
import { PrismaService } from '../../prisma.service';
import { normalizeArray } from 'src/common/utils/method.utils';
import { PrismaService } from 'src/prisma/prisma.service';
import settings from 'src/settings';

async function main() {
const ormConfig = settings().ormconfig();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { JwtService } from '@nestjs/jwt';
import * as bcrypt from 'bcrypt';
import { AuthService } from '../../../modules/auth/auth.service';
import settings from '../../../settings';
import { PrismaService } from '../../prisma.service';
import { UserRepository } from '../../repositories/user.repository';
import { AuthService } from 'src/modules/auth/auth.service';
import { PrismaService } from 'src/prisma/prisma.service';
import { UserRepository } from 'src/prisma/repositories/user.repository';
import settings from 'src/settings';

async function main() {
const ormConfig = settings().ormconfig();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import settings from '../../../settings';
import { PrismaService } from '../../prisma.service';
import { PrismaService } from 'src/prisma/prisma.service';
import settings from 'src/settings';

async function main() {
const ormConfig = settings().ormconfig();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import settings from '../../../settings';
import { PrismaService } from '../../prisma.service';
import { PrismaService } from 'src/prisma/prisma.service';
import settings from 'src/settings';

async function main() {
const ormConfig = settings().ormconfig();
Expand Down
108 changes: 108 additions & 0 deletions src/prisma/migrations/20240116150914_django_to_nest/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
Warnings:

- You are about to drop the column `language` on the `session_userprofile` table. All the data in the column will be lost.
- You are about to drop the column `portal_check` on the `session_userprofile` table. All the data in the column will be lost.
- You are about to drop the column `user_id` on the `session_userprofile` table. All the data in the column will be lost.
- You are about to drop the `subject_professor_course_list` table. If the table is not empty, all the data it contains will be lost.
- Added the required column `date_joined` to the `session_userprofile` table without a default value. This is not possible if the table is not empty.
- Added the required column `first_name` to the `session_userprofile` table without a default value. This is not possible if the table is not empty.
- Added the required column `last_name` to the `session_userprofile` table without a default value. This is not possible if the table is not empty.
- Added the required column `title_en_no_space` to the `subject_course` table without a default value. This is not possible if the table is not empty.
- Added the required column `title_no_space` to the `subject_course` table without a default value. This is not possible if the table is not empty.
- Added the required column `title_en_no_space` to the `subject_lecture` table without a default value. This is not possible if the table is not empty.
- Added the required column `title_no_space` to the `subject_lecture` table without a default value. This is not possible if the table is not empty.

*/
-- DropIndex
DROP INDEX `session_userprofile_user_id_09dd6af1_uniq` ON `session_userprofile`;

-- AlterTable
ALTER TABLE `review_review` MODIFY `grade` SMALLINT NOT NULL DEFAULT 0,
MODIFY `load` SMALLINT NOT NULL DEFAULT 0,
MODIFY `speech` SMALLINT NOT NULL DEFAULT 0,
MODIFY `like` INTEGER NOT NULL DEFAULT 0,
MODIFY `is_deleted` INTEGER NOT NULL DEFAULT 0;

-- AlterTable
ALTER TABLE `session_userprofile` DROP COLUMN `language`,
DROP COLUMN `portal_check`,
DROP COLUMN `user_id`,
ADD COLUMN `date_joined` DATETIME(0) NOT NULL,
ADD COLUMN `first_name` VARCHAR(30) NOT NULL,
ADD COLUMN `last_name` VARCHAR(150) NOT NULL,
ADD COLUMN `refresh_token` VARCHAR(255) NULL;

-- AlterTable
ALTER TABLE `subject_course` ADD COLUMN `title_en_no_space` VARCHAR(200) NOT NULL,
ADD COLUMN `title_no_space` VARCHAR(100) NOT NULL;

-- AlterTable
ALTER TABLE `subject_lecture` ADD COLUMN `title_en_no_space` VARCHAR(200) NOT NULL,
ADD COLUMN `title_no_space` VARCHAR(100) NOT NULL;

-- DropTable
DROP TABLE `subject_professor_course_list`;

-- CreateIndex
CREATE INDEX `session_userprofile_department_id_fkey` ON `session_userprofile`(`department_id`);

-- CreateIndex
CREATE INDEX `session_userprofile_favorite_departments_department_id_fkey` ON `session_userprofile_favorite_departments`(`department_id`);

-- CreateIndex
CREATE INDEX `session_userprofile_taken_lectures_lecture_id_fkey` ON `session_userprofile_taken_lectures`(`lecture_id`);

-- CreateIndex
CREATE INDEX `subject_course_department_id_fkey` ON `subject_course`(`department_id`);

-- AddForeignKey
ALTER TABLE `review_review` ADD CONSTRAINT `review_review_course_id_fkey` FOREIGN KEY (`course_id`) REFERENCES `subject_course`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `review_review` ADD CONSTRAINT `review_review_lecture_id_fkey` FOREIGN KEY (`lecture_id`) REFERENCES `subject_lecture`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `review_review` ADD CONSTRAINT `review_review_writer_id_fkey` FOREIGN KEY (`writer_id`) REFERENCES `session_userprofile`(`id`) ON DELETE SET NULL ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `review_reviewvote` ADD CONSTRAINT `review_reviewvote_review_id_fkey` FOREIGN KEY (`review_id`) REFERENCES `review_review`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `review_reviewvote` ADD CONSTRAINT `review_reviewvote_userprofile_id_fkey` FOREIGN KEY (`userprofile_id`) REFERENCES `session_userprofile`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `session_userprofile` ADD CONSTRAINT `session_userprofile_department_id_fkey` FOREIGN KEY (`department_id`) REFERENCES `subject_department`(`id`) ON DELETE SET NULL ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `session_userprofile_favorite_departments` ADD CONSTRAINT `session_userprofile_favorite_departments_userprofile_id_fkey` FOREIGN KEY (`userprofile_id`) REFERENCES `session_userprofile`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `session_userprofile_favorite_departments` ADD CONSTRAINT `session_userprofile_favorite_departments_department_id_fkey` FOREIGN KEY (`department_id`) REFERENCES `subject_department`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `session_userprofile_taken_lectures` ADD CONSTRAINT `session_userprofile_taken_lectures_userprofile_id_fkey` FOREIGN KEY (`userprofile_id`) REFERENCES `session_userprofile`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `session_userprofile_taken_lectures` ADD CONSTRAINT `session_userprofile_taken_lectures_lecture_id_fkey` FOREIGN KEY (`lecture_id`) REFERENCES `subject_lecture`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `subject_course` ADD CONSTRAINT `subject_course_department_id_fkey` FOREIGN KEY (`department_id`) REFERENCES `subject_department`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `subject_course_professors` ADD CONSTRAINT `subject_course_professors_course_id_fkey` FOREIGN KEY (`course_id`) REFERENCES `subject_course`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `subject_course_professors` ADD CONSTRAINT `subject_course_professors_professor_id_fkey` FOREIGN KEY (`professor_id`) REFERENCES `subject_professor`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `subject_lecture` ADD CONSTRAINT `subject_lecture_department_id_fkey` FOREIGN KEY (`department_id`) REFERENCES `subject_department`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `subject_lecture` ADD CONSTRAINT `subject_lecture_course_id_fkey` FOREIGN KEY (`course_id`) REFERENCES `subject_course`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `subject_lecture_professors` ADD CONSTRAINT `subject_lecture_professors_lecture_id_fkey` FOREIGN KEY (`lecture_id`) REFERENCES `subject_lecture`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `subject_lecture_professors` ADD CONSTRAINT `subject_lecture_professors_professor_id_fkey` FOREIGN KEY (`professor_id`) REFERENCES `subject_professor`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
2 changes: 1 addition & 1 deletion src/prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "mysql"
provider = "mysql"
8 changes: 4 additions & 4 deletions src/prisma/prisma.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit() {
await this.$connect();
// @ts-ignore
this.$on('query', async (e) => {
// @ts-ignore
console.log(`Query: ${e.query} ${e.params}`);
});
// this.$on('query', async (e) => {
// // @ts-ignore
// console.log(`Query: ${e.query} ${e.params}`);
// });
}

async enableShutdownHooks(app: INestApplication) {
Expand Down
Loading
Loading