Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const PRESERVED_NATIVE_TYPES: Record<string, string> = {
decimal: 'Numeric',
timestamp: 'Timestamp',
'timestamp without time zone': 'Timestamp',
timestamptz: 'Timestamptz',
'timestamp with time zone': 'Timestamptz',
timestamptz: 'TimestamptzString',
'timestamp with time zone': 'TimestamptzString',
date: 'Date',
time: 'Time',
'time without time zone': 'Time',
Expand All @@ -47,7 +47,8 @@ const PARAMETERIZED_NATIVE_TYPES: Record<string, string> = {
numeric: 'Numeric',
decimal: 'Numeric',
timestamp: 'Timestamp',
timestamptz: 'Timestamptz',
timestamptz: 'TimestamptzString',
'timestamp with time zone': 'TimestamptzString',
time: 'Time',
timetz: 'Timetz',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const authoringTypes = {
Int: { kind: 'typeConstructor', output: { codecId: 'pg/int4@1', nativeType: 'int4' } },
Uuid: { kind: 'typeConstructor', output: { codecId: 'pg/uuid@1', nativeType: 'uuid' } },
Inet: { kind: 'typeConstructor', output: { codecId: 'pg/inet@1', nativeType: 'inet' } },
Timestamptz: {
TimestamptzString: {
kind: 'typeConstructor',
output: { codecId: 'pg/timestamptz-temporal@1', nativeType: 'timestamptz' },
output: { codecId: 'pg/timestamptz-string@1', nativeType: 'timestamptz' },
},
VarChar: {
kind: 'typeConstructor',
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('Postgres PSL inference round trip', () => {
expect(inferred).not.toContain('bareAmount Numeric()');
expect(inferred).toMatch(/jsonValue\s+Json/);
expect(inferred).toMatch(/jsonbValue\s+Jsonb/);
expect(inferred).toMatch(/occurredAt\s+Timestamptz/);
expect(inferred).toMatch(/occurredAt\s+TimestamptzString/);
expect(inferred).toMatch(/label\s+VarChar\(191\)/);

const emitted = parseAndEmit(inferred);
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('Postgres PSL inference round trip', () => {
json_value: { codecId: 'pg/json@1', nativeType: 'json', nullable: false },
jsonb_value: { codecId: 'pg/jsonb@1', nativeType: 'jsonb', nullable: false },
occurred_at: {
codecId: 'pg/timestamptz-temporal@1',
codecId: 'pg/timestamptz-string@1',
nativeType: 'timestamptz',
nullable: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ describe('createPostgresTypeMap', () => {
nativeType: 'numeric',
});
expect(typeMap.resolve('timestamptz')).toEqual({
pslType: { name: 'Timestamptz' },
pslType: { name: 'TimestamptzString' },
nativeType: 'timestamptz',
});
expect(typeMap.resolve('timestamp with time zone')).toEqual({
pslType: { name: 'Timestamptz' },
pslType: { name: 'TimestamptzString' },
nativeType: 'timestamp with time zone',
});
expect(typeMap.resolve('jsonb')).toEqual({ pslType: { name: 'Jsonb' }, nativeType: 'jsonb' });
Expand Down Expand Up @@ -145,31 +145,28 @@ describe('representation-explicit spellings stay out of introspection', () => {
['date', 'Date'],
['timestamp', 'Timestamp'],
['timestamp without time zone', 'Timestamp'],
['timestamptz', 'Timestamptz'],
['timestamp with time zone', 'Timestamptz'],
['timestamptz', 'TimestamptzString'],
['timestamp with time zone', 'TimestamptzString'],
['time', 'Time'],
['time without time zone', 'Time'],
])('resolves %s to the bare %s, never a *String spelling', (nativeType, pslName) => {
])('resolves %s to %s (timestamptz variants use TimestamptzString)', (nativeType, pslName) => {
expect(map.resolve(nativeType)).toMatchObject({ pslType: { name: pslName } });
});

it('keeps precision on the bare spelling', () => {
expect(map.resolve('timestamptz(6)')).toMatchObject({
pslType: { name: 'Timestamptz', args: ['6'] },
pslType: { name: 'TimestamptzString', args: ['6'] },
});
});

it('never produces a *String name for any native type it knows', () => {
it('never produces a *String name for any native type it knows except timestamptz variants (timestamptz, timestamp with time zone, timestamptz(6))', () => {
const natives = [
'date',
'timestamp',
'timestamp without time zone',
'timestamptz',
'timestamp with time zone',
'time',
'time without time zone',
'timetz',
'timestamptz(6)',
'timestamp(3)',
'time(3)',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('printPsl', () => {
// WARNING: This table has no primary key in the database
model AuditLog {
event String
timestamp Timestamptz
timestamp TimestamptzString
@@map("audit_log")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ describe('printPsl', () => {
// Contract inferred from the live database schema. Edit as needed, then run \`prisma contract emit\`.

model Post {
id Int @id @default(autoincrement())
title String @default("Untitled")
isPublished Boolean @default(false) @map("is_published")
viewCount Int @default(0) @map("view_count")
createdAt Timestamptz @default(now()) @map("created_at")
id Int @id @default(autoincrement())
title String @default("Untitled")
isPublished Boolean @default(false) @map("is_published")
viewCount Int @default(0) @map("view_count")
createdAt TimestamptzString @default(now()) @map("created_at")

@@map("post")
}
Expand Down Expand Up @@ -431,10 +431,10 @@ describe('printPsl', () => {
// Contract inferred from the live database schema. Edit as needed, then run \`prisma contract emit\`.

model Data {
id Int @id
computed String @default(dbgenerated("my_custom_func()"))
payload Jsonb @default(dbgenerated("'{}'::jsonb"))
touchedAt Timestamptz @default(dbgenerated("clock_timestamp()")) @map("touched_at")
id Int @id
computed String @default(dbgenerated("my_custom_func()"))
payload Jsonb @default(dbgenerated("'{}'::jsonb"))
touchedAt TimestamptzString @default(dbgenerated("clock_timestamp()")) @map("touched_at")

@@map("data")
}
Expand Down