diff --git a/apps/backend/src/app.module.ts b/apps/backend/src/app.module.ts index 54fb044e..9af0cf4b 100644 --- a/apps/backend/src/app.module.ts +++ b/apps/backend/src/app.module.ts @@ -3,11 +3,10 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { AppController } from './app.controller'; import { AppService } from './app.service'; -import { TaskModule } from './task/task.module'; import AppDataSource from './data-source'; @Module({ - imports: [TypeOrmModule.forRoot(AppDataSource.options), TaskModule], + imports: [TypeOrmModule.forRoot(AppDataSource.options)], controllers: [AppController], providers: [AppService], }) diff --git a/apps/backend/src/data-source.ts b/apps/backend/src/data-source.ts index 4cd06624..dee1429a 100644 --- a/apps/backend/src/data-source.ts +++ b/apps/backend/src/data-source.ts @@ -1,6 +1,5 @@ import { DataSource } from 'typeorm'; import { PluralNamingStrategy } from './strategies/plural-naming.strategy'; -import { Task } from './task/types/task.entity'; import * as dotenv from 'dotenv'; dotenv.config(); @@ -12,8 +11,10 @@ const AppDataSource = new DataSource({ username: process.env.NX_DB_USERNAME, password: process.env.NX_DB_PASSWORD, database: process.env.NX_DB_DATABASE, - entities: [Task], + entities: [], migrations: ['apps/backend/src/migrations/*.js'], + // migrations: ['apps/backend/src/migrations/*.ts'], // use this line instead of the above when running migrations locally, + // then switch back to the above before pushing to github so that it works on the deployment server // Setting synchronize: true shouldn't be used in production - otherwise you can lose production data synchronize: false, namingStrategy: new PluralNamingStrategy(), diff --git a/apps/backend/src/migrations/1754254886189-add_task.ts b/apps/backend/src/migrations/1754254886189-add_task.ts deleted file mode 100644 index 450a6415..00000000 --- a/apps/backend/src/migrations/1754254886189-add_task.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; - -export class AddTask1754254886189 implements MigrationInterface { - name = 'AddTask1754254886189'; - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query( - `CREATE TYPE "public"."tasks_category_enum" AS ENUM('Draft', 'To Do', 'In Progress', 'Completed')`, - ); - await queryRunner.query( - `CREATE TABLE "task" ("id" SERIAL NOT NULL, "title" character varying NOT NULL, "description" character varying, "dateCreated" TIMESTAMP NOT NULL DEFAULT now(), "dueDate" TIMESTAMP, "labels" jsonb NOT NULL DEFAULT '[]', "category" "public"."tasks_category_enum" NOT NULL DEFAULT 'Draft', CONSTRAINT "PK_8d12ff38fcc62aaba2cab748772" PRIMARY KEY ("id"))`, - ); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP TABLE "task"`); - await queryRunner.query(`DROP TYPE "public"."tasks_category_enum"`); - } -} diff --git a/apps/backend/src/migrations/1754254886189-init.ts b/apps/backend/src/migrations/1754254886189-init.ts new file mode 100644 index 00000000..d35b9233 --- /dev/null +++ b/apps/backend/src/migrations/1754254886189-init.ts @@ -0,0 +1,92 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class Init1754254886189 implements MigrationInterface { + name = 'Init1754254886189'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE TYPE "public"."commit_length_enum" AS ENUM('Semester', 'Month', 'Year')`, + ); + + await queryRunner.query( + `CREATE TYPE "public"."site_enum" AS ENUM('Downtown Campus', 'North Campus', 'West Campus', 'East Campus')`, + ); + + await queryRunner.query( + `CREATE TYPE "public"."app_status_enum" AS ENUM('App submitted', 'in review', 'forms sent', 'accepted', 'rejected')`, + ); + + await queryRunner.query( + `CREATE TYPE "public"."school_enum" AS ENUM('Harvard Medical School', 'Johns Hopkins', 'Stanford Medicine', 'Mayo Clinic', 'Other')`, + ); + + await queryRunner.query( + `CREATE TYPE "public"."experience_type_enum" AS ENUM('BS', 'MS', 'PhD', 'MD', 'MD PhD', 'RN', 'NP', 'PA', 'Other')`, + ); + + await queryRunner.query( + `CREATE TYPE "public"."interest_area_enum" AS ENUM('Nursing', 'HarmReduction', 'WomensHealth')`, + ); + + await queryRunner.query( + `CREATE TABLE "admin" ( + "id" SERIAL NOT NULL, + "name" character varying NOT NULL, + "email" character varying NOT NULL UNIQUE, + CONSTRAINT "PK_admin_id" PRIMARY KEY ("id") + )`, + ); + + await queryRunner.query( + `CREATE TABLE "discipline" ( + "id" SERIAL NOT NULL, + "name" character varying NOT NULL, + "admin_ids" integer[] NOT NULL DEFAULT '{}', + CONSTRAINT "PK_discipline_id" PRIMARY KEY ("id") + )`, + ); + + await queryRunner.query( + `CREATE TABLE "application" ( + "appId" SERIAL NOT NULL, + "phone" character varying NOT NULL, + "school" "public"."school_enum" NOT NULL, + "daysAvailable" character varying NOT NULL, + "weeklyHours" integer NOT NULL, + "experienceType" "public"."experience_type_enum" NOT NULL, + "interest" "public"."interest_area_enum" NOT NULL, + "license" character varying, + "appStatus" "public"."app_status_enum" NOT NULL DEFAULT 'App submitted', + "isInternational" boolean NOT NULL DEFAULT false, + "isLearner" boolean NOT NULL DEFAULT false, + "referredEmail" character varying, + "referred" boolean NOT NULL DEFAULT false, + CONSTRAINT "PK_application_appId" PRIMARY KEY ("appId") + )`, + ); + + await queryRunner.query( + `CREATE TABLE "learner" ( + "id" SERIAL NOT NULL, + "app_id" integer NOT NULL, + "name" character varying NOT NULL, + "startDate" DATE NOT NULL, + "endDate" DATE NOT NULL, + CONSTRAINT "PK_learner_id" PRIMARY KEY ("id"), + CONSTRAINT "FK_learner_app_id" FOREIGN KEY ("app_id") REFERENCES "application"("appId") ON DELETE CASCADE + )`, + ); + } + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "learner"`); + await queryRunner.query(`DROP TABLE "application"`); + await queryRunner.query(`DROP TABLE "discipline"`); + await queryRunner.query(`DROP TABLE "admin"`); + await queryRunner.query(`DROP TYPE "public"."interest_area_enum"`); + await queryRunner.query(`DROP TYPE "public"."experience_type_enum"`); + await queryRunner.query(`DROP TYPE "public"."school_enum"`); + await queryRunner.query(`DROP TYPE "public"."app_status_enum"`); + await queryRunner.query(`DROP TYPE "public"."site_enum"`); + await queryRunner.query(`DROP TYPE "public"."commit_length_enum"`); + } +} diff --git a/example.env b/example.env index 211b1472..a4a120c7 100644 --- a/example.env +++ b/example.env @@ -1,5 +1,5 @@ -NX_DB_HOST=localhost, -NX_DB_USERNAME=postgres, -NX_DB_PASSWORD=, -NX_DB_DATABASE=jumpstart, -NX_DB_PORT=5432, \ No newline at end of file +NX_DB_HOST=localhost +NX_DB_PORT=5432 +NX_DB_USERNAME=postgres +NX_DB_PASSWORD= +NX_DB_DATABASE=bhchp