Skip to content

Postgres timestamp precision is always zero with Atlas #2454

@sagikazarmark

Description

@sagikazarmark
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When a field is defined as timestamp (or any other alternatives, like timestamptz), the precision in the database type is always 0 (regardless if a precision was specified or not).

Expected Behavior 🤔

When no precision is specified, the database type shouldn't have a precision.
When a precision is specified, the database type should have that precision, not zero.

Steps to Reproduce 🕹

Steps:

  1. Create a time field
  2. Enable atlas
  3. Describe the table
var timeSchema = map[string]string{
	dialect.Postgres: "timestamptz",
	dialect.SQLite:   "timestamp",
	dialect.MySQL:    "datetime(3)",
}

// ...

field.Time("expiry").
    SchemaType(timeSchema),

Your Environment 🌎

Tech Version
Go 1.17.3
Ent 0.10.1
Database Postgres
Driver https://github.com/lib/pq

I was able to reproduce the issue in this PR: dexidp/dex#2428

One additional detail (that should probably end up in a separate issue): even when Atlas is disabled, precision values are ignored. Even if I set the type to timestamptz(3) for example, in the database the type will just be timestamp with time zone. This is fine in my case because the default is not zero fortunately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions