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

Command seed run won't close the process after completing #122

Open
SergioMD15 opened this issue Dec 9, 2024 · 0 comments
Open

Command seed run won't close the process after completing #122

SergioMD15 opened this issue Dec 9, 2024 · 0 comments

Comments

@SergioMD15
Copy link

What?

I'm struggling to include kysely seed run within the scripts to start my server (using v0.9.0 of kysely-ctl). I've created some seed files using the following configuration:

import { defineConfig, getKnexTimestampPrefix } from "kysely-ctl"
import { Pool } from "pg"

export default defineConfig({
  dialect: "pg",
  dialectConfig: {
    pool: new Pool({ connectionString: process.env.DATABASE_URL })
  },
  migrations: {
    migrationFolder: "src/db/migrations",
    getMigrationPrefix: getKnexTimestampPrefix
  },
  seeds: {
    seedFolder: "src/db/seeds",
    getSeedPrefix: () => {
      const fs = require("fs")
      const files = fs.readdirSync("src/db/seeds")

      return `${files.length + 1}_`
    }
  }
})

Adding also a sample seed file in case it helps:

// Omitting the implementation of the service for the sake of simplicity.
import { CreateUserService } from "@src/components/users/services/createUser"
import type { Kysely } from "kysely"
import moment from "moment"
import { DB } from "../generated/types/db"

export async function seed(_: Kysely<DB>): Promise<void> {
  await new CreateUserService({
    email: "[email protected]",
    password: "P@ssw0rd",
    birthDate: moment("2000-01-23").toDate(),
    name: "Foo Bar"
  }).call()
}

Migrations and seeds' execution work fine, i.e. they modify/populate the database correctly, but the issue is more around the command kysely seed run which never stops its execution. This is messing up with the following script to start my server because it's running one instruction after the previous one finishes it's execution:

# For the sake of simplicity, I'm omitting `build` script.
# Also, kysely:seed:run is the alias I use in my package.json for `kysely seed run`.
npm run build && npm run kysely:seed:run && node dist/src/index.js

This is a sample output of what I see after running the command, I have to manually stop the execution:

image
@SergioMD15 SergioMD15 changed the title seed run won't close the process after completing Command seed run won't close the process after completing Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant