rom-sql 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -0
- data/lib/rom/sql/attribute.rb +1 -1
- data/lib/rom/sql/projection_dsl.rb +6 -0
- data/lib/rom/sql/version.rb +1 -1
- data/rom-sql.gemspec +1 -1
- data/spec/integration/association/many_to_many/custom_fks_spec.rb +9 -13
- data/spec/integration/association/many_to_many/from_view_spec.rb +9 -8
- data/spec/integration/association/many_to_many_spec.rb +103 -102
- data/spec/integration/association/many_to_one/custom_fks_spec.rb +6 -7
- data/spec/integration/association/many_to_one/from_view_spec.rb +8 -4
- data/spec/integration/association/many_to_one_spec.rb +61 -54
- data/spec/integration/association/one_to_many/custom_fks_spec.rb +7 -6
- data/spec/integration/association/one_to_many/from_view_spec.rb +7 -10
- data/spec/integration/association/one_to_many/self_ref_spec.rb +6 -6
- data/spec/integration/association/one_to_many_spec.rb +0 -3
- data/spec/integration/association/one_to_one_spec.rb +17 -11
- data/spec/integration/association/one_to_one_through_spec.rb +3 -5
- data/spec/integration/commands/create_spec.rb +33 -22
- data/spec/integration/commands/update_spec.rb +3 -3
- data/spec/integration/commands/upsert_spec.rb +1 -1
- data/spec/integration/gateway_spec.rb +12 -8
- data/spec/integration/migration_spec.rb +4 -3
- data/spec/integration/plugins/associates/many_to_many_spec.rb +2 -2
- data/spec/integration/plugins/associates_spec.rb +1 -1
- data/spec/integration/relation_schema_spec.rb +4 -5
- data/spec/integration/schema/call_spec.rb +1 -1
- data/spec/integration/schema/inferrer/mysql_spec.rb +22 -23
- data/spec/integration/schema/inferrer/postgres_spec.rb +83 -82
- data/spec/integration/schema/inferrer/sqlite_spec.rb +18 -19
- data/spec/integration/schema/inferrer_spec.rb +54 -33
- data/spec/integration/schema/prefix_spec.rb +9 -11
- data/spec/integration/schema/qualified_spec.rb +9 -11
- data/spec/integration/schema/rename_spec.rb +13 -15
- data/spec/integration/schema/view_spec.rb +2 -2
- data/spec/integration/sequel_api_spec.rb +1 -1
- data/spec/integration/setup_spec.rb +5 -5
- data/spec/integration/support/active_support_notifications_spec.rb +2 -2
- data/spec/integration/support/rails_log_subscriber_spec.rb +2 -2
- data/spec/shared/accounts.rb +44 -0
- data/spec/shared/database_setup.rb +42 -81
- data/spec/shared/notes.rb +21 -0
- data/spec/shared/posts.rb +32 -0
- data/spec/shared/puppies.rb +13 -0
- data/spec/shared/relations.rb +1 -1
- data/spec/shared/users.rb +29 -0
- data/spec/shared/users_and_tasks.rb +32 -18
- data/spec/spec_helper.rb +18 -30
- data/spec/support/env_helper.rb +25 -0
- data/spec/support/oracle/create_users.sql +7 -0
- data/spec/support/oracle/set_sys_passwords.sql +2 -0
- data/spec/unit/plugin/pagination_spec.rb +2 -2
- data/spec/unit/plugin/timestamp_spec.rb +1 -1
- data/spec/unit/projection_dsl_spec.rb +8 -0
- data/spec/unit/relation/group_spec.rb +5 -3
- data/spec/unit/relation/max_spec.rb +1 -1
- data/spec/unit/relation/select_spec.rb +7 -0
- metadata +33 -5
- data/spec/shared/users_and_accounts.rb +0 -10
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'dry-struct'
|
2
2
|
|
3
|
-
RSpec.describe 'Commands / Update' do
|
4
|
-
include_context '
|
3
|
+
RSpec.describe 'Commands / Update', seeds: false do
|
4
|
+
include_context 'users'
|
5
5
|
|
6
6
|
subject(:users) { container.command(:users) }
|
7
7
|
|
@@ -73,7 +73,7 @@ RSpec.describe 'Commands / Update' do
|
|
73
73
|
|
74
74
|
expect {
|
75
75
|
users.update.by_id(piotr[:id]).call(name: nil)
|
76
|
-
}.to raise_error(ROM::SQL::NotNullConstraintError, /name/)
|
76
|
+
}.to raise_error(ROM::SQL::NotNullConstraintError, /name/i)
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'materializes single result' do
|
@@ -1,19 +1,17 @@
|
|
1
|
-
RSpec.describe ROM::SQL::Gateway, :postgres
|
1
|
+
RSpec.describe ROM::SQL::Gateway, :postgres do
|
2
2
|
include_context 'database setup'
|
3
3
|
|
4
4
|
describe 'migration' do
|
5
|
+
before do
|
6
|
+
inferrable_relations.concat %i(rabbits carrots)
|
7
|
+
end
|
8
|
+
|
5
9
|
context 'creating migrations inline' do
|
6
10
|
subject(:gateway) { container.gateways[:default] }
|
7
11
|
|
8
12
|
let(:conf) { ROM::Configuration.new(:sql, conn) }
|
9
13
|
let(:container) { ROM.container(conf) }
|
10
14
|
|
11
|
-
after do
|
12
|
-
[:rabbits, :carrots].each do |name|
|
13
|
-
gateway.connection.drop_table?(name)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
15
|
it 'allows creating and running migrations' do
|
18
16
|
migration = gateway.migration do
|
19
17
|
up do
|
@@ -39,6 +37,10 @@ RSpec.describe ROM::SQL::Gateway, :postgres, skip_tables: true do
|
|
39
37
|
end
|
40
38
|
|
41
39
|
context 'running migrations from a file system' do
|
40
|
+
before do
|
41
|
+
inferrable_relations.concat %i(schema_migrations)
|
42
|
+
end
|
43
|
+
|
42
44
|
let(:migration_dir) do
|
43
45
|
Pathname(__FILE__).dirname.join('../fixtures/migrations').realpath
|
44
46
|
end
|
@@ -64,8 +66,10 @@ RSpec.describe ROM::SQL::Gateway, :postgres, skip_tables: true do
|
|
64
66
|
|
65
67
|
describe 'transactions' do
|
66
68
|
before do
|
67
|
-
|
69
|
+
inferrable_relations.concat %i(names)
|
70
|
+
end
|
68
71
|
|
72
|
+
before do
|
69
73
|
conn.create_table(:names) do
|
70
74
|
String :name
|
71
75
|
end
|
@@ -1,11 +1,12 @@
|
|
1
|
-
RSpec.describe ROM::SQL, '.migration', :postgres
|
1
|
+
RSpec.describe ROM::SQL, '.migration', :postgres do
|
2
2
|
include_context 'database setup'
|
3
3
|
|
4
4
|
before do
|
5
|
-
|
6
|
-
conn.drop_table?(:dragons)
|
5
|
+
inferrable_relations.concat %i(dragons schema_migrations)
|
7
6
|
end
|
8
7
|
|
8
|
+
before { conf }
|
9
|
+
|
9
10
|
it 'creates a migration for a specific gateway' do
|
10
11
|
migration = ROM::SQL.migration do
|
11
12
|
change do
|
@@ -1,5 +1,5 @@
|
|
1
|
-
RSpec.describe 'Plugins / :associates / with many-to-many', :sqlite do
|
2
|
-
include_context '
|
1
|
+
RSpec.describe 'Plugins / :associates / with many-to-many', :sqlite, seeds: false do
|
2
|
+
include_context 'users and tasks'
|
3
3
|
|
4
4
|
let(:tasks) { container.commands[:tasks] }
|
5
5
|
let(:tags) { container.commands[:tags] }
|
@@ -1,5 +1,6 @@
|
|
1
1
|
RSpec.describe 'Inferring schema from database' do
|
2
|
-
include_context '
|
2
|
+
include_context 'users'
|
3
|
+
include_context 'posts'
|
3
4
|
|
4
5
|
with_adapters do
|
5
6
|
context "when database schema exists" do
|
@@ -13,13 +14,11 @@ RSpec.describe 'Inferring schema from database' do
|
|
13
14
|
|
14
15
|
context "for empty database schemas" do
|
15
16
|
it "returns an empty schema" do
|
16
|
-
|
17
|
-
|
18
|
-
expect { container.not_here }.to raise_error(NoMethodError)
|
17
|
+
expect { container.users }.to raise_error(NoMethodError)
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
|
-
context 'defining associations' do
|
21
|
+
context 'defining associations', seeds: false do
|
23
22
|
it "allows defining a one-to-many" do
|
24
23
|
class Test::Posts < ROM::Relation[:sql]
|
25
24
|
schema(:posts) do
|
@@ -2,45 +2,44 @@ RSpec.describe 'ROM::SQL::Schema::MysqlInferrer', :mysql do
|
|
2
2
|
include_context 'database setup'
|
3
3
|
|
4
4
|
before do
|
5
|
-
|
5
|
+
inferrable_relations.concat %i(test_inferrence)
|
6
|
+
end
|
6
7
|
|
8
|
+
before do
|
7
9
|
conn.create_table :test_inferrence do
|
8
10
|
tinyint :tiny
|
9
11
|
mediumint :medium
|
12
|
+
bigint :big
|
10
13
|
datetime :created_at
|
11
14
|
column :date_and_time, 'datetime(0)'
|
12
15
|
column :time_with_ms, 'datetime(3)'
|
13
16
|
timestamp :unix_time_usec
|
14
17
|
column :unix_time_sec, 'timestamp(0) null'
|
18
|
+
boolean :flag, null: false
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
18
|
-
after do
|
19
|
-
conn.drop_table?(:test_inferrence)
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:dataset) { :test_inferrence }
|
23
|
-
|
24
|
-
let(:schema) { container.relations[dataset].schema }
|
25
|
-
|
26
22
|
before do
|
27
|
-
|
28
|
-
|
29
|
-
schema(dataset, infer: true)
|
23
|
+
conf.relation(:test_inferrence) do
|
24
|
+
schema(infer: true)
|
30
25
|
end
|
31
26
|
end
|
32
27
|
|
33
|
-
|
34
|
-
|
28
|
+
let(:schema) { container.relations[:test_inferrence].schema }
|
29
|
+
let(:source) { container.relations[:test_inferrence].name }
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
31
|
+
it 'can infer attributes for dataset' do
|
32
|
+
expect(schema.to_h).
|
33
|
+
to eql(
|
34
|
+
tiny: ROM::SQL::Types::Int.optional.meta(name: :tiny, source: source),
|
35
|
+
medium: ROM::SQL::Types::Int.optional.meta(name: :medium, source: source),
|
36
|
+
big: ROM::SQL::Types::Int.optional.meta(name: :big, source: source),
|
37
|
+
created_at: ROM::SQL::Types::Time.optional.meta(name: :created_at, source: source),
|
38
|
+
date_and_time: ROM::SQL::Types::Time.optional.meta(name: :date_and_time, source: source),
|
39
|
+
time_with_ms: ROM::SQL::Types::Time.optional.meta(name: :time_with_ms, source: source),
|
40
|
+
unix_time_usec: ROM::SQL::Types::Time.meta(name: :unix_time_usec, source: source),
|
41
|
+
unix_time_sec: ROM::SQL::Types::Time.optional.meta(name: :unix_time_sec, source: source),
|
42
|
+
flag: ROM::SQL::Types::Bool.meta(name: :flag, source: source)
|
43
|
+
)
|
45
44
|
end
|
46
45
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
RSpec.describe 'ROM::SQL::Schema::PostgresInferrer', :postgres do
|
2
2
|
include_context 'database setup'
|
3
3
|
|
4
|
+
before do
|
5
|
+
inferrable_relations.concat %i(test_inferrence)
|
6
|
+
end
|
7
|
+
|
4
8
|
colors = %w(red orange yellow green blue purple)
|
5
9
|
|
6
10
|
before do
|
@@ -14,6 +18,7 @@ RSpec.describe 'ROM::SQL::Schema::PostgresInferrer', :postgres do
|
|
14
18
|
|
15
19
|
conn.create_table :test_inferrence do
|
16
20
|
primary_key :id, :uuid
|
21
|
+
bigint :big
|
17
22
|
Json :json_data
|
18
23
|
Jsonb :jsonb_data
|
19
24
|
Decimal :money, null: false
|
@@ -35,92 +40,88 @@ RSpec.describe 'ROM::SQL::Schema::PostgresInferrer', :postgres do
|
|
35
40
|
timestamp :created_at
|
36
41
|
column :datetime, "timestamp(0) without time zone"
|
37
42
|
column :datetime_tz, "timestamp(0) with time zone"
|
43
|
+
boolean :flag, null: false
|
38
44
|
end
|
39
45
|
end
|
40
46
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
let(:dataset) { :test_inferrence }
|
46
|
-
|
47
|
-
let(:schema) { container.relations[dataset].schema }
|
47
|
+
let(:schema) { container.relations[:test_inferrence].schema }
|
48
|
+
let(:source) { container.relations[:test_inferrence].name }
|
48
49
|
|
49
50
|
context 'inferring db-specific attributes' do
|
50
51
|
before do
|
51
|
-
|
52
|
-
|
53
|
-
schema(dataset, infer: true)
|
52
|
+
conf.relation(:test_inferrence) do
|
53
|
+
schema(infer: true)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'can infer attributes for dataset' do
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
58
|
+
expect(schema.to_h).
|
59
|
+
to eql(
|
60
|
+
id: ROM::SQL::Types::PG::UUID.meta(name: :id, source: source, primary_key: true),
|
61
|
+
big: ROM::SQL::Types::Int.optional.meta(name: :big, source: source),
|
62
|
+
json_data: ROM::SQL::Types::PG::JSON.optional.meta(name: :json_data, source: source),
|
63
|
+
jsonb_data: ROM::SQL::Types::PG::JSONB.optional.meta(name: :jsonb_data, source: source),
|
64
|
+
money: ROM::SQL::Types::Decimal.meta(name: :money, source: source),
|
65
|
+
tags: ROM::SQL::Types::PG::Array('text').optional.meta(name: :tags, source: source),
|
66
|
+
tag_ids: ROM::SQL::Types::PG::Array('biging').optional.meta(name: :tag_ids, source: source),
|
67
|
+
color: ROM::SQL::Types::String.enum(*colors).optional.meta(name: :color, source: source),
|
68
|
+
ip: ROM::SQL::Types::PG::IPAddress.optional.meta(
|
69
|
+
name: :ip,
|
70
|
+
source: source,
|
71
|
+
read: ROM::SQL::Types::PG::IPAddressR.optional
|
72
|
+
),
|
73
|
+
subnet: ROM::SQL::Types::PG::IPAddress.optional.meta(
|
74
|
+
name: :subnet,
|
75
|
+
source: source,
|
76
|
+
read: ROM::SQL::Types::PG::IPAddressR.optional
|
77
|
+
),
|
78
|
+
hw_address: ROM::SQL::Types::String.optional.meta(name: :hw_address, source: source),
|
79
|
+
center: ROM::SQL::Types::PG::PointT.optional.meta(
|
80
|
+
name: :center,
|
81
|
+
source: source,
|
82
|
+
read: ROM::SQL::Types::PG::PointTR.optional
|
83
|
+
),
|
84
|
+
page: ROM::SQL::Types::String.optional.meta(name: :page, source: source),
|
85
|
+
mapping: ROM::SQL::Types::PG::HStore.optional.meta(
|
86
|
+
name: :mapping,
|
87
|
+
source: source,
|
88
|
+
read: ROM::SQL::Types::PG::HStoreR.optional
|
89
|
+
),
|
90
|
+
line: ROM::SQL::Types::PG::LineT.optional.meta(
|
91
|
+
name: :line,
|
92
|
+
source: source,
|
93
|
+
read: ROM::SQL::Types::PG::LineTR.optional
|
94
|
+
),
|
95
|
+
circle: ROM::SQL::Types::PG::CircleT.optional.meta(
|
96
|
+
name: :circle,
|
97
|
+
source: source,
|
98
|
+
read: ROM::SQL::Types::PG::CircleTR.optional
|
99
|
+
),
|
100
|
+
box: ROM::SQL::Types::PG::BoxT.optional.meta(
|
101
|
+
name: :box,
|
102
|
+
source: source,
|
103
|
+
read: ROM::SQL::Types::PG::BoxTR.optional
|
104
|
+
),
|
105
|
+
lseg: ROM::SQL::Types::PG::LineSegmentT.optional.meta(
|
106
|
+
name: :lseg,
|
107
|
+
source: source,
|
108
|
+
read: ROM::SQL::Types::PG::LineSegmentTR.optional
|
109
|
+
),
|
110
|
+
polygon: ROM::SQL::Types::PG::PolygonT.optional.meta(
|
111
|
+
name: :polygon,
|
112
|
+
source: source,
|
113
|
+
read: ROM::SQL::Types::PG::PolygonTR.optional
|
114
|
+
),
|
115
|
+
path: ROM::SQL::Types::PG::PathT.optional.meta(
|
116
|
+
name: :path,
|
117
|
+
source: source,
|
118
|
+
read: ROM::SQL::Types::PG::PathTR.optional
|
119
|
+
),
|
120
|
+
created_at: ROM::SQL::Types::Time.optional.meta(name: :created_at, source: source),
|
121
|
+
datetime: ROM::SQL::Types::Time.optional.meta(name: :datetime, source: source),
|
122
|
+
datetime_tz: ROM::SQL::Types::Time.optional.meta(name: :datetime_tz, source: source),
|
123
|
+
flag: ROM::SQL::Types::Bool.meta(name: :flag, source: source)
|
124
|
+
)
|
124
125
|
end
|
125
126
|
end
|
126
127
|
|
@@ -137,7 +138,6 @@ RSpec.describe 'ROM::SQL::Schema::PostgresInferrer', :postgres do
|
|
137
138
|
|
138
139
|
context 'with a column with bi-directional mapping' do
|
139
140
|
before do
|
140
|
-
conn.drop_table?(:test_bidirectional)
|
141
141
|
conn.execute('create extension if not exists hstore')
|
142
142
|
|
143
143
|
conn.create_table(:test_bidirectional) do
|
@@ -191,11 +191,12 @@ RSpec.describe 'ROM::SQL::Schema::PostgresInferrer', :postgres do
|
|
191
191
|
line: line, circle: circle, lseg: lseg, box: box,
|
192
192
|
polygon: polygon, closed_path: closed_path, open_path: open_path
|
193
193
|
)
|
194
|
-
expect(inserted).
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
194
|
+
expect(inserted).
|
195
|
+
to eql(
|
196
|
+
id: 1, center: point, ip: dns, mapping: mapping,
|
197
|
+
line: line, circle: circle, lseg: lseg, box: box_corrected,
|
198
|
+
polygon: polygon, closed_path: closed_path, open_path: open_path
|
199
|
+
)
|
199
200
|
expect(relation.to_a).to eql([inserted])
|
200
201
|
end
|
201
202
|
end
|
@@ -2,37 +2,36 @@ RSpec.describe 'ROM::SQL::Schema::SqliteInferrer', :sqlite do
|
|
2
2
|
include_context 'database setup'
|
3
3
|
|
4
4
|
before do
|
5
|
-
|
5
|
+
inferrable_relations.concat %i(test_inferrence)
|
6
|
+
end
|
6
7
|
|
8
|
+
before do
|
7
9
|
conn.create_table :test_inferrence do
|
8
10
|
tinyint :tiny
|
9
11
|
int8 :big
|
12
|
+
bigint :long
|
10
13
|
column :dummy, nil
|
14
|
+
boolean :flag, null: false
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
14
|
-
after do
|
15
|
-
conn.drop_table?(:test_inferrence)
|
16
|
-
end
|
17
|
-
|
18
|
-
let(:dataset) { :test_inferrence }
|
19
|
-
|
20
|
-
let(:schema) { container.relations[dataset].schema }
|
21
|
-
|
22
18
|
before do
|
23
|
-
|
24
|
-
|
25
|
-
schema(dataset, infer: true)
|
19
|
+
conf.relation(:test_inferrence) do
|
20
|
+
schema(infer: true)
|
26
21
|
end
|
27
22
|
end
|
28
23
|
|
29
|
-
|
30
|
-
|
24
|
+
let(:schema) { container.relations[:test_inferrence].schema }
|
25
|
+
let(:source) { container.relations[:test_inferrence].name }
|
31
26
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
27
|
+
it 'can infer attributes for dataset' do
|
28
|
+
expect(schema.to_h).
|
29
|
+
to eql(
|
30
|
+
tiny: ROM::SQL::Types::Int.optional.meta(name: :tiny, source: source),
|
31
|
+
big: ROM::SQL::Types::Int.optional.meta(name: :big, source: source),
|
32
|
+
long: ROM::SQL::Types::Int.optional.meta(name: :long, source: source),
|
33
|
+
dummy: ROM::SQL::Types::SQLite::Object.optional.meta(name: :dummy, source: source),
|
34
|
+
flag: ROM::SQL::Types::Bool.meta(name: :flag, source: source)
|
35
|
+
)
|
37
36
|
end
|
38
37
|
end
|