graphile / migrate

Opinionated SQL-powered productive roll-forward migration tool for PostgreSQL.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gmrc `connectionString` should be ignored if `DATABASE_URL` exists in the env

samlevin opened this issue · comments

Hey Benjie. We've nearly completed our adoption of graphile-migrate and as a team, we're loving it. A lot of great philosophies at play. Awesome work all around.

Our development team has a 'zero config' dev environment philosophy where a lot of settings are hard-coded to repositories (with insecure defaults). We're trying to replicate this for graphile-migrate but the migrate command appears to be preferring connectionString - even though DATABASE_URL exists.

Thoughts? ENV var precedence is fairly typical in the config world. Am I right in assuming that migrate would/should follow suit?

No; explicit always wins over implicit. If you provide a connection string explicitly via the Graphile Migrate config file then that will override the implicit and generic environmental variable DATABASE_URL that may have come from anywhere and could relate to some other service such as PostGraphile or Graphile Worker or even a completely different project.

Perhaps there's an alternative way we can solve this; for example a .js config file where you can set connectionString: process.env.DATABASE_URL || "fallback"

This'd be the place to apply that change:

export const GMRC_PATH = `${process.cwd()}/.gmrc`;
export async function getSettings(): Promise<Settings> {
let data;
try {
data = await fsp.readFile(GMRC_PATH, "utf8");
} catch (e) {
throw new Error(
"No .gmrc file found; please run `graphile-migrate init` first.",
);
}
try {
return JSON5.parse(data);
} catch (e) {
throw new Error("Failed to parse .gmrc file: " + e.message);
}
}

I think read .gmrc if present, otherwise try .gmrc.js.