-
-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some SQL statements generate from supabase db diff
are ordered in an unexecutable way
#496
Comments
Hello @dshukertjr , could you try diffing with supabase db diff --use-migra create_tables -f create_tables Here's the generated output on my local dev: SQL statementscreate type "public"."user_status" as enum ('ONLINE', 'OFFLINE');
create table "public"."channels" (
"id" bigint generated by default as identity not null,
"data" jsonb,
"slug" text
);
create table "public"."messages" (
"id" bigint generated by default as identity not null,
"data" jsonb,
"message" text,
"username" text not null,
"channel_id" bigint not null,
"inserted_at" timestamp with time zone not null default timezone('utc'::text, now())
);
create table "public"."reactions" (
"id" bigint generated by default as identity not null,
"emoji" text not null,
"message_id" bigint not null,
"created_at" timestamp with time zone not null default timezone('utc'::text, now())
);
create table "public"."users" (
"username" text not null,
"data" jsonb,
"age_range" int4range,
"status" user_status default 'ONLINE'::user_status,
"catchphrase" tsvector,
"interests" text[]
);
CREATE UNIQUE INDEX channels_pkey ON public.channels USING btree (id);
CREATE UNIQUE INDEX messages_pkey ON public.messages USING btree (id);
CREATE UNIQUE INDEX reactions_pkey ON public.reactions USING btree (id);
CREATE UNIQUE INDEX users_pkey ON public.users USING btree (username);
alter table "public"."channels" add constraint "channels_pkey" PRIMARY KEY using index "channels_pkey";
alter table "public"."messages" add constraint "messages_pkey" PRIMARY KEY using index "messages_pkey";
alter table "public"."reactions" add constraint "reactions_pkey" PRIMARY KEY using index "reactions_pkey";
alter table "public"."users" add constraint "users_pkey" PRIMARY KEY using index "users_pkey";
alter table "public"."messages" add constraint "messages_channel_id_fkey" FOREIGN KEY (channel_id) REFERENCES channels(id) not valid;
alter table "public"."messages" validate constraint "messages_channel_id_fkey";
alter table "public"."messages" add constraint "messages_username_fkey" FOREIGN KEY (username) REFERENCES users(username) not valid;
alter table "public"."messages" validate constraint "messages_username_fkey";
alter table "public"."reactions" add constraint "reactions_message_id_fkey" FOREIGN KEY (message_id) REFERENCES messages(id) not valid;
alter table "public"."reactions" validate constraint "reactions_message_id_fkey";
set check_function_bodies = off;
CREATE OR REPLACE FUNCTION public.get_status(name_param text)
RETURNS user_status
LANGUAGE sql
IMMUTABLE
AS $function$
SELECT status from users WHERE username=name_param;
$function$
;
CREATE OR REPLACE FUNCTION public.get_username_and_status(name_param text)
RETURNS TABLE(username text, status user_status)
LANGUAGE sql
IMMUTABLE
AS $function$
SELECT username, status from users WHERE username=name_param;
$function$
;
CREATE OR REPLACE FUNCTION public.void_func()
RETURNS void
LANGUAGE sql
AS $function$
$function$
; We are leaning towards defaulting to migra in the future if it works for most people. So please also let us know if you find anything missing from migra generated diff. For eg. #420 (comment) |
Feel free to reopen if this is still a blocker for you. |
Thanks! Using |
Bug report
Describe the bug
Sorry if I'm missing something obvious, but SQL statements produced by
supabase db diff
seems to be ordered in an unexecutable way. For example,create table
statement might be placed after a function definition that depends on the table. Using v1.5.4 of the CLI.To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
supabase start
SQL statements
supabase db diff create_tables -f create_tables
supabase db reset
, which fails, because order of the SQL statements.SQL statements that get generated
Expected behavior
After running
supabase db diff
to generate the migration file, we should be able to runsupabase db reset
.System information
The text was updated successfully, but these errors were encountered: