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

Add a --help command, more verbose console logs, make dir if not present, and load before apply automatically. #9

Closed
wants to merge 1 commit into from
Closed

Conversation

kerimhudson
Copy link

@kerimhudson kerimhudson commented Mar 23, 2024

Hopefully this resolves #8 a little bit. I'm opening this as a starting point for some ideas for which I think would make it easier for someone to pick this up quicker.

More verbose console logs.

This introduces some more verbose console logs, with some instructions to help people pick up what to do next. It also adds a --help flag which can be used on the root, which explains a little more how to use this tool.

For example, now when init is used it gives you some steps on how to proceed.

Make directory if it doesn't exist

Just a nice to have where if you specify a directory for the migrationsDir and it doesn't exist, it generates it.

Combining apply and load

This introduces the load function into apply, so that rather than having it as two steps it just does it all at once.

…grations, add a --help command, and make logs a little more verbose
Copy link
Member

@KyleJune KyleJune left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is doing too many different things at the moment.

If you want to get these changes in, it should be 3 PRs.

  1. The logger changes, which I have given feedback on. This could include adding the help command.
  2. The change for automating making the directory if it doesn't exist, which I've also given feedback on.
  3. Removing the need to call load directly. For that last one, the load command should be removed in favor of the function that handles loading being called by all the other commands except for the init command.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm against the addition of this file. Rather than using a custom wrapper around console.log, I'd rather switch to using std/log from deno. On the page linked below, it has an example for module authors.

https://deno.land/[email protected]/log/mod.ts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If switching to use logger.info and logger.error, we shouldn't be adding any color or prefixes ourselves. I believe if someone wants to format their logs a certain way, they can do so with log.setup.

For example, I'd be okay with replacing console.log("Connecting to database") with logger.info("Connecting to database"). I'm also okay with general message improvements. But I don't want to add a bunch of prefixes for the various commands like this PR currently does.

Copy link
Member

@KyleJune KyleJune Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the logger name, go with "@udibo/migrate".

Comment on lines +176 to +180
function createMigrationDirectoryIfNotExists(
migrationsDir: string | undefined,
) {
throw new Error("Function not implemented.");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function isn't needed. Deno's standard library includes one for ensuring a directory exists. Just use that.
https://deno.land/[email protected]/fs/ensure_dir.ts

Comment on lines +30 to +33
logger(
"error",
"Migration table already exists. Have you already initialized migrate?",
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer errors not ask a question. I'd just have it say 'Already initialized'.


logger(
"init",
"Database has been initialised with migrations table and migration timestamp trigger.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to give this much detail. I think just saying something like "Created table for tracking migrations" would be fine.

Comment on lines 333 to +338
} else {
console.log("command not found");
if (command == "--help") {
help();
} else {
logger("error", "Command not found or missing argument.");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to else if for the help command and else for the log regarding command not found.

Comment on lines +286 to +300
logger(
"info",
"Migrate allows you to manage your postgres migrations via the CLI and files in your codebase",
);
logger(
"init",
"init allows you to initialize your project and creates a migrations table in your database.",
);
logger(
"load",
"load allows you to add migrations to your database but not run them",
);
logger("apply", "apply loads and migrates any unmigrated migrations");
logger("list", "list shows you all your migration files and their status");
logger("status", "status gives you an overview of your migrations");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If adding a help command. It should log one message saying "Commands:" Followed by other messages with 2 leading spaces that have the list of commands with the descriptions. Similar to what deno does. You can use padEnd to make all the commands have spacing after them that makes them all line up. No need to do coloring for this.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd
image

@kerimhudson
Copy link
Author

Thanks for the feedback. I'm going on holiday for a couple of weeks but will pick it up when I'm back.

@kerimhudson kerimhudson closed this by deleting the head repository Jun 1, 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

Successfully merging this pull request may close these issues.

Confusing installation steps
2 participants