Skip to content

Conversation

namhtpyn
Copy link

  • Add virtual mode support for PostgreSQL generated columns
  • Update schema serializer to handle both virtual and stored generated columns
  • Modify SQL generator to support VIRTUAL keyword in generated column statements
  • Add comprehensive tests for virtual generated columns
  • Update type definitions and interfaces for virtual generated column configuration
  • Ensure backward compatibility with existing stored generated columns

- Add virtual mode support for PostgreSQL generated columns
- Update schema serializer to handle both virtual and stored generated columns
- Modify SQL generator to support VIRTUAL keyword in generated column statements
- Add comprehensive tests for virtual generated columns
- Update type definitions and interfaces for virtual generated column configuration
- Ensure backward compatibility with existing stored generated columns
@Copilot Copilot AI review requested due to automatic review settings September 21, 2025 08:36
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for virtual generated columns in PostgreSQL 18, expanding beyond the existing stored generated columns functionality. The change enables developers to create virtual computed columns that are calculated on-the-fly rather than physically stored.

Key changes:

  • Enhanced generated column configuration to support both virtual and stored modes
  • Updated SQL generation to produce VIRTUAL keyword for virtual columns
  • Added comprehensive test coverage for virtual generated column scenarios

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
drizzle-orm/type-tests/pg/generated-columns.ts Added comprehensive type tests for virtual generated columns
drizzle-orm/src/pg-core/columns/common.ts Enhanced generatedAlwaysAs method to accept mode configuration
drizzle-kit/tests/pg-generated.test.ts Added test cases for virtual generated columns and mode transitions
drizzle-kit/src/sqlgenerator.ts Updated SQL generation to support VIRTUAL keyword
drizzle-kit/src/serializer/pgSerializer.ts Modified serializer to handle virtual/stored mode properly
drizzle-kit/src/serializer/pgSchema.ts Updated schema validation to accept virtual and stored types

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

lastName: varchar('last_name', { length: 255 }),
email: text('email').notNull(),
fullName: text('full_name').generatedAlwaysAs(
sql`concat_ws(first_name, ' ', last_name)`,
Copy link
Preview

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concat_ws function call has incorrect parameter order. The separator should be the first parameter, but here 'first_name' is passed as the separator instead of ' '. It should be concat_ws(' ', first_name, last_name).

Copilot uses AI. Check for mistakes.

{ mode: 'virtual' },
).notNull(),
upperName: text('upper_name').generatedAlwaysAs(
sql` case when first_name is null then null else upper(first_name) end `,
Copy link
Preview

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] There are extra spaces at the beginning and end of the SQL template literal. Remove the leading and trailing spaces for consistency: sqlcase when first_name is null then null else upper(first_name) end``.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant