halvardssm / deno-nessie

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

[IDEA]: Add foundation when creating a seed or migration and remove raw imports #138

Closed ebebbington closed 2 years ago

ebebbington commented 3 years ago

The Idea

I think it would be nice to add some more foundation into these files when they are created, just to save the developer a bit more time, eg creating a migration would result in

// Assume i ran `nessie make:migration create_users_table`
import { AbstractSeed, Info, ClientPostgreSQL } from "https://deno.land/x/nessie@2.0.1/mod.ts";

export default class extends AbstractSeed<ClientPostgreSQL> {
    /** Runs on seed */
    async run(info: Info): Promise<void> {
      this.client.queryArray(`<type> TABLE <table> (
        ... // place your code here
      )`)
    }
}

Also it'd be nice for the imports to use a local deps.ts, most people use a deps.ts at root level so i think it'll be safe to do import { ... } from "../../deps.ts", this does shave off some time for the user and makes it's that bit more faster to create a migration or seed

ebebbington commented 3 years ago

Happy to work on a pr should you agree

halvardssm commented 3 years ago

Hi @ebebbington ! For the first part: Do you mean that we should have a way to automatically generate seed files for the migrations we create? For the second part: we could add an optional property to the config object for auto adding the deps file, and I am happy to review PRs!

ebebbington commented 3 years ago

Hi @ebebbington ! For the first part: Do you mean that we should have a way to automatically generate seed files for the migrations we create? For the second part: we could add an optional property to the config object for auto adding the deps file, and I am happy to review PRs!

  1. Yeah, kinda, it applies to both seeders and migrations i guess, it's a matter of being able to specify the 'skeleton sql query' in the run() method, so nessie would try get the type of query and table name from the path, eg create_users_table may result in this.client.queryArray('CREATE table users') but after thinking about it, is this really worth it?

  2. To be honest, i think it's better to auto adding to deps.ts be the default, because im sure the high majority of people dont use imports from urls in a file other than deps.ts

halvardssm commented 2 years ago

@ebebbington Finally a weekend where I have time to look over issues 😅

  1. I don't think this amount of automation is fit for the Nessie project, but it could be an extension? As always, I'm happy to review some PR's or code examples if you have a clear idea in mind 😄
  2. I am not comfortable auto importing deps.ts, mainly due to the case that there is no set way of working with Deno, hence there might be multiple unorthodox ways of providing imports amongst the users. That being said, I would be interested in providing an optional param to set a custom deps.ts import considering users might use different versions of the components.

I will have some more time coming up to review PR's and issues, but I won't be adding any more code for the time being (except for deps version updates), so feel free to submit a PR!

halvardssm commented 2 years ago

@ebebbington Custom migration and seed templates are now available in Nessie 2.0.4. Let me know if this is sufficient for this issue 😄