Skip to content

Conversation

@aidanharan
Copy link
Contributor

@aidanharan aidanharan commented Oct 8, 2025

Added support for computed columns (#1346).

create_table :users do |t|
    t.string :name
    t.virtual :lower_name, as: "LOWER(name)", stored: false
    t.virtual :upper_name, as: "UPPER(name)", stored: true
    t.virtual :name_length, as: "LEN(name)"
end

Computed columns can be virtual stored: false (default) or persisted stored: true.

Ref:

@aidanharan aidanharan requested a review from Copilot October 8, 2025 17:13
Copy link

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 computed columns in SQL Server, allowing developers to define virtual columns with computed expressions that can be either virtual (not stored) or persisted (stored). The implementation follows SQL Server's computed column syntax and integrates with Rails' Active Record column definition system.

Key changes:

  • Added virtual column support with t.virtual syntax in table definitions
  • Implemented computed column detection and metadata extraction from SQL Server system tables
  • Enhanced schema dumping to preserve virtual column definitions

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/cases/virtual_column_test_sqlserver.rb Comprehensive test suite for virtual column functionality
test/cases/coerced_tests.rb Added :as and :stored as valid column options
lib/active_record/connection_adapters/sqlserver_column.rb Extended Column class with virtual column support methods
lib/active_record/connection_adapters/sqlserver_adapter.rb Added supports_virtual_columns? capability
lib/active_record/connection_adapters/sqlserver/table_definition.rb Added virtual column options to table definition
lib/active_record/connection_adapters/sqlserver/schema_statements.rb Enhanced column metadata extraction for computed columns
lib/active_record/connection_adapters/sqlserver/schema_dumper.rb Added virtual column dumping support and fixed typo
lib/active_record/connection_adapters/sqlserver/schema_creation.rb Added SQL generation for virtual column definitions
CHANGELOG.md Added entry for computed columns feature

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

@aidanharan aidanharan merged commit dfdb318 into main Oct 18, 2025
6 checks passed
@aidanharan aidanharan deleted the virtual-columns branch October 18, 2025 16:21
@ttilberg
Copy link

Yeah!

This also closes #1346

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants