Skip to content

Commit

Permalink
update schema
Browse files Browse the repository at this point in the history
  • Loading branch information
YousefED committed May 15, 2024
1 parent 2b1250d commit f554d37
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"unittest:vitest": "vitest run",
"unittest:playwright": "playwright-test '**/*.browsertest.ts' --runner mocha",
"test": "npm run unittest:vitest && npm run unittest:playwright",
"gentypes": "./supabase.sh gen types typescript --local --schema public > ../shared/src/schema.ts",
"gentypes": "./supabase.sh gen types typescript --db-url=postgresql://postgres:postgres@localhost:54322 --schema public > ../shared/src/schema.ts",
"migrate": "./supabase.sh migration new newmigation_file",
"diff": "./supabase.sh db diff",
"lint": "eslint src"
Expand Down
99 changes: 94 additions & 5 deletions packages/shared/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type Json =
| { [key: string]: Json | undefined }
| Json[]

export interface Database {
export type Database = {
public: {
Tables: {
document_permissions: {
Expand All @@ -29,15 +29,17 @@ export interface Database {
{
foreignKeyName: "document_permissions_document_id_fkey"
columns: ["document_id"]
isOneToOne: false
referencedRelation: "documents"
referencedColumns: ["id"]
},
{
foreignKeyName: "document_permissions_user_id_fkey"
columns: ["user_id"]
isOneToOne: false
referencedRelation: "users"
referencedColumns: ["id"]
}
},
]
}
document_relations: {
Expand All @@ -57,15 +59,17 @@ export interface Database {
{
foreignKeyName: "document_relations_child_id_fkey"
columns: ["child_id"]
isOneToOne: false
referencedRelation: "documents"
referencedColumns: ["id"]
},
{
foreignKeyName: "document_relations_parent_id_fkey"
columns: ["parent_id"]
isOneToOne: false
referencedRelation: "documents"
referencedColumns: ["id"]
}
},
]
}
documents: {
Expand Down Expand Up @@ -100,9 +104,10 @@ export interface Database {
{
foreignKeyName: "documents_user_id_fkey"
columns: ["user_id"]
isOneToOne: false
referencedRelation: "users"
referencedColumns: ["id"]
}
},
]
}
workspaces: {
Expand Down Expand Up @@ -134,15 +139,17 @@ export interface Database {
{
foreignKeyName: "workspaces_document_nano_id_fkey"
columns: ["document_nano_id"]
isOneToOne: false
referencedRelation: "documents"
referencedColumns: ["nano_id"]
},
{
foreignKeyName: "workspaces_owner_user_id_fkey"
columns: ["owner_user_id"]
isOneToOne: false
referencedRelation: "users"
referencedColumns: ["id"]
}
},
]
}
}
Expand All @@ -167,3 +174,85 @@ export interface Database {
}
}

type PublicSchema = Database[Extract<keyof Database, "public">]

export type Tables<
PublicTableNameOrOptions extends
| keyof (PublicSchema["Tables"] & PublicSchema["Views"])
| { schema: keyof Database },
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
? keyof (Database[PublicTableNameOrOptions["schema"]]["Tables"] &
Database[PublicTableNameOrOptions["schema"]]["Views"])
: never = never,
> = PublicTableNameOrOptions extends { schema: keyof Database }
? (Database[PublicTableNameOrOptions["schema"]]["Tables"] &
Database[PublicTableNameOrOptions["schema"]]["Views"])[TableName] extends {
Row: infer R
}
? R
: never
: PublicTableNameOrOptions extends keyof (PublicSchema["Tables"] &
PublicSchema["Views"])
? (PublicSchema["Tables"] &
PublicSchema["Views"])[PublicTableNameOrOptions] extends {
Row: infer R
}
? R
: never
: never

export type TablesInsert<
PublicTableNameOrOptions extends
| keyof PublicSchema["Tables"]
| { schema: keyof Database },
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"]
: never = never,
> = PublicTableNameOrOptions extends { schema: keyof Database }
? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends {
Insert: infer I
}
? I
: never
: PublicTableNameOrOptions extends keyof PublicSchema["Tables"]
? PublicSchema["Tables"][PublicTableNameOrOptions] extends {
Insert: infer I
}
? I
: never
: never

export type TablesUpdate<
PublicTableNameOrOptions extends
| keyof PublicSchema["Tables"]
| { schema: keyof Database },
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"]
: never = never,
> = PublicTableNameOrOptions extends { schema: keyof Database }
? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends {
Update: infer U
}
? U
: never
: PublicTableNameOrOptions extends keyof PublicSchema["Tables"]
? PublicSchema["Tables"][PublicTableNameOrOptions] extends {
Update: infer U
}
? U
: never
: never

export type Enums<
PublicEnumNameOrOptions extends
| keyof PublicSchema["Enums"]
| { schema: keyof Database },
EnumName extends PublicEnumNameOrOptions extends { schema: keyof Database }
? keyof Database[PublicEnumNameOrOptions["schema"]]["Enums"]
: never = never,
> = PublicEnumNameOrOptions extends { schema: keyof Database }
? Database[PublicEnumNameOrOptions["schema"]]["Enums"][EnumName]
: PublicEnumNameOrOptions extends keyof PublicSchema["Enums"]
? PublicSchema["Enums"][PublicEnumNameOrOptions]
: never

0 comments on commit f554d37

Please sign in to comment.