Skip to content

Commit

Permalink
chore: revert refactor seed directory
Browse files Browse the repository at this point in the history
  • Loading branch information
wielopolski committed Nov 7, 2024
1 parent f797e46 commit a435f19
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy-api-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
3 changes: 2 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" });

Expand Down
17 changes: 8 additions & 9 deletions apps/api/src/storage/seed/seed.ts → apps/api/src/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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" });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" });

Expand All @@ -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;

0 comments on commit a435f19

Please sign in to comment.