diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7bb809c..6bfeea4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -117,6 +117,7 @@ jobs: - { ruby-version: '3.2', generate-types: 'false', generate-gemfile: 'false' } - { ruby-version: '3.3', generate-types: 'true', generate-gemfile: 'false' } - { ruby-version: '3.3', generate-types: 'false', generate-gemfile: 'true' } + - { ruby-version: '4.0', generate-types: 'true', generate-gemfile: 'true' } steps: - uses: actions/checkout@v7 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c1d5f14..ab56807 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -49,7 +49,7 @@ jobs: strategy: fail-fast: false matrix: - ruby-version: ['3.1', '3.2', '3.4'] + ruby-version: ['3.1', '3.2', '3.4', '4.0'] steps: - uses: actions/checkout@v7 @@ -63,9 +63,14 @@ jobs: run: ruby -Ilib -Itest -e 'Dir["test/*_test.rb"].sort.each { |file| require File.expand_path(file) }' end2end-pg: - name: End-to-End (PostgreSQL) + name: End-to-End (PostgreSQL, Ruby ${{ matrix.ruby-version }}) runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby-version: ['3.3', '4.0'] + services: postgres: image: postgres:16.2 @@ -89,7 +94,7 @@ jobs: - uses: ruby/setup-ruby@v1 with: - ruby-version: '3.3' + ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - name: Create the schema @@ -101,9 +106,14 @@ jobs: run: bundle exec rake end2end_pg end2end-mysql: - name: End-to-End (MySQL) + name: End-to-End (MySQL, Ruby ${{ matrix.ruby-version }}) runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby-version: ['3.3', '4.0'] + services: mysql: image: mysql:8.3.0 @@ -126,7 +136,7 @@ jobs: - uses: ruby/setup-ruby@v1 with: - ruby-version: '3.3' + ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - name: Create the schema (and allow LOAD DATA LOCAL INFILE for :copyfrom) @@ -138,15 +148,20 @@ jobs: run: bundle exec rake end2end_mysql2 end2end-sqlite: - name: End-to-End (SQLite) + name: End-to-End (SQLite, Ruby ${{ matrix.ruby-version }}) runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby-version: ['3.3', '4.0'] + steps: - uses: actions/checkout@v7 - uses: ruby/setup-ruby@v1 with: - ruby-version: '3.3' + ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - name: End-to-End tests diff --git a/CLAUDE.md b/CLAUDE.md index 94079c4..2e9686e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -28,7 +28,7 @@ UPDATE_GOLDEN=1 bundle exec ruby -Itest test/extended_golden_test.rb # rewrite * **The plugin runs inside ruby.wasm**: only Ruby core + `json`; no gems, no C extensions, no filesystem, no network. Anything `require`d by `lib/` or `exe/` must exist in the WASM (`scripts/wasm/build.sh` stages the stdlib). Gems used only by tests/tooling go in the `Gemfile` groups, never in `lib/`. -* **Generated code must stay valid for Ruby 3.1–3.4** (`Struct` below 3.2, `Data` from 3.2) and RuboCop/Steep-clean. +* **Generated code must stay valid for Ruby 3.1–4.0** (`Struct` below 3.2, `Data` from 3.2) and RuboCop/Steep-clean. * Generated code is plain, idiomatic Ruby (keyword args, `Data` rows, implicit returns, 2-space indent); do not mirror the C# sibling plugin's style. Parameter *values* are never logged. * Prepared statements are per connection (`ConnectionState`) because the query object is shared by pooled connections. @@ -37,7 +37,7 @@ UPDATE_GOLDEN=1 bundle exec ruby -Itest test/extended_golden_test.rb # rewrite ## Git, CI and releases * Develop on a feature branch, small commits; PRs target `main`. Label PRs (`bug`, `enhancement`, `documentation`; `breaking` for incompatible changes, see `.github/release.yml`). -* CI: `build.yml` (WASM, lint, `sqlc diff`, Steep, option matrix) and `tests.yml` (unit, Ruby 3.1/3.2/3.4, E2E on real +* CI: `build.yml` (WASM, lint, `sqlc diff`, Steep, option matrix) and `tests.yml` (unit, Ruby 3.1/3.2/3.4/4.0, E2E on real PostgreSQL/MySQL/SQLite). Both must be green. * **Never create tags or releases by hand and never add release markers to commit messages.** Releases are started by a maintainer with the *Release* workflow (`docs/Releasing.md`); do not trigger it unless explicitly asked. diff --git a/README.md b/README.md index a256366..6c5b7af 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # sqlc-gen-ruby A [sqlc](https://sqlc.dev) plugin that turns your SQL into Ruby methods, with RBS type signatures. -Works with `pg` (PostgreSQL), `mysql2` (MySQL) and `sqlite3` (SQLite), and Ruby 3.1 – 3.4. +Works with `pg` (PostgreSQL), `mysql2` (MySQL) and `sqlite3` (SQLite), and Ruby 3.1 – 4.0. The plugin is written in pure Ruby and ships as one self-contained WebAssembly file (the [ruby.wasm](https://github.com/ruby/ruby.wasm) interpreter with the plugin inside), so you don't need to install anything besides sqlc. @@ -58,7 +58,7 @@ More: [the generated code for every driver](docs/Examples.md) (it is the plugin' | Option | Default | What it does | |---|---|---| | `driver` | required | `pg`, `mysql2` or `sqlite3`. Must match the sqlc `engine:`. | -| `rubyVersion` | `3.3` | Oldest Ruby the code must run on, `3.1` – `3.4`. Rows are `Data` classes from 3.2 and `Struct`s below. | +| `rubyVersion` | `3.3` | Oldest Ruby the code must run on, `3.1` – `4.0`. Rows are `Data` classes from 3.2 and `Struct`s below. | | `generateTypes` | `true` | Also generate `.rbs` type signatures. | | `generateGemfile` | `false` | Also generate a `Gemfile` with the gems the code needs. | | `moduleName` | `Codegen` | The module the code lives in, e.g. `MyApp::Db`. | @@ -177,7 +177,6 @@ server; duplicate keys and invalid values raise `Mysql2::Error` instead of being ### Limitations * Two result columns with the same name (e.g. `a.id, b.id`) are an error: alias one (`b.id AS book_id`) or use `sqlc.embed`. -* `rubyVersion` takes `3.4` but not a patch version of it (`3.4.1`). * SQLite's `NUMERIC` affinity can return an `Integer` where `Float` is declared. * `:batchexec` / `:batchone` / `:batchmany` are not atomic on their own: wrap them in `transaction` for all-or-nothing. * SQLite: a transaction belongs to the thread that opened it; a Fiber / `Enumerator#next` inside it that uses the same diff --git a/docs/Testing.md b/docs/Testing.md index b245bda..cbe6614 100644 --- a/docs/Testing.md +++ b/docs/Testing.md @@ -39,8 +39,8 @@ They `require` the generated code from `examples/` and run it against a real dat ## CI workflows (`.github/workflows/`) | Workflow | When | What | |---|---|---| -| `build.yml` | push to `main`, pull requests (not for Markdown-only changes), release | build `plugin.wasm`; lint; `sqlc diff` with the WASM and the process plugin; Steep; generate with option combinations (Ruby 3.1/3.2/3.3 × types/Gemfile) and check the output with the matching Ruby | -| `tests.yml` | same | unit tests; the plugin on Ruby 3.1 / 3.2 / 3.4; end-to-end against PostgreSQL 16 and MySQL 8.3 service containers and SQLite | +| `build.yml` | push to `main`, pull requests (not for Markdown-only changes), release | build `plugin.wasm`; lint; `sqlc diff` with the WASM and the process plugin; Steep; generate with option combinations (Ruby 3.1/3.2/3.3/4.0 × types/Gemfile) and check the output with the matching Ruby | +| `tests.yml` | same | unit tests; the plugin on Ruby 3.1 / 3.2 / 3.4 / 4.0; end-to-end against PostgreSQL 16 and MySQL 8.3 service containers and SQLite (Ruby 3.3 and 4.0) | | `docs.yml` | `examples/` change on `main`, manual | regenerates `docs/Examples.md` and opens a PR | | `release.yml` | manual only | see [Releasing](Releasing.md) | diff --git a/lib/sqlc_gen_ruby/ruby_version.rb b/lib/sqlc_gen_ruby/ruby_version.rb index 5c619d3..a8006db 100644 --- a/lib/sqlc_gen_ruby/ruby_version.rb +++ b/lib/sqlc_gen_ruby/ruby_version.rb @@ -3,7 +3,7 @@ module SqlcGenRuby # Port of PluginOptions/RubyVersion.cs. The comparison deliberately mirrors the C# record's # CompareTo, including its handling of omitted minor / patch parts (e.g. "3" compares equal to any - # "3.x", while "3.3.5" compares greater than "3.3", so it is rejected by the max-version check). + # "3.x", while "3.3.5" compares greater than "3.3"). The max-version check ignores the patch part. class RubyVersion include Comparable @@ -23,7 +23,7 @@ def self.parse(pattern) if version < MIN_SUPPORTED raise ArgumentError, "Provided version #{version} is below the minimum supported version #{MIN_SUPPORTED}" end - if version > MAX_SUPPORTED + if new(version.major, version.minor) > MAX_SUPPORTED # any patch release of the newest minor is fine raise ArgumentError, "Provided version #{version} is above the maximum supported version #{MAX_SUPPORTED}" end @@ -82,7 +82,7 @@ def compare_nullable(value, other) private :compare_nullable MIN_SUPPORTED = new(3, 1).freeze - MAX_SUPPORTED = new(3, 4).freeze + MAX_SUPPORTED = new(4, 0).freeze IMMUTABLE_DATA_MIN = new(3, 2).freeze end end diff --git a/test/features_test.rb b/test/features_test.rb index 359281f..6806a70 100644 --- a/test/features_test.rb +++ b/test/features_test.rb @@ -561,6 +561,6 @@ def test_nested_module_name_is_self_contained def test_unknown_and_misplaced_options_are_errors assert_raises(RuntimeError) { generate(load_request('pg', moduleNmae: 'Db')) } assert_raises(RuntimeError) { generate(load_request('mysql2', preparedStatements: false)) } - generate(load_request('pg', rubyVersion: '3.4')) + generate(load_request('pg', rubyVersion: '4.0')) end end diff --git a/test/options_test.rb b/test/options_test.rb index 656e360..f3f4be3 100644 --- a/test/options_test.rb +++ b/test/options_test.rb @@ -29,20 +29,20 @@ def test_unknown_override_keys_are_rejected end def test_version_bounds - %w[3.1 3.2 3.3 3.4 3].each { |v| RubyVersion.parse(v) } - err = assert_raises(ArgumentError) { RubyVersion.parse('3.5') } - assert_equal 'Provided version 3.5 is above the maximum supported version 3.4', err.message + %w[3.1 3.2 3.3 3.4 4.0 3 4].each { |v| RubyVersion.parse(v) } + err = assert_raises(ArgumentError) { RubyVersion.parse('4.1') } + assert_equal 'Provided version 4.1 is above the maximum supported version 4.0', err.message err = assert_raises(ArgumentError) { RubyVersion.parse('3.0') } assert_equal 'Provided version 3.0 is below the minimum supported version 3.1', err.message + assert_raises(ArgumentError) { RubyVersion.parse('5') } assert_raises(ArgumentError) { RubyVersion.parse('2.7') } assert_raises(ArgumentError) { RubyVersion.parse('three') } assert_raises(ArgumentError) { RubyVersion.parse('3.03') } end - # The C# comparison treats a patch component as greater than a missing one. - def test_patch_versions_compare_like_the_csharp_implementation - assert_raises(ArgumentError) { RubyVersion.parse('3.4.1') } - RubyVersion.parse('3.2.9') + def test_patch_versions_are_accepted + %w[3.2.9 3.4.1 4.0.1].each { |v| RubyVersion.parse(v) } + assert_operator RubyVersion.parse('3.4.1'), :>, RubyVersion.parse('3.4') end def test_immutable_data_support