halvardssm / deno-nessie

A modular Deno library for PostgreSQL, MySQL, MariaDB and SQLite migrations
MIT License
527 stars 31 forks source link

[BUG] nessie.config.ts migrationFolder and seedFolder paths not taking effect #82

Closed gaylonalfano closed 4 years ago

gaylonalfano commented 4 years ago

System (please complete the following information):

Describe the bug When I initialize Nessie running the standard command: deno run --allow-net --allow-read --allow-write https://deno.land/x/nessie/cli.ts init, it creates a project/db directory inside my current working directory (project), as well as the default nessie.config.ts file (project/nessie.config.ts). That seems standard and no issue there.

However, if I want to store my migrations and seeds into a different directory/path structure by changing the migrationFolder and seedFolder paths, it does not seem to work.

Here is my current project/nessie.config.ts config:

import { ClientOptions, ClientPostgreSQL, ConnectionOptions } from "./deps.ts";
import config from "./src/app/config/config.ts";

/** These are the default config options. */
const nessieOptions: ClientOptions = {
  migrationFolder: "./src/app/db/migrations",
  seedFolder: "./src/app/db/seeds",
  experimental: true,
};

// Official example imports deno-postgres ConnectionOptions
// https://github.com/halvardssm/deno-nessie/blob/master/examples/config-postgres.ts
const connectionConfig: ConnectionOptions = {
  database: config.DB_DATABASE,
  hostname: config.DB_HOST,
  port: +config.DB_PORT,
  user: config.DB_USER,
  password: config.DB_PASSWORD,
};

export default {
  nessiePostgresClient: new ClientPostgreSQL(nessieOptions, connectionConfig),
};

To Reproduce Steps to reproduce the behavior:

  1. For example, I can change the default migrationFolder: "./db/migrations" to, say, migrationFolder: "./src/app/db/migrations" and seedFolder: "./src/app/db/seeds".

  2. I save my changes in nessie.config.ts and then, inside my project root folder, I run my first make [name] command to create my first migration: deno run --allow-net --allow-read --allow-write https://deno.land/x/nessie/cli.ts make create_users. After this command runs, I still end up with a project/db/migrations/12345_create_users.ts file, instead of my preferred and configured path of project/src/app/db/migrations/12345_create_users.ts.

  3. It's only when I run the Nessie command from my project/src/app directory, does Nessie create the nested project/src/app/db/migrations and project/src/app/db/seeds directories.

Expected behavior My expectation is that my nessie configuration will create my nested directories and store the new migration file inside project/src/app/db/migrations/11111_create_users.ts. However, it instead saves the migration file inside project/db/migrations/11111_create_users.ts. I have even deleted the default ./db directory (created when I first ran init with Nessie) and re-ran the make [name] to create another migration. It still doesn't seem to use the paths specified in my nessie.config.ts file.

Perhaps I'm missing something. I just assumed that my nessie.config.ts config would store my migration files and seed files in the relative paths I specify for migrationsFolder and seedFolder, but perhaps I'm missing something. For now, I just make sure I am in my project/src/app directory before I run any Nessie commands. Please let me know if I can provide anything else.

gaylonalfano commented 4 years ago

Okay, I may have resolved the directory issue by using the --reload flag. I'm still trying it out but it seems like I can now run my Nessie commands and the custom paths I configure for migrations and seeds are working. I'll test a bit more and then close.

Update - Yep, the migrationFolder and seedFolder settings are now taking effect now that I re-ran the --reload flag. I need to research more on when it's a good idea to re-run --reload. Thanks!