From 50ac20e17e2ef2e271086718db5dd8b52d670a97 Mon Sep 17 00:00:00 2001 From: piersolh <145268163+piersolh@users.noreply.github.com> Date: Sun, 14 Sep 2025 14:37:41 -0400 Subject: [PATCH 1/3] adding migrations --- apps/backend/src/app.module.ts | 3 +- apps/backend/src/data-source.ts | 3 +- .../src/migrations/1754254886189-add_task.ts | 19 ---- .../src/migrations/1754254886189-init.ts | 92 +++++++++++++++++++ example.env | 5 - 5 files changed, 94 insertions(+), 28 deletions(-) delete mode 100644 apps/backend/src/migrations/1754254886189-add_task.ts create mode 100644 apps/backend/src/migrations/1754254886189-init.ts delete mode 100644 example.env 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..e9c75481 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,7 +11,7 @@ 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'], // Setting synchronize: true shouldn't be used in production - otherwise you can lose production data synchronize: false, 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 deleted file mode 100644 index 211b1472..00000000 --- a/example.env +++ /dev/null @@ -1,5 +0,0 @@ -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 From 749cdabbcaef07b4471ab3dbbebe2c8ff68dead0 Mon Sep 17 00:00:00 2001 From: piersolh <145268163+piersolh@users.noreply.github.com> Date: Sun, 14 Sep 2025 14:46:57 -0400 Subject: [PATCH 2/3] adding back example env --- example.env | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 example.env diff --git a/example.env b/example.env new file mode 100644 index 00000000..a4a120c7 --- /dev/null +++ b/example.env @@ -0,0 +1,5 @@ +NX_DB_HOST=localhost +NX_DB_PORT=5432 +NX_DB_USERNAME=postgres +NX_DB_PASSWORD= +NX_DB_DATABASE=bhchp From f3d586e52b232c2b2ad779b23124ac7646c8bdf9 Mon Sep 17 00:00:00 2001 From: piersolh <145268163+piersolh@users.noreply.github.com> Date: Tue, 16 Sep 2025 22:05:30 -0400 Subject: [PATCH 3/3] adding comments to explain type error --- apps/backend/src/data-source.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/backend/src/data-source.ts b/apps/backend/src/data-source.ts index e9c75481..dee1429a 100644 --- a/apps/backend/src/data-source.ts +++ b/apps/backend/src/data-source.ts @@ -13,6 +13,8 @@ const AppDataSource = new DataSource({ database: process.env.NX_DB_DATABASE, 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(),