Skip to content

Add hooks to cli commands #501

Closed as not planned
Closed as not planned

Description

@osaxma

Feature request

Is your feature request related to a problem? Please describe.

Currently, when I would like to run a command before or after certain supabase cli commands, I've to run that manually or write a script to run both commands.

Describe the solution you'd like

It would be useful if we could hook commands to supabase cli commands. One idea comes to mind is to define them within the config.toml such as:

[hooks]

post_start='psql postgresql://postgres:postgres@localhost:54322/postgres < custom_seed.sql'
post_start='dart run generate_types.dart'

post_db_reset='dart run generate_types.dart'

pre_stop='pg_dump postgresql://postgres:postgres@localhost:54322/postgres -n public > dumps/schema_dump.sql' 

excuse my poor toml -- I'm sure this could be structured in a better way for sub-commands (e.g. supabase db reset).

In the above example, the idea is that each lifecycle command (e.g. stop, start, reset) can have pre- or post-hook(s).

Activity

  1. sweatybridge commented on Oct 14, 2022

    @sweatybridge
    Contributor

    Also related is #160 which asks for pre/post-migration sql files.

  2. NixBiks commented on Jan 11, 2023

    @NixBiks
    Contributor

    Would be great with an example where a seed.ts file is executed after resetting the db. I always run into TS config issues with imports etc. I imagine I'm not the only one

  3. carlassmann commented on Jan 24, 2023

    @carlassmann

    @NixBiks as you might have Deno set up in your workspace for functions anyway, using Deno for the seed script is quite comfortable.

    supabase start && deno run --allow-read=. --allow-net scripts/seed.ts

  4. mosnicholas commented on Mar 7, 2023

    @mosnicholas
    Contributor

    would love to know if there have been more thoughts on this topic? Particularly for seed files. My seed.sql is getting really large, would be very helpful to be able to split it up a bit and simplify

  5. isaacharrisholt commented on Mar 16, 2023

    @isaacharrisholt

    @mosnicholas we ran into this problem too, so we just wrote a little script that'll read CSVs from a supabase/seeds directory and create a load of insert statements in the seeds.sql file.

    You can also have pre-seed.sql and post-seed.sql for running any other SQL you need (extensions etc.).

    If you name files 1-foo.csv, 2-bar.csv, the numbering will be respected (and 10 will come after 9, not 1... thanks ascii...).

    Code is here: https://gist.github.com/isaacharrisholt/8b92d21429e2981827795c5e29763a5f

  6. mosnicholas commented on Mar 16, 2023

    @mosnicholas
    Contributor

    oh wow nice idea :) when / how are you running it @isaacharrisholt ?

  7. isaacharrisholt commented on Mar 16, 2023

    @isaacharrisholt

    @mosnicholas we run it using a pre-commit hook with the following:

    bash -c 'cd scripts/csv-seeder; go run main.go ../../supabase'

    But you could also do it in CI and push the changes to the branch, like you might do with supabase gen types.

    One thing you have to be careful with is that it'll create insert statements exactly how you've written the CSVs - it won't add quotes or anything. This is handy though, because you can call postgres functions. If the following file is user.csv:

    id,uuid,date,name
    1,gen_random_uuid(),now(),'Isaac'

    Then it'll generate:

    INSERT INTO user (id, uuid, date, name)
    VALUES (1, gen_random_uuid(), now(), 'Isaac');
  8. ydennisy commented on Jun 27, 2023

    @ydennisy

    Any updates here? :)

  9. psteinroe commented on Dec 13, 2023

    @psteinroe

    would love a pre-migrations hook to run externally managed migrations e.g. for graphile/worker.

  10. logemann commented on Jan 15, 2024

    @logemann

    This feature req would also be the best way to seed files into storage right? I really would like to have some files already present on starting local dev.

  11. lauri865 commented on Feb 6, 2024

    @lauri865

    This would be great. We already have custom scripts for e.g. seeding storage, and now looking to run idempotent migrations for some stuff like webhooks, and so fort. Would be great to pipe them into the CLI workflows, as custom scripts can be easy to forgotten / accidentially bypassed in the team.

  12. logemann commented on Jul 30, 2024

    @logemann

    This would be great. We already have custom scripts for e.g. seeding storage

    how do you approached seeding storage? I really would like to see a feature lfrom supabase ike seed-storage.yml where we just define the files together with the fileURL and map them to the buckets created in seed.sql. This way we could db reset everything and have a full running DB with storage again...

  13. jackd commented on May 12, 2025

    @jackd

    I realize this is a fairly old issue, but for anyone coming across it, you can now split your seed across multiple files and seed storage shows how to seed storage.

    AFAIK seed files are run before storage objects are added, so hooks as requested in this issue would still have benefits even in this scope, e.g. to populate tables that link to storage.objects.

  14. github-actions commented on Jun 17, 2026

    @github-actions
    Contributor

    Hi! Thanks for opening this issue.

    We're closing this because it has not had any activity for 45 days, and we try to keep the Supabase CLI issue tracker focused on reports that are still current.

    If this still reproduces on the latest Supabase CLI, please comment with /reopen on its own line and include your CLI version, updated reproduction steps, and any recent error output. We appreciate the signal and are happy to take another look.

  15. edurenye commented on Jun 18, 2026

    @edurenye

    We still want this feature

  16. jgoux commented on Jun 23, 2026

    @jgoux
    Contributor

    /reopen

  17. github-actions commented on Aug 8, 2026

    @github-actions
    Contributor

    Hi! Thanks for opening this issue.

    We're closing this because it has not had any activity for 45 days, and we try to keep the Supabase CLI issue tracker focused on reports that are still current.

    If this still reproduces on the latest Supabase CLI, please comment with /reopen on its own line and include your CLI version, updated reproduction steps, and any recent error output. We appreciate the signal and are happy to take another look.

  18. edurenye commented on Aug 8, 2026

    @edurenye

    Would still be nice to have

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions