Migration squash does not include data added to migration file
Describe the bug Up till this point, we have assumed all migrations are schema migrations. However, there are cases where it's useful to insert specific data into the db using a migration. For example, you may want to initialise a lookup table, or update existing rows with a default value before adding a not-null constraint.
Not sure what is the best way to support data migrations, but here are a few ideas to start with:
- Run data migration from application bootstrap code
- Run sql manually or via cli hook
- Interleave data migration in existing schema migration file
To Reproduce Steps to reproduce the behavior:
echo 'create table test(name text)' | supabase migration new
echo 'insert into test(name) values("Ant")' | supabase migration new
supabase db push
supabase migration squash
Expected behavior
Squashed migration should contain inserted data, ie. insert into test(name) values("Ant")
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: [e.g. iOS]
- Browser (if applicable) [e.g. chrome, safari]
- Version of CLI [e.g. v1.60.0]
- Version of supabase-js (if applicable) [e.g. v2.22.0]
- Version of Node.js (if applicable) [e.g. v16.20.0]
Additional context Add any other context about the problem here.
I think I can add something to this Issue:
I have a migration setting up the stripe wrapper like this:
SELECT
pgsodium.create_key(name := 'stripe');
DO $$
DECLARE
key_id text;
BEGIN
SELECT
id INTO key_id
FROM
pgsodium.valid_key
WHERE
name = 'stripe'
LIMIT 1;
EXECUTE format(E'create server stripe_server foreign data wrapper stripe_wrapper options (api_key_id ''%s'');', key_id);
END
$$;
This part is gone after doing supabase migration squash but without it I get an error that there is no stripe_server
Maybe there is just a better way to setup wrappers in a migration? That was the only way I was able to do it in a reproduceable way.
merging this with another related issue https://github.com/supabase/cli/issues/1618