Database file generated doesn't output correct type for TIMESTAMP(0)
anshul-kai opened this issue · 2 comments
Bug report
- I confirm this is a bug with Supabase, not with my own application.
- I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
Database file generated using the dashboard or the command line doesn't generate correct data types for TIMESTAMP(0). Should be a Date type and so should the underlying data insteadof string.
To Reproduce
Use either approach below to generate database files for a profiles table as described below.
CREATE TABLE "profiles" (
"id" UUID PRIMARY KEY REFERENCES auth.users ON DELETE CASCADE,
"email" TEXT UNIQUE NOT NULL,
"firstName" TEXT,
"lastName" TEXT,
"createdAt" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(0)
);
Approach 1
https://supabase.com/dashboard/project/_/api?page=tables-intro
Approach 2
npx supabase login
npx supabase init
npx supabase gen types --lang=typescript --project-id "$PROJECT_REF" --schema public > database.types.ts
File Generated
export type Database = {
public: {
Tables: {
profiles: {
Row: {
createdAt: string | null
email: string
firstName: string | null
id: string
lastName: string | null
updatedAt: string | null
}
Insert: {
createdAt?: string | null
email: string
firstName?: string | null
id: string
lastName?: string | null
updatedAt?: string | null
}
Update: {
createdAt?: string | null
email?: string
firstName?: string | null
id?: string
lastName?: string | null
updatedAt?: string | null
}
Relationships: [
{
foreignKeyName: "profiles_id_fkey"
columns: ["id"]
isOneToOne: true
referencedRelation: "users"
referencedColumns: ["id"]
},
]
}
}
}
}
Expected behavior
createdAt and updatedAt should be of type Date instead of string
I'm running into the same issue. Right now I'm manually editing the generated files to replace string with Date but that is only a short-term solution. Ideally there should be a way to define how the timestamp type (and possibly other types) are exposed in the generated types. Is that something that is on the roadmap?
Closing in favor of supabase/postgrest-js#572