Skip to content

Verify Rails-style stored generated columns (Oracle 12c+ GENERATED ALWAYS AS ... STORED) #2713

@yahonda

Description

@yahonda

Background

Oracle 12c introduced GENERATED columns:

-- Virtual (computed at read time)
ALTER TABLE products ADD full_name VARCHAR2(200) GENERATED ALWAYS AS (first_name || ' ' || last_name) VIRTUAL;

-- Stored (persisted)
ALTER TABLE products ADD full_name VARCHAR2(200) GENERATED ALWAYS AS (first_name || ' ' || last_name) STORED;

oracle-enhanced supports the VIRTUAL form via the :as option since long ago (see OracleEnhanced::TableDefinition's :as option in valid_column_definition_options).

Rails 7.1+ standardised the generated: { type: :stored | :virtual, expression: "..." } keyword for add_column / change_column (see PostgreSQL's add_column_options! for the as: / stored: mapping). Oracle 12c+ supports both VIRTUAL and STORED, but oracle-enhanced has not been audited against Rails' standardised keyword.

Question to resolve

  • Does add_column :t, :col, :string, as: "...", stored: true (or the newer generated: { ... } form) flow through to Oracle as GENERATED ALWAYS AS (...) STORED?
  • Does the schema dumper round-trip the stored vs virtual distinction?
  • Does change_column handle the same?

Verification steps

  1. Read Rails::Generators::Migration migrations for the standardised generated-column DSL across Rails 7.0 / 7.1 / 7.2 / 8.0 / 8.1 / 8.2 — pin which keyword form is current
  2. Probe oracle-enhanced against each form, observing emitted DDL
  3. Where DDL is wrong / missing, decide whether to add a Rails 8.2-versioned MigrationCompatibility module (so older migrations keep their existing :as-only behavior)
  4. Update schema_dumper to dump the correct form

Out of scope

Why now

Surfaced during the survey for #2702 / #2710. The VIRTUAL path predates STORED; STORED has been quietly supported by Oracle for over a decade. Worth a short audit to confirm AR's standardised DSL passes through correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions