Skip to content
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

Database file generated doesn't output correct type for TIMESTAMP(0) #1267

Closed
2 tasks done
anshul-kai opened this issue Sep 5, 2024 · 2 comments
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@anshul-kai
Copy link

anshul-kai commented Sep 5, 2024

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

@anshul-kai anshul-kai added the bug Something isn't working label Sep 5, 2024
@anshul-kai anshul-kai changed the title Database file generated doesn't output correct type for TIMESTAMP Database file generated doesn't output correct type for TIMESTAMP(0) Sep 5, 2024
@jens-ghc
Copy link

jens-ghc commented Nov 4, 2024

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?

@soedirgo
Copy link
Member

soedirgo commented Nov 5, 2024

Closing in favor of supabase/postgrest-js#572

@soedirgo soedirgo closed this as not planned Won't fix, can't repro, duplicate, stale Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants