rom-sql 2.0.0.beta2 → 2.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +66 -0
- data/lib/rom/plugins/relation/sql/postgres/explain.rb +54 -0
- data/lib/rom/sql.rb +1 -1
- data/lib/rom/sql/attribute.rb +17 -18
- data/lib/rom/sql/errors.rb +3 -0
- data/lib/rom/sql/extensions/mysql.rb +1 -1
- data/lib/rom/sql/extensions/mysql/type_builder.rb +28 -0
- data/lib/rom/sql/extensions/postgres.rb +3 -1
- data/lib/rom/sql/extensions/postgres/commands.rb +30 -13
- data/lib/rom/sql/extensions/postgres/{attributes_inferrer.rb → type_builder.rb} +24 -28
- data/lib/rom/sql/extensions/postgres/type_serializer.rb +39 -0
- data/lib/rom/sql/extensions/postgres/types.rb +24 -477
- data/lib/rom/sql/extensions/postgres/types/array.rb +163 -0
- data/lib/rom/sql/extensions/postgres/types/geometric.rb +135 -0
- data/lib/rom/sql/extensions/postgres/types/json.rb +235 -0
- data/lib/rom/sql/extensions/postgres/types/network.rb +15 -0
- data/lib/rom/sql/extensions/sqlite.rb +1 -1
- data/lib/rom/sql/extensions/sqlite/{attributes_inferrer.rb → type_builder.rb} +5 -5
- data/lib/rom/sql/extensions/sqlite/types.rb +8 -3
- data/lib/rom/sql/foreign_key.rb +17 -0
- data/lib/rom/sql/function.rb +86 -8
- data/lib/rom/sql/gateway.rb +26 -26
- data/lib/rom/sql/index.rb +4 -0
- data/lib/rom/sql/migration.rb +3 -3
- data/lib/rom/sql/migration/inline_runner.rb +9 -83
- data/lib/rom/sql/migration/migrator.rb +35 -12
- data/lib/rom/sql/migration/recorder.rb +21 -0
- data/lib/rom/sql/migration/runner.rb +115 -0
- data/lib/rom/sql/migration/schema_diff.rb +108 -53
- data/lib/rom/sql/migration/writer.rb +61 -0
- data/lib/rom/sql/relation.rb +2 -1
- data/lib/rom/sql/relation/reading.rb +63 -3
- data/lib/rom/sql/relation/writing.rb +38 -0
- data/lib/rom/sql/schema.rb +9 -3
- data/lib/rom/sql/schema/attributes_inferrer.rb +3 -119
- data/lib/rom/sql/schema/inferrer.rb +99 -18
- data/lib/rom/sql/schema/type_builder.rb +94 -0
- data/lib/rom/sql/type_dsl.rb +30 -0
- data/lib/rom/sql/type_extensions.rb +11 -6
- data/lib/rom/sql/type_serializer.rb +46 -0
- data/lib/rom/sql/types.rb +12 -0
- data/lib/rom/sql/version.rb +1 -1
- metadata +26 -244
- data/.codeclimate.yml +0 -15
- data/.gitignore +0 -17
- data/.rspec +0 -3
- data/.travis.yml +0 -39
- data/.yardopts +0 -2
- data/Gemfile +0 -33
- data/Guardfile +0 -24
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -19
- data/circle.yml +0 -10
- data/lib/rom/sql/extensions/mysql/attributes_inferrer.rb +0 -10
- data/lib/rom/sql/relation/sequel_api.rb +0 -133
- data/log/.gitkeep +0 -0
- data/rom-sql.gemspec +0 -29
- data/spec/extensions/postgres/attribute_spec.rb +0 -217
- data/spec/extensions/postgres/integration_spec.rb +0 -59
- data/spec/extensions/postgres/types_spec.rb +0 -252
- data/spec/extensions/sqlite/types_spec.rb +0 -11
- data/spec/fixtures/migrations/20150403090603_create_carrots.rb +0 -8
- data/spec/integration/associations/many_to_many/custom_fks_spec.rb +0 -76
- data/spec/integration/associations/many_to_many/from_view_spec.rb +0 -88
- data/spec/integration/associations/many_to_many_spec.rb +0 -162
- data/spec/integration/associations/many_to_one/custom_fks_spec.rb +0 -64
- data/spec/integration/associations/many_to_one/from_view_spec.rb +0 -84
- data/spec/integration/associations/many_to_one/self_ref_spec.rb +0 -53
- data/spec/integration/associations/many_to_one_spec.rb +0 -117
- data/spec/integration/associations/one_to_many/custom_fks_spec.rb +0 -54
- data/spec/integration/associations/one_to_many/from_view_spec.rb +0 -57
- data/spec/integration/associations/one_to_many/self_ref_spec.rb +0 -54
- data/spec/integration/associations/one_to_many_spec.rb +0 -86
- data/spec/integration/associations/one_to_one_spec.rb +0 -69
- data/spec/integration/associations/one_to_one_through_spec.rb +0 -92
- data/spec/integration/auto_migrations/errors_spec.rb +0 -31
- data/spec/integration/auto_migrations/indexes_spec.rb +0 -253
- data/spec/integration/auto_migrations/managing_columns_spec.rb +0 -156
- data/spec/integration/auto_migrations/postgres/column_types_spec.rb +0 -63
- data/spec/integration/combine_with_spec.rb +0 -43
- data/spec/integration/commands/create_spec.rb +0 -304
- data/spec/integration/commands/delete_spec.rb +0 -84
- data/spec/integration/commands/update_spec.rb +0 -90
- data/spec/integration/commands/upsert_spec.rb +0 -83
- data/spec/integration/gateway_spec.rb +0 -107
- data/spec/integration/migration_spec.rb +0 -55
- data/spec/integration/plugins/associates/many_to_many_spec.rb +0 -69
- data/spec/integration/plugins/associates_spec.rb +0 -250
- data/spec/integration/plugins/auto_restrictions_spec.rb +0 -74
- data/spec/integration/relation_schema_spec.rb +0 -271
- data/spec/integration/schema/call_spec.rb +0 -24
- data/spec/integration/schema/inferrer/mysql_spec.rb +0 -45
- data/spec/integration/schema/inferrer/postgres_spec.rb +0 -203
- data/spec/integration/schema/inferrer/sqlite_spec.rb +0 -37
- data/spec/integration/schema/inferrer_spec.rb +0 -390
- data/spec/integration/schema/prefix_spec.rb +0 -16
- data/spec/integration/schema/qualified_spec.rb +0 -16
- data/spec/integration/schema/rename_spec.rb +0 -21
- data/spec/integration/schema/view_spec.rb +0 -29
- data/spec/integration/sequel_api_spec.rb +0 -36
- data/spec/integration/setup_spec.rb +0 -26
- data/spec/integration/support/active_support_notifications_spec.rb +0 -24
- data/spec/integration/support/rails_log_subscriber_spec.rb +0 -30
- data/spec/integration/wrap_spec.rb +0 -91
- data/spec/shared/accounts.rb +0 -48
- data/spec/shared/database_setup.rb +0 -70
- data/spec/shared/notes.rb +0 -23
- data/spec/shared/posts.rb +0 -34
- data/spec/shared/puppies.rb +0 -15
- data/spec/shared/relations.rb +0 -8
- data/spec/shared/users.rb +0 -32
- data/spec/shared/users_and_tasks.rb +0 -50
- data/spec/spec_helper.rb +0 -122
- data/spec/support/env_helper.rb +0 -25
- data/spec/support/helpers.rb +0 -24
- data/spec/support/oracle/create_users.sql +0 -7
- data/spec/support/oracle/set_sys_passwords.sql +0 -2
- data/spec/support/test_configuration.rb +0 -16
- data/spec/unit/attribute_spec.rb +0 -104
- data/spec/unit/function_spec.rb +0 -48
- data/spec/unit/gateway_spec.rb +0 -70
- data/spec/unit/logger_spec.rb +0 -14
- data/spec/unit/migration_tasks_spec.rb +0 -111
- data/spec/unit/migrator_spec.rb +0 -25
- data/spec/unit/order_dsl_spec.rb +0 -43
- data/spec/unit/plugin/associates_spec.rb +0 -94
- data/spec/unit/plugin/pagination_spec.rb +0 -91
- data/spec/unit/plugin/timestamp_spec.rb +0 -117
- data/spec/unit/projection_dsl_spec.rb +0 -110
- data/spec/unit/relation/assoc_spec.rb +0 -87
- data/spec/unit/relation/associations_spec.rb +0 -27
- data/spec/unit/relation/avg_spec.rb +0 -11
- data/spec/unit/relation/by_pk_spec.rb +0 -62
- data/spec/unit/relation/dataset_spec.rb +0 -50
- data/spec/unit/relation/distinct_spec.rb +0 -15
- data/spec/unit/relation/exclude_spec.rb +0 -11
- data/spec/unit/relation/exist_predicate_spec.rb +0 -25
- data/spec/unit/relation/exists_spec.rb +0 -18
- data/spec/unit/relation/fetch_spec.rb +0 -21
- data/spec/unit/relation/group_spec.rb +0 -61
- data/spec/unit/relation/having_spec.rb +0 -22
- data/spec/unit/relation/inner_join_spec.rb +0 -158
- data/spec/unit/relation/inspect_spec.rb +0 -11
- data/spec/unit/relation/instrument_spec.rb +0 -45
- data/spec/unit/relation/invert_spec.rb +0 -11
- data/spec/unit/relation/left_join_spec.rb +0 -55
- data/spec/unit/relation/lock_spec.rb +0 -93
- data/spec/unit/relation/map_spec.rb +0 -16
- data/spec/unit/relation/max_spec.rb +0 -11
- data/spec/unit/relation/min_spec.rb +0 -11
- data/spec/unit/relation/order_spec.rb +0 -51
- data/spec/unit/relation/pluck_spec.rb +0 -11
- data/spec/unit/relation/prefix_spec.rb +0 -29
- data/spec/unit/relation/primary_key_spec.rb +0 -27
- data/spec/unit/relation/project_spec.rb +0 -24
- data/spec/unit/relation/qualified_columns_spec.rb +0 -30
- data/spec/unit/relation/qualified_spec.rb +0 -25
- data/spec/unit/relation/read_spec.rb +0 -25
- data/spec/unit/relation/rename_spec.rb +0 -23
- data/spec/unit/relation/right_join_spec.rb +0 -57
- data/spec/unit/relation/select_append_spec.rb +0 -21
- data/spec/unit/relation/select_spec.rb +0 -40
- data/spec/unit/relation/sum_spec.rb +0 -11
- data/spec/unit/relation/union_spec.rb +0 -19
- data/spec/unit/relation/unique_predicate_spec.rb +0 -18
- data/spec/unit/relation/where_spec.rb +0 -133
- data/spec/unit/restriction_dsl_spec.rb +0 -34
- data/spec/unit/schema_spec.rb +0 -25
- data/spec/unit/types_spec.rb +0 -65
@@ -1,253 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::SQL::Gateway, :postgres, :helpers do
|
2
|
-
include_context 'database setup'
|
3
|
-
|
4
|
-
before do
|
5
|
-
conn.drop_table?(:users)
|
6
|
-
end
|
7
|
-
|
8
|
-
let(:table_name) { :users }
|
9
|
-
let(:relation_name) { ROM::Relation::Name.new(table_name) }
|
10
|
-
|
11
|
-
subject(:gateway) { container.gateways[:default] }
|
12
|
-
|
13
|
-
let(:inferrer) { ROM::SQL::Schema::Inferrer.new }
|
14
|
-
|
15
|
-
let(:migrated_schema) do
|
16
|
-
empty = define_schema(table_name)
|
17
|
-
empty.with(inferrer.(empty, gateway))
|
18
|
-
end
|
19
|
-
|
20
|
-
let(:attributes) { migrated_schema.to_a }
|
21
|
-
|
22
|
-
def indexdef(index)
|
23
|
-
gateway.connection[<<-SQL, index].first[:indexdef]
|
24
|
-
select indexdef
|
25
|
-
from pg_indexes
|
26
|
-
where indexname = ?
|
27
|
-
SQL
|
28
|
-
end
|
29
|
-
|
30
|
-
describe 'create table' do
|
31
|
-
describe 'one-column indexes' do
|
32
|
-
before do
|
33
|
-
conf.relation(:users) do
|
34
|
-
schema do
|
35
|
-
attribute :id, ROM::SQL::Types::Serial
|
36
|
-
attribute :name, ROM::SQL::Types::String.meta(index: true)
|
37
|
-
|
38
|
-
indexes do
|
39
|
-
index :name, name: :unique_name, unique: true
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'creates ordinary b-tree indexes' do
|
46
|
-
gateway.auto_migrate!(conf)
|
47
|
-
|
48
|
-
expect(attributes.map(&:to_ast))
|
49
|
-
.to eql([
|
50
|
-
[:attribute,
|
51
|
-
[:id,
|
52
|
-
[:definition, [Integer, {}]],
|
53
|
-
primary_key: true, source: :users]],
|
54
|
-
[:attribute,
|
55
|
-
[:name,
|
56
|
-
[:definition, [String, {}]],
|
57
|
-
source: :users]],
|
58
|
-
])
|
59
|
-
|
60
|
-
expect(migrated_schema.indexes.first).
|
61
|
-
to eql(ROM::SQL::Index.new(
|
62
|
-
[define_attribute(:name, :String, source: relation_name)],
|
63
|
-
name: :unique_name,
|
64
|
-
unique: true
|
65
|
-
))
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe 'alter table' do
|
71
|
-
describe 'one-column indexes' do
|
72
|
-
context 'adding' do
|
73
|
-
before do
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'adds indexed column' do
|
77
|
-
conn.create_table :users do
|
78
|
-
primary_key :id
|
79
|
-
end
|
80
|
-
|
81
|
-
conf.relation(:users) do
|
82
|
-
schema do
|
83
|
-
attribute :id, ROM::SQL::Types::Serial
|
84
|
-
attribute :name, ROM::SQL::Types::String.meta(index: true)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
gateway.auto_migrate!(conf)
|
89
|
-
|
90
|
-
name_index = migrated_schema.indexes.first
|
91
|
-
|
92
|
-
expect(migrated_schema.attributes[1].name).to eql(:name)
|
93
|
-
expect(migrated_schema.indexes.size).to eql(1)
|
94
|
-
expect(name_index.name).to eql(:users_name_index)
|
95
|
-
expect(name_index.attributes.map(&:name)).to eql(%i(name))
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'supports custom names' do
|
99
|
-
conn.create_table :users do
|
100
|
-
primary_key :id
|
101
|
-
end
|
102
|
-
|
103
|
-
conf.relation(:users) do
|
104
|
-
schema do
|
105
|
-
attribute :id, ROM::SQL::Types::Serial
|
106
|
-
attribute :name, ROM::SQL::Types::String
|
107
|
-
|
108
|
-
indexes do
|
109
|
-
index :name, name: :custom_idx
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
gateway.auto_migrate!(conf)
|
115
|
-
|
116
|
-
name_index = migrated_schema.indexes.first
|
117
|
-
|
118
|
-
expect(migrated_schema.attributes[1].name).to eql(:name)
|
119
|
-
expect(migrated_schema.indexes.size).to eql(1)
|
120
|
-
expect(name_index.name).to eql(:custom_idx)
|
121
|
-
expect(name_index.attributes.map(&:name)).to eql(%i(name))
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'adds index to existing column' do
|
125
|
-
conn.create_table :users do
|
126
|
-
primary_key :id
|
127
|
-
column :name, String
|
128
|
-
end
|
129
|
-
|
130
|
-
conf.relation(:users) do
|
131
|
-
schema do
|
132
|
-
attribute :id, ROM::SQL::Types::Serial
|
133
|
-
attribute :name, ROM::SQL::Types::String
|
134
|
-
|
135
|
-
indexes do
|
136
|
-
index :name
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
gateway.auto_migrate!(conf)
|
142
|
-
|
143
|
-
name_index = migrated_schema.indexes.first
|
144
|
-
|
145
|
-
expect(name_index.name).to eql(:users_name_index)
|
146
|
-
expect(name_index.attributes.map(&:name)).to eql(%i(name))
|
147
|
-
expect(name_index).not_to be_unique
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'supports unique indexes' do
|
151
|
-
conn.create_table :users do
|
152
|
-
primary_key :id
|
153
|
-
column :name, String
|
154
|
-
end
|
155
|
-
|
156
|
-
conf.relation(:users) do
|
157
|
-
schema do
|
158
|
-
attribute :id, ROM::SQL::Types::Serial
|
159
|
-
attribute :name, ROM::SQL::Types::String
|
160
|
-
|
161
|
-
indexes do
|
162
|
-
index :name, unique: true
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
gateway.auto_migrate!(conf)
|
168
|
-
|
169
|
-
name_index = migrated_schema.indexes.first
|
170
|
-
|
171
|
-
expect(name_index.name).to eql(:users_name_index)
|
172
|
-
expect(name_index.attributes.map(&:name)).to eql(%i(name))
|
173
|
-
expect(name_index).to be_unique
|
174
|
-
end
|
175
|
-
|
176
|
-
if metadata[:postgres]
|
177
|
-
it 'uses index method' do
|
178
|
-
conn.create_table :users do
|
179
|
-
primary_key :id
|
180
|
-
column :props, :jsonb, null: false
|
181
|
-
end
|
182
|
-
|
183
|
-
conf.relation(:users) do
|
184
|
-
schema do
|
185
|
-
attribute :id, ROM::SQL::Types::Serial
|
186
|
-
attribute :props, ROM::SQL::Types::PG::JSONB
|
187
|
-
|
188
|
-
indexes do
|
189
|
-
index :props, type: :gin
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
gateway.auto_migrate!(conf)
|
195
|
-
|
196
|
-
expect(indexdef('users_props_index')).
|
197
|
-
to eql('CREATE INDEX users_props_index ON users USING gin (props)')
|
198
|
-
end
|
199
|
-
|
200
|
-
it 'supports partial indexes' do
|
201
|
-
conn.create_table :users do
|
202
|
-
primary_key :id
|
203
|
-
column :name, String
|
204
|
-
end
|
205
|
-
|
206
|
-
conf.relation(:users) do
|
207
|
-
schema do
|
208
|
-
attribute :id, ROM::SQL::Types::Serial
|
209
|
-
attribute :name, ROM::SQL::Types::String
|
210
|
-
|
211
|
-
indexes do
|
212
|
-
index :name, name: :long_names_only, predicate: 'length(name) > 10'
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
gateway.auto_migrate!(conf)
|
218
|
-
|
219
|
-
expect(indexdef('long_names_only')).
|
220
|
-
to eql('CREATE INDEX long_names_only ON users USING btree (name) WHERE (length(name) > 10)')
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
context 'removing' do
|
226
|
-
before do
|
227
|
-
conf.relation(:users) do
|
228
|
-
schema do
|
229
|
-
attribute :id, ROM::SQL::Types::Serial
|
230
|
-
attribute :name, ROM::SQL::Types::String
|
231
|
-
attribute :email, ROM::SQL::Types::String
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
conn.create_table :users do
|
236
|
-
primary_key :id
|
237
|
-
column :name, String
|
238
|
-
column :email, String
|
239
|
-
|
240
|
-
index :name
|
241
|
-
index :email, name: :email_idx
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
it 'removes index' do
|
246
|
-
gateway.auto_migrate!(conf)
|
247
|
-
|
248
|
-
expect(migrated_schema.indexes).to be_empty
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
@@ -1,156 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::SQL::Gateway, :postgres, :helpers do
|
2
|
-
include_context 'database setup'
|
3
|
-
|
4
|
-
before do
|
5
|
-
conn.drop_table?(:users)
|
6
|
-
end
|
7
|
-
|
8
|
-
before do
|
9
|
-
conf.relation(:users) do
|
10
|
-
schema do
|
11
|
-
attribute :id, ROM::SQL::Types::Serial
|
12
|
-
attribute :name, ROM::SQL::Types::String
|
13
|
-
attribute :email, ROM::SQL::Types::String.optional
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
let(:table_name) { :users }
|
19
|
-
|
20
|
-
subject(:gateway) { container.gateways[:default] }
|
21
|
-
|
22
|
-
let(:inferrer) { ROM::SQL::Schema::Inferrer.new }
|
23
|
-
|
24
|
-
let(:migrated_schema) do
|
25
|
-
empty = define_schema(table_name)
|
26
|
-
empty.with(inferrer.(empty, gateway))
|
27
|
-
end
|
28
|
-
|
29
|
-
let(:attributes) { migrated_schema.to_a }
|
30
|
-
|
31
|
-
describe 'create a table' do
|
32
|
-
it 'creates a table from a relation' do
|
33
|
-
gateway.auto_migrate!(conf)
|
34
|
-
|
35
|
-
expect(attributes.map(&:to_ast))
|
36
|
-
.to eql([
|
37
|
-
[:attribute,
|
38
|
-
[:id,
|
39
|
-
[:definition, [Integer, {}]],
|
40
|
-
primary_key: true, source: :users]],
|
41
|
-
[:attribute, [:name, [:definition, [String, {}]], source: :users]],
|
42
|
-
[:attribute,
|
43
|
-
[:email,
|
44
|
-
[:sum,
|
45
|
-
[[:constrained,
|
46
|
-
[[:definition, [NilClass, {}]],
|
47
|
-
[:predicate, [:type?, [[:type, NilClass], [:input, ROM::Undefined]]]],
|
48
|
-
{}]],
|
49
|
-
[:definition, [String, {}]],
|
50
|
-
{}]],
|
51
|
-
source: :users]]
|
52
|
-
])
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe 'adding columns' do
|
57
|
-
before do
|
58
|
-
conn.create_table :users do
|
59
|
-
primary_key :id
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'adds columns to an existing table' do
|
64
|
-
gateway.auto_migrate!(conf)
|
65
|
-
|
66
|
-
expect(attributes[1].to_ast)
|
67
|
-
.to eql(
|
68
|
-
[:attribute, [:name, [:definition, [String, {}]], source: :users]]
|
69
|
-
)
|
70
|
-
expect(attributes[2].to_ast)
|
71
|
-
.to eql(
|
72
|
-
[:attribute,
|
73
|
-
[:email,
|
74
|
-
[:sum,
|
75
|
-
[[:constrained,
|
76
|
-
[[:definition, [NilClass, {}]],
|
77
|
-
[:predicate, [:type?, [[:type, NilClass], [:input, ROM::Undefined]]]],
|
78
|
-
{}]],
|
79
|
-
[:definition, [String, {}]],
|
80
|
-
{}]],
|
81
|
-
source: :users]]
|
82
|
-
)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe 'removing columns' do
|
87
|
-
before do
|
88
|
-
conn.create_table :users do
|
89
|
-
primary_key :id
|
90
|
-
column :name, String, null: false
|
91
|
-
column :email, String
|
92
|
-
column :age, Integer, null: false
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'removes columns from a table' do
|
97
|
-
gateway.auto_migrate!(conf)
|
98
|
-
|
99
|
-
expect(attributes.map(&:name)).to eql(%i(id name email))
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe 'empty diff' do
|
104
|
-
before do
|
105
|
-
conn.create_table :users do
|
106
|
-
primary_key :id
|
107
|
-
column :name, String, null: false
|
108
|
-
column :email, String
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'leaves existing schema' do
|
113
|
-
current = container.relations[:users].schema
|
114
|
-
|
115
|
-
gateway.auto_migrate!(conf)
|
116
|
-
|
117
|
-
expect(attributes).to eql(current.to_a)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe 'changing NOTNULL' do
|
122
|
-
describe 'adding' do
|
123
|
-
before do
|
124
|
-
conn.create_table :users do
|
125
|
-
primary_key :id
|
126
|
-
column :name, String
|
127
|
-
column :email, String
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'adds the constraint' do
|
132
|
-
gateway.auto_migrate!(conf)
|
133
|
-
|
134
|
-
expect(attributes[1].name).to eql(:name)
|
135
|
-
expect(attributes[1]).not_to be_optional
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe 'removing' do
|
140
|
-
before do
|
141
|
-
conn.create_table :users do
|
142
|
-
primary_key :id
|
143
|
-
column :name, String, null: false
|
144
|
-
column :email, String, null: false
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'removes the constraint' do
|
149
|
-
gateway.auto_migrate!(conf)
|
150
|
-
|
151
|
-
expect(attributes[2].name).to eql(:email)
|
152
|
-
expect(attributes[2]).to be_optional
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::SQL::Gateway, :postgres, :helpers do
|
2
|
-
include_context 'database setup'
|
3
|
-
|
4
|
-
before do
|
5
|
-
conn.drop_table?(:test_pg_types)
|
6
|
-
end
|
7
|
-
|
8
|
-
let(:table_name) { :test_pg_types }
|
9
|
-
|
10
|
-
subject(:gateway) { container.gateways[:default] }
|
11
|
-
|
12
|
-
let(:inferrer) { ROM::SQL::Schema::Inferrer.new }
|
13
|
-
|
14
|
-
let(:migrated_schema) do
|
15
|
-
empty = define_schema(table_name)
|
16
|
-
empty.with(inferrer.(empty, gateway))
|
17
|
-
end
|
18
|
-
|
19
|
-
let(:attributes) { migrated_schema.to_a }
|
20
|
-
|
21
|
-
describe 'common types' do
|
22
|
-
before do
|
23
|
-
conf.relation(:test_pg_types) do
|
24
|
-
schema do
|
25
|
-
attribute :id, ROM::SQL::Types::Serial
|
26
|
-
attribute :string, ROM::SQL::Types::String
|
27
|
-
attribute :int, ROM::SQL::Types::Int
|
28
|
-
attribute :time, ROM::SQL::Types::Time
|
29
|
-
attribute :date, ROM::SQL::Types::Date
|
30
|
-
attribute :decimal, ROM::SQL::Types::Decimal
|
31
|
-
attribute :string_nullable, ROM::SQL::Types::String.optional
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'has support for PG data types' do
|
37
|
-
gateway.auto_migrate!(conf)
|
38
|
-
|
39
|
-
expect(attributes.map(&:to_ast))
|
40
|
-
.to eql([
|
41
|
-
[:attribute,
|
42
|
-
[:id,
|
43
|
-
[:definition, [Integer, {}]],
|
44
|
-
primary_key: true, source: :test_pg_types]],
|
45
|
-
[:attribute, [:string, [:definition, [String, {}]], source: :test_pg_types]],
|
46
|
-
[:attribute, [:int, [:definition, [Integer, {}]], source: :test_pg_types]],
|
47
|
-
[:attribute, [:time, [:definition, [Time, {}]], source: :test_pg_types]],
|
48
|
-
[:attribute, [:date, [:definition, [Date, {}]], source: :test_pg_types]],
|
49
|
-
[:attribute, [:decimal, [:definition, [BigDecimal, {}]], source: :test_pg_types]],
|
50
|
-
[:attribute,
|
51
|
-
[:string_nullable,
|
52
|
-
[:sum,
|
53
|
-
[[:constrained,
|
54
|
-
[[:definition, [NilClass, {}]],
|
55
|
-
[:predicate, [:type?, [[:type, NilClass], [:input, ROM::Undefined]]]],
|
56
|
-
{}]],
|
57
|
-
[:definition, [String, {}]],
|
58
|
-
{}]],
|
59
|
-
source: :test_pg_types]]
|
60
|
-
])
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|