Raw sql in schema

Hello! I'm trying to reference the supabase auth table as mentioned in the supabase docs (https://supabase.com/docs/guides/auth/managing-user-data):

create table public.profiles (
  id uuid not null references auth.users on delete cascade,
  first_name text,
  last_name text,

  primary key (id)
);


Here's what I have:
export const users = pgTable('users', {
  id: sql`uuid not null references auth.users on delete cascade`,
});


But I guess I'm not doing it correctly as Ts complains:
Type 'SQL<unknown>' is not assignable to type 'PgColumnBuilderBase<ColumnBuilderBaseConfig<ColumnDataType, string>, object>'.
  Types of property '_' are incompatible.
    Type '{ brand: "SQL"; type: unknown; }' is missing the following properties from type '{ brand: "ColumnBuilder"; name: string; dataType: ColumnDataType; columnType: string; data: unknown; driverParam: unknown; notNull: boolean; hasDefault: boolean; enumValues: string[] | undefined; dialect: "pg"; }': name, dataType, columnType, data, and 5 more.ts(2322)


I'm aware there are other "solutions" to this problem of referencing the auth table that involve editing the generated SQL afterwards, but would prefer if I could somehow define the raw sql in the schema itself

Thanks in advance
Was this page helpful?