graphile / migrate

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

Wrap included files with include comment #211

Open astephensen opened 7 months ago

astephensen commented 7 months ago

Description

This PR will wrap included files with comments, as first described in https://github.com/graphile/migrate/issues/208.

This also facilitates removing the included content when performing an uncommit.

Have opened as a draft as I'm open to any and all feedback!

Pre-Commit

select 'foo';
--!include functions/hello.sql
create or replace function public.hello() returns text as $$
  select 'Hello, world!';
$$ language sql;

Committed

--! Previous: -
--! Hash: sha1:2d5fea0f4300a51ebf5c9d2416def4f2d22563d3
--! Message: World

select 'foo';
--! Included functions/hello.sql
create or replace function public.hello() returns text as $$
  select 'Hello, world!';
$$ language sql;
--! EndIncluded functions/hello.sql

Uncommitted

--! Message: World

select 'foo';
--!include functions/hello.sql

Implementation

The method I implemented is similar to what @jcgsville described in the original issue, with a few little changes.

The main downside of this approach is the original formatting of the --!include is not preseved, i.e. if the include is written as --! include ... the migration will not restore the additional whitespace when uncommitting.

Notes

Performance impact

unknown - likely minimal.

Security impact

unknown - likely none.

Checklist

jcgsville commented 7 months ago

Thanks for taking a stab at this, @astephensen 🙂

benjie commented 6 months ago

I had to run prettier across a lot of files that I didn't touch — not sure if this was missed in a previous PR or if I didn't have it configured correctly locally, but it was causing the tests to fail.

I think you must have it misconfigured (older prettier version?) - use yarn && yarn lint:fix to fix formatting issues.

astephensen commented 6 months ago

Thanks for the review @benjie, I will address those comments!