supabase / cli

Supabase CLI. Manage postgres migrations, run Supabase locally, deploy edge functions. Postgres backups. Generating types from your database schema.
https://supabase.com/docs/reference/cli/about
MIT License
1.07k stars 209 forks source link

supabase db diff --use-migra generates same grants in all generations #2488

Open terion-name opened 4 months ago

terion-name commented 4 months ago

Bug report

Describe the bug

supabase db diff --use-migra generates same grants in all generations

To Reproduce

Take migration files from attachments. migrations.zip The problem is already seen there – in last 3 migrations you see the same grants:

grant delete on table "public"."test" to "postgres";
grant insert on table "public"."test" to "postgres";
grant references on table "public"."test" to "postgres";
grant select on table "public"."test" to "postgres";
grant trigger on table "public"."test" to "postgres";
grant truncate on table "public"."test" to "postgres";
grant update on table "public"."test" to "postgres";
grant delete on table "public"."test2" to "postgres";
grant insert on table "public"."test2" to "postgres";
grant references on table "public"."test2" to "postgres";
grant select on table "public"."test2" to "postgres";
grant trigger on table "public"."test2" to "postgres";
grant truncate on table "public"."test2" to "postgres";
grant update on table "public"."test2" to "postgres";

Used script:

{
  "scripts": {
    "db:dump": "dotenv -- cross-var supabase db diff --use-migra -f initial_schema --db-url=%POSTGRES_URL%",
  },
  "devDependencies": {
    "cross-var": "^1.1.0",
    "dotenv-cli": "^7.4.2"
  }
}

Running db:dump multiple times creates new same files

Expected behavior

Grants migrations are not duplicated

System information

avallete commented 2 months ago

It seems that this bug has already been fixed in the latest version of the Supabase CLI.

I wanted to take a look at this, so I tried to reproduce the issue locally by following the steps outlined in the migrations attached to this issue. After running the following command:

npx supabase db diff --use-migra -f initial_schema

on Supabase CLI version 1.191.3, the result was as expected:

No schema changes found

Additionally, after adding an extra column to the "test" table and running the command again, the generated migration contained only the ALTER TABLE instruction, which is the expected behavior.

It appears this issue has been resolved in the newer versions. Could you please confirm if this is also solved on your end so we can close this issue?