graphile / migrate

Opinionated SQL-powered productive roll-forward migration tool for PostgreSQL.
MIT License
751 stars 58 forks source link

[Feature Request] 'seed' or 'run' command #37

Closed pixelpax closed 4 years ago

pixelpax commented 4 years ago

This isn't difficult to do as-is, but would be a great convenience command to just programmatically run an arbitrary sql file against the database.

My team likes to have a few different seed.sql files to test different situations with, and it'd be nice to be able to use graphile/migrate's settings and pgClient to do this for convenience and consistency. That way we could easily create quick one liners that can reset and seed the database in different ways for testing and development across environments.

Something like the following to run arbitrary strings:

export const runOnDb = async (
  sql: string,
  shadow: boolean,
  filename?: string,
) => {
  const parsedSettings = await parseSettings(getSettings(), shadow);
  withClient(
    parsedSettings.connectionString,
    parsedSettings,
    async (pgClient: PoolClient, context: Context) => {
      await runStringMigration(
        pgClient,
        parsedSettings,
        context,
        sql,
        filename || '',
      );
    },
  );
};

Would be low hanging fruit from existing commands.

benjie commented 4 years ago

graphile-migrate run blah.sql seems quite legit; doing all the parameter substitution, setting settings, etc. This seems a good idea.

pixelpax commented 4 years ago

Nice! Cool, I can take this but it might take a couple weeks for it to get to the front of my queue.

benjie commented 4 years ago

Sure; there’s no rush :)