Skip to content

Commit

Permalink
support composite primary keys
Browse files Browse the repository at this point in the history
  • Loading branch information
eitoball committed Feb 25, 2024
1 parent 4ba3f0f commit f1381e7
Show file tree
Hide file tree
Showing 26 changed files with 659 additions and 248 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ['3.0', '3.1', '3.2', head]
ruby: ['3.0', '3.1', '3.2', '3.3', head]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ gem 'rails', '>= 7.0'
gem 'rbs', '>= 3'
gem 'steep', '>= 1.4'
gem 'minitest'
gem 'abbrev'
gem 'mutex_m'
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PATH
GEM
remote: https://rubygems.org/
specs:
abbrev (0.1.2)
actioncable (7.0.5)
actionpack (= 7.0.5)
activesupport (= 7.0.5)
Expand Down Expand Up @@ -105,6 +106,7 @@ GEM
mini_mime (1.1.2)
mini_portile2 (2.8.2)
minitest (5.15.0)
mutex_m (0.2.0)
net-imap (0.3.4)
date
net-protocol
Expand Down Expand Up @@ -189,7 +191,9 @@ PLATFORMS
ruby

DEPENDENCIES
abbrev
minitest
mutex_m
rails (>= 7.0)
rake (~> 13.0)
rbs (>= 3)
Expand Down
12 changes: 10 additions & 2 deletions lib/rbs_rails/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@ def generate
pk = klass.primary_key
return 'top' unless pk

col = klass.columns.find {|col| col.name == pk }
sql_type_to_class(col.type)
if pk.is_a?(Array)
types = pk.map do |_pk|
col = klass.columns.find {|col| col.name == _pk }
sql_type_to_class(col.type)
end
"[ #{types.join(', ')} ]"
else
col = klass.columns.find {|col| col.name == pk }
sql_type_to_class(col.type)
end
end

private def generated_relation_methods_decl
Expand Down
78 changes: 59 additions & 19 deletions rbs_collection.lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
sources:
- type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
path: ".gem_rbs_collection"
Expand All @@ -11,68 +11,76 @@ gems:
version: '0'
source:
type: stdlib
- name: actioncable
version: '7.1'
source:
type: git
name: ruby/gem_rbs_collection
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: actionmailer
version: '7.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: actionpack
version: '6.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: actionview
version: '6.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: activejob
version: '6.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: activemodel
version: '6.0'
version: '7.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: activerecord
version: '6.1'
version: '7.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: activestorage
version: '6.1'
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: activesupport
version: '6.0'
version: '7.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: cgi
Expand All @@ -84,27 +92,35 @@ gems:
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: date
version: '0'
source:
type: stdlib
- name: erb
version: '0'
source:
type: stdlib
- name: fileutils
version: '0'
source:
type: stdlib
- name: globalid
version: '1.1'
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: i18n
version: '1.10'
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: json
Expand All @@ -120,7 +136,7 @@ gems:
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: minitest
Expand Down Expand Up @@ -148,23 +164,31 @@ gems:
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: rails-dom-testing
version: '2.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: railties
version: '6.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 163126f59d1bb765a6234fc60d3edf21cdfce255
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: rake
version: '13.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: rbs
Expand All @@ -175,6 +199,10 @@ gems:
version: '0'
source:
type: stdlib
- name: securerandom
version: '0'
source:
type: stdlib
- name: singleton
version: '0'
source:
Expand All @@ -183,10 +211,22 @@ gems:
version: '0'
source:
type: stdlib
- name: thor
version: '1.2'
source:
type: git
name: ruby/gem_rbs_collection
revision: 01361bb0fd6e2f3e2da2b11a733ffc938b9047c4
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: time
version: '0'
source:
type: stdlib
- name: timeout
version: '0'
source:
type: stdlib
- name: tsort
version: '0'
source:
Expand Down
2 changes: 1 addition & 1 deletion sig/_internal/activerecord.rbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# TODO: Define it in gem_rbs_collection repository
class ActiveRecord::Base
def self.primary_key: () -> String
def self.primary_key: () -> (String | Array[bot])
end
4 changes: 0 additions & 4 deletions sig/_internal/fileutils.rbs

This file was deleted.

5 changes: 0 additions & 5 deletions sig/_internal/thor.rbs

This file was deleted.

2 changes: 1 addition & 1 deletion test/app/Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'rails', '>= 6', '< 7'
gem 'rails', '>= 7', '< 8'
gem 'sqlite3'
gem 'puma'
gem 'bootsnap', require: false
Expand Down
Loading

0 comments on commit f1381e7

Please sign in to comment.