graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

[request] Add pre/post migration SQL hooks

Open jflambert opened this issue 1 year ago • 3 comments

Is your proposal related to a problem?

I would like to run a set of SQL instructions before and after Hasura runs its migrations.

Describe the solution you'd like

maybe specific files in the migrations folder that are dedicated to pre/post migrations

for example hasura/migrations/pre.sql and hasura/migrations/post.sql

Also, presumably post.sql should only run when migrations are successful? Or maybe make that an option.

Describe alternatives you've considered

None so far. Just recently realized I need this.

If the feature is approved, would you be willing to submit a PR?

No

jflambert avatar Oct 06 '22 17:10 jflambert

The names setup.sql and teardown.sql might also be good

As for use cases, how about sending a pg_notify broadcast that the DB is under "maintenance". In my case I want to pause some timescaledb jobs.

jflambert avatar Oct 06 '22 17:10 jflambert

Not sure why you can't achieve this with transactions? For example:

-- setup hook
BEGIN;
  -- do something here, ie.
  PERFORM pg_notify('platform_event', 'Maintenance in progress');
  ...
COMMIT;

-- migration
BEGIN;
alter table ....
COMMIT;

-- teardown
BEGIN;
  -- do something post migration
  PERFORM pg_notify('platform_event', 'Maintenance completed');
COMMIT;

mirzap avatar Oct 07 '22 09:10 mirzap

no I want a single pre/post for all migrations

pre.sql migrations (100 files) post.sql

jflambert avatar Oct 07 '22 11:10 jflambert