From a435f19a67002ea50360dbd83d003457168c8acf Mon Sep 17 00:00:00 2001 From: wielopolski Date: Thu, 7 Nov 2024 16:40:35 +0100 Subject: [PATCH] chore: revert refactor seed directory --- .github/workflows/deploy-api-staging.yml | 4 ++-- apps/api/package.json | 3 ++- .../src/{storage/seed => }/nice-data-seeds.ts | 4 ++-- apps/api/src/{storage/seed => }/seed-helpers.ts | 2 +- .../src/{storage/seed => }/seed.production.ts | 8 ++++---- apps/api/src/{storage/seed => }/seed.ts | 17 ++++++++--------- .../trancateTables.ts => truncateTables.ts} | 12 +++++++++++- 7 files changed, 30 insertions(+), 20 deletions(-) rename apps/api/src/{storage/seed => }/nice-data-seeds.ts (99%) rename apps/api/src/{storage/seed => }/seed-helpers.ts (99%) rename apps/api/src/{storage/seed => }/seed.production.ts (92%) rename apps/api/src/{storage/seed => }/seed.ts (97%) rename apps/api/src/{storage/seed/trancateTables.ts => truncateTables.ts} (64%) diff --git a/.github/workflows/deploy-api-staging.yml b/.github/workflows/deploy-api-staging.yml index de0204168..725f0ab7a 100644 --- a/.github/workflows/deploy-api-staging.yml +++ b/.github/workflows/deploy-api-staging.yml @@ -56,7 +56,7 @@ jobs: ECS_CLUSTER: ${{ vars.AWS_ECS_CLUSTER }} ECS_SERVICE: ${{ vars.AWS_ECS_SERVICE }} DOCKER_IMAGE: ${{ secrets.AWS_ECR_REGISTRY }}:${{ github.sha }} - run: selleo aws ecs deploy --region $AWS_REGION --cluster $ECS_CLUSTER --service $ECS_SERVICE --docker-image $DOCKER_IMAGE --one-off migrate --one-off storage/seed/seed + run: selleo aws ecs deploy --region $AWS_REGION --cluster $ECS_CLUSTER --service $ECS_SERVICE --docker-image $DOCKER_IMAGE --one-off migrate --one-off seed - name: ECS Run migrations env: @@ -70,4 +70,4 @@ jobs: AWS_REGION: ${{ vars.AWS_REGION }} ECS_CLUSTER: ${{ vars.AWS_ECS_CLUSTER }} ECS_SERVICE: ${{ vars.AWS_ECS_SERVICE }} - run: selleo aws ecs run --region $AWS_REGION --cluster $ECS_CLUSTER --service $ECS_SERVICE --one-off storage/seed/seed + run: selleo aws ecs run --region $AWS_REGION --cluster $ECS_CLUSTER --service $ECS_SERVICE --one-off seed diff --git a/apps/api/package.json b/apps/api/package.json index c267691a6..38af7976a 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -26,7 +26,8 @@ "db:migrate": "drizzle-kit migrate", "db:generate": "drizzle-kit generate", "db:seed": "ts-node -r tsconfig-paths/register ./src/storage/seed/seed.ts", - "db:seed-prod": "node dist/src/seed.js" + "db:seed-prod": "node dist/src/seed.js", + "db:truncate-tables": "node dist/src/truncateTables.js" }, "dependencies": { "@aws-sdk/client-s3": "^3.658.1", diff --git a/apps/api/src/storage/seed/nice-data-seeds.ts b/apps/api/src/nice-data-seeds.ts similarity index 99% rename from apps/api/src/storage/seed/nice-data-seeds.ts rename to apps/api/src/nice-data-seeds.ts index b101794d0..14cc9e25b 100644 --- a/apps/api/src/storage/seed/nice-data-seeds.ts +++ b/apps/api/src/nice-data-seeds.ts @@ -11,8 +11,8 @@ import { textBlockSchema, } from "src/lessons/schemas/lessonItem.schema"; -import { QUESTION_TYPE } from "../../questions/schema/questions.types"; -import { STATUS } from "../schema/utils"; +import { QUESTION_TYPE } from "./questions/schema/questions.types"; +import { STATUS } from "./storage/schema/utils"; import type { Static } from "@sinclair/typebox"; diff --git a/apps/api/src/storage/seed/seed-helpers.ts b/apps/api/src/seed-helpers.ts similarity index 99% rename from apps/api/src/storage/seed/seed-helpers.ts rename to apps/api/src/seed-helpers.ts index 00b8c1ccb..8127299b4 100644 --- a/apps/api/src/storage/seed/seed-helpers.ts +++ b/apps/api/src/seed-helpers.ts @@ -15,7 +15,7 @@ import { import { niceCourses } from "./nice-data-seeds"; -import type { DatabasePg } from "../../common"; +import type { DatabasePg } from "./common"; export async function createNiceCourses(adminUserId: string, db: DatabasePg) { for (const courseData of niceCourses) { diff --git a/apps/api/src/storage/seed/seed.production.ts b/apps/api/src/seed.production.ts similarity index 92% rename from apps/api/src/storage/seed/seed.production.ts rename to apps/api/src/seed.production.ts index 854d969d0..81398f7d8 100644 --- a/apps/api/src/storage/seed/seed.production.ts +++ b/apps/api/src/seed.production.ts @@ -4,11 +4,11 @@ import { eq } from "drizzle-orm"; import { drizzle } from "drizzle-orm/postgres-js"; import postgres from "postgres"; -import hashPassword from "../../common/helpers/hashPassword"; -import { USER_ROLES } from "../../users/schemas/user-roles"; -import { credentials, users } from "../schema"; +import hashPassword from "./common/helpers/hashPassword"; +import { credentials, users } from "./storage/schema"; +import { USER_ROLES } from "./users/schemas/user-roles"; -import type { DatabasePg } from "../../common"; +import type { DatabasePg } from "./common"; dotenv.config({ path: "./.env" }); diff --git a/apps/api/src/storage/seed/seed.ts b/apps/api/src/seed.ts similarity index 97% rename from apps/api/src/storage/seed/seed.ts rename to apps/api/src/seed.ts index 0accd9625..ce81af18a 100644 --- a/apps/api/src/storage/seed/seed.ts +++ b/apps/api/src/seed.ts @@ -5,10 +5,10 @@ import { drizzle } from "drizzle-orm/postgres-js"; import { sampleSize } from "lodash"; import postgres from "postgres"; -import hashPassword from "../../common/helpers/hashPassword"; -import { STATES } from "../../common/states"; -import { LESSON_ITEM_TYPE } from "../../lessons/lesson.type"; -import { USER_ROLES } from "../../users/schemas/user-roles"; +import hashPassword from "./common/helpers/hashPassword"; +import { STATES } from "./common/states"; +import { LESSON_ITEM_TYPE } from "./lessons/lesson.type"; +import { createNiceCourses, seedTruncateAllTables } from "./seed-helpers"; import { categories, courseLessons, @@ -22,12 +22,11 @@ import { studentCourses, textBlocks, users, -} from "../schema"; -import { STATUS } from "../schema/utils"; - -import { createNiceCourses, seedTruncateAllTables } from "./seed-helpers"; +} from "./storage/schema"; +import { STATUS } from "./storage/schema/utils"; +import { USER_ROLES } from "./users/schemas/user-roles"; -import type { DatabasePg, UUIDType } from "../../common"; +import type { DatabasePg, UUIDType } from "./common"; dotenv.config({ path: "./.env" }); diff --git a/apps/api/src/storage/seed/trancateTables.ts b/apps/api/src/truncateTables.ts similarity index 64% rename from apps/api/src/storage/seed/trancateTables.ts rename to apps/api/src/truncateTables.ts index 49a9479f7..23ee8da50 100644 --- a/apps/api/src/storage/seed/trancateTables.ts +++ b/apps/api/src/truncateTables.ts @@ -4,7 +4,7 @@ import postgres from "postgres"; import { seedTruncateAllTables } from "./seed-helpers"; -import type { DatabasePg } from "../../common"; +import type { DatabasePg } from "./common"; dotenv.config({ path: "./.env" }); @@ -18,6 +18,16 @@ const db = drizzle(sql) as DatabasePg; async function seed() { await seedTruncateAllTables(db); + console.log("✨✨✨Created empty database✨✨✨"); +} + +if (require.main === module) { + seed() + .then(() => process.exit(0)) + .catch((error) => { + console.error("An error occurred:", error); + process.exit(1); + }); } export default seed;