Skip to content

Commit

Permalink
adds database types
Browse files Browse the repository at this point in the history
  • Loading branch information
wmalarski committed Oct 29, 2023
1 parent fe39b97 commit 44def65
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/db/setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
create table public."Task" (
id bigint generated by default as identity,
created_at timestamp with time zone null default now(),
text text null,
user_id uuid not null,
finished boolean null default false,
constraint Task_pkey primary key (id),
constraint Task_user_id_fkey foreign key (user_id) references auth.users (id) on delete cascade
) tablespace pg_default;

CREATE POLICY "Enable all for users based on user_id" ON "public"."Task" AS PERMISSIVE FOR ALL TO public USING (auth.uid() = user_id) WITH CHECK (auth.uid() = user_id)
3 changes: 2 additions & 1 deletion src/server/supabase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createClient } from "@supabase/supabase-js";
import type { SupabaseAuthClientOptions } from "@supabase/supabase-js/dist/module/lib/types";
import { parse, serialize } from "cookie";
import { Database } from "./types";

const options = {
httpOnly: true,
Expand Down Expand Up @@ -40,7 +41,7 @@ const getCookieStorage = ({
};

export const initSupabase = (args: InitSupabaseArgs) => {
return createClient(
return createClient<Database>(
import.meta.env.VITE_PUBLIC_SUPABASE_URL,
import.meta.env.VITE_PUBLIC_SUPABASE_ANON_KEY,
{ auth: { flowType: "pkce", storage: getCookieStorage(args) } },
Expand Down
57 changes: 57 additions & 0 deletions src/server/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
export type Json =
| string
| number
| boolean
| null
| { [key: string]: Json | undefined }
| Json[];

export interface Database {
public: {
Tables: {
Task: {
Row: {
created_at: string | null;
finished: boolean | null;
id: number;
text: string | null;
user_id: string;
};
Insert: {
created_at?: string | null;
finished?: boolean | null;
id?: number;
text?: string | null;
user_id: string;
};
Update: {
created_at?: string | null;
finished?: boolean | null;
id?: number;
text?: string | null;
user_id?: string;
};
Relationships: [
{
foreignKeyName: "Task_user_id_fkey";
columns: ["user_id"];
referencedRelation: "users";
referencedColumns: ["id"];
},
];
};
};
Views: {
[_ in never]: never;
};
Functions: {
[_ in never]: never;
};
Enums: {
[_ in never]: never;
};
CompositeTypes: {
[_ in never]: never;
};
};
}

0 comments on commit 44def65

Please sign in to comment.