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,5 +1,9 @@
|
|
1
|
-
RSpec.describe 'Schema inference for common datatypes' do
|
2
|
-
include_context '
|
1
|
+
RSpec.describe 'Schema inference for common datatypes', seeds: false do
|
2
|
+
include_context 'users and tasks'
|
3
|
+
|
4
|
+
before do
|
5
|
+
inferrable_relations.concat %i(test_inferrence test_numeric)
|
6
|
+
end
|
3
7
|
|
4
8
|
let(:schema) { container.relations[dataset].schema }
|
5
9
|
|
@@ -22,10 +26,11 @@ RSpec.describe 'Schema inference for common datatypes' do
|
|
22
26
|
let(:source) { ROM::Relation::Name[dataset] }
|
23
27
|
|
24
28
|
it 'can infer attributes for dataset' do
|
25
|
-
expect(schema.to_h).
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
expect(schema.to_h).
|
30
|
+
to eql(
|
31
|
+
id: ROM::SQL::Types::Serial.meta(name: :id, source: source),
|
32
|
+
name: ROM::SQL::Types::String.meta(name: :name, source: source)
|
33
|
+
)
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
@@ -34,29 +39,35 @@ RSpec.describe 'Schema inference for common datatypes' do
|
|
34
39
|
let(:source) { ROM::Relation::Name[:tasks] }
|
35
40
|
|
36
41
|
it 'can infer attributes for dataset' do
|
37
|
-
expect(schema.to_h).
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
expect(schema.to_h).
|
43
|
+
to eql(
|
44
|
+
id: ROM::SQL::Types::Serial.meta(name: :id, source: source),
|
45
|
+
title: ROM::SQL::Types::String.optional.meta(name: :title, source: source),
|
46
|
+
user_id: ROM::SQL::Types::Int.optional.meta(
|
47
|
+
name: :user_id,
|
48
|
+
foreign_key: true,
|
49
|
+
source: source,
|
50
|
+
target: :users
|
51
|
+
)
|
52
|
+
)
|
45
53
|
end
|
46
54
|
end
|
47
55
|
|
48
56
|
context 'for complex table' do
|
49
57
|
before do |example|
|
50
58
|
ctx = self
|
51
|
-
conn.drop_table?(:test_inferrence)
|
52
59
|
|
53
60
|
conn.create_table :test_inferrence do
|
54
61
|
primary_key :id
|
55
62
|
String :text, null: false
|
56
|
-
Boolean :flag, null: false
|
57
63
|
Time :time
|
58
64
|
Date :date
|
59
|
-
|
65
|
+
|
66
|
+
if ctx.oracle?(example)
|
67
|
+
Date :datetime, null: false
|
68
|
+
else
|
69
|
+
DateTime :datetime, null: false
|
70
|
+
end
|
60
71
|
|
61
72
|
if ctx.sqlite?(example)
|
62
73
|
add_constraint(:test_constraint) { char_length(text) > 3 }
|
@@ -73,13 +84,14 @@ RSpec.describe 'Schema inference for common datatypes' do
|
|
73
84
|
let(:dataset) { :test_inferrence }
|
74
85
|
let(:source) { ROM::Relation::Name[dataset] }
|
75
86
|
|
76
|
-
it 'can infer attributes for dataset' do
|
87
|
+
it 'can infer attributes for dataset' do |ex|
|
88
|
+
date_type = oracle?(ex) ? ROM::SQL::Types::Time : ROM::SQL::Types::Date
|
89
|
+
|
77
90
|
expect(schema.to_h).to eql(
|
78
91
|
id: ROM::SQL::Types::Serial.meta(name: :id, source: source),
|
79
92
|
text: ROM::SQL::Types::String.meta(name: :text, source: source),
|
80
|
-
flag: ROM::SQL::Types::Bool.meta(name: :flag, source: source),
|
81
93
|
time: ROM::SQL::Types::Time.optional.meta(name: :time, source: source),
|
82
|
-
date:
|
94
|
+
date: date_type.optional.meta(name: :date, source: source),
|
83
95
|
datetime: ROM::SQL::Types::Time.meta(name: :datetime, source: source),
|
84
96
|
data: ROM::SQL::Types::Blob.optional.meta(name: :data, source: source),
|
85
97
|
)
|
@@ -87,10 +99,7 @@ RSpec.describe 'Schema inference for common datatypes' do
|
|
87
99
|
end
|
88
100
|
|
89
101
|
context 'numeric datatypes' do
|
90
|
-
before do
|
91
|
-
ctx = self
|
92
|
-
conn.drop_table?(:test_numeric)
|
93
|
-
|
102
|
+
before do
|
94
103
|
conn.create_table :test_numeric do
|
95
104
|
primary_key :id
|
96
105
|
decimal :dec, null: false
|
@@ -98,7 +107,6 @@ RSpec.describe 'Schema inference for common datatypes' do
|
|
98
107
|
numeric :num, size: [5, 2], null: false
|
99
108
|
smallint :small
|
100
109
|
integer :int
|
101
|
-
bigint :big
|
102
110
|
float :floating
|
103
111
|
double :double_p
|
104
112
|
end
|
@@ -107,15 +115,21 @@ RSpec.describe 'Schema inference for common datatypes' do
|
|
107
115
|
let(:dataset) { :test_numeric }
|
108
116
|
let(:source) { ROM::Relation::Name[dataset] }
|
109
117
|
|
118
|
+
let(:integer) { ROM::SQL::Types::Int.meta(source: source) }
|
110
119
|
let(:decimal) { ROM::SQL::Types::Decimal.meta(source: source) }
|
111
120
|
|
112
121
|
it 'infers attributes with precision' do |example|
|
113
122
|
if mysql?(example)
|
114
123
|
default_precision = decimal.meta(name: :dec, precision: 10, scale: 0)
|
124
|
+
elsif oracle?(example)
|
125
|
+
# Oracle treats DECIMAL as NUMBER(38, 0)
|
126
|
+
default_precision = integer.meta(name: :dec)
|
115
127
|
else
|
116
128
|
default_precision = decimal.meta(name: :dec)
|
117
129
|
end
|
118
130
|
|
131
|
+
pending 'Add precision inferrence for Oracle' if oracle?(example)
|
132
|
+
|
119
133
|
expect(schema.to_h).to eql(
|
120
134
|
id: ROM::SQL::Types::Serial.meta(name: :id, source: source),
|
121
135
|
dec: default_precision,
|
@@ -123,7 +137,6 @@ RSpec.describe 'Schema inference for common datatypes' do
|
|
123
137
|
num: decimal.meta(name: :num, precision: 5, scale: 2),
|
124
138
|
small: ROM::SQL::Types::Int.optional.meta(name: :small, source: source),
|
125
139
|
int: ROM::SQL::Types::Int.optional.meta(name: :int, source: source),
|
126
|
-
big: ROM::SQL::Types::Int.optional.meta(name: :big, source: source),
|
127
140
|
floating: ROM::SQL::Types::Float.optional.meta(name: :floating, source: source),
|
128
141
|
double_p: ROM::SQL::Types::Float.optional.meta(name: :double_p, source: source),
|
129
142
|
)
|
@@ -132,11 +145,13 @@ RSpec.describe 'Schema inference for common datatypes' do
|
|
132
145
|
end
|
133
146
|
|
134
147
|
describe 'using commands with inferred schema' do
|
148
|
+
before do
|
149
|
+
inferrable_relations.concat %i(people)
|
150
|
+
end
|
151
|
+
|
135
152
|
let(:relation) { container.relation(:people) }
|
136
153
|
|
137
154
|
before do
|
138
|
-
conn.drop_table?(:people)
|
139
|
-
|
140
155
|
conf.relation(:people) do
|
141
156
|
schema(dataset, infer: true)
|
142
157
|
end
|
@@ -218,21 +233,26 @@ RSpec.describe 'Schema inference for common datatypes' do
|
|
218
233
|
end
|
219
234
|
end
|
220
235
|
|
221
|
-
it 'accetps Time' do
|
236
|
+
it 'accetps Time' do |ex|
|
222
237
|
time = Time.iso8601('1970-01-01T06:00:00')
|
223
238
|
result = create.call(name: 'Jade', birth_date: time)
|
239
|
+
# Oracle's Date type stores time
|
240
|
+
expected_date = oracle?(ex) ? time : Date.iso8601('1970-01-01T00:00:00')
|
224
241
|
|
225
|
-
expect(result).to eql(id: 1, name: 'Jade', birth_date:
|
242
|
+
expect(result).to eql(id: 1, name: 'Jade', birth_date: expected_date)
|
226
243
|
end
|
227
244
|
end
|
228
245
|
|
229
246
|
unless metadata[:sqlite] && defined? JRUBY_VERSION
|
230
247
|
context 'timestamp' do
|
231
|
-
before do
|
248
|
+
before do |ex|
|
249
|
+
ctx = self
|
250
|
+
|
232
251
|
conn.create_table :people do
|
233
252
|
primary_key :id
|
234
253
|
String :name, null: false
|
235
|
-
|
254
|
+
# TODO: fix ROM, then Sequel to infer TIMESTAMP NOT NULL for Oracle
|
255
|
+
Timestamp :created_at, null: ctx.oracle?(ex)
|
236
256
|
end
|
237
257
|
end
|
238
258
|
|
@@ -259,7 +279,8 @@ RSpec.describe 'Schema inference for common datatypes' do
|
|
259
279
|
expect(result).to eql(id: 1, name: 'Jade', created_at: expected_time)
|
260
280
|
end
|
261
281
|
|
262
|
-
if
|
282
|
+
# TODO: Find out if Oracle's adapter really doesn't support RFCs
|
283
|
+
if !metadata[:mysql] && !metadata[:oracle]
|
263
284
|
it 'accepts strings in RFC 2822' do
|
264
285
|
now = Time.now
|
265
286
|
result = create.call(name: 'Jade', created_at: now.rfc822)
|
@@ -1,18 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe ROM::SQL::Schema, '#prefix' do
|
4
|
-
include_context '
|
3
|
+
RSpec.describe ROM::SQL::Schema, '#prefix', :postgres, seeds: false do
|
4
|
+
include_context 'users'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
schema(infer: true)
|
10
|
-
end
|
6
|
+
before do
|
7
|
+
conf.relation(:users) do
|
8
|
+
schema(infer: true)
|
11
9
|
end
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
12
|
+
it 'auto-projects a relation with renamed columns using provided prefix' do
|
13
|
+
expect(relations[:users].schema.prefix(:user).(relations[:users]).dataset.sql)
|
14
|
+
.to eql('SELECT "id" AS "user_id", "name" AS "user_name" FROM "users" ORDER BY "users"."id"')
|
17
15
|
end
|
18
16
|
end
|
@@ -1,18 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe ROM::SQL::Schema, '#qualified' do
|
4
|
-
include_context '
|
3
|
+
RSpec.describe ROM::SQL::Schema, '#qualified', :postgres, seeds: false do
|
4
|
+
include_context 'users'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
schema(infer: true)
|
10
|
-
end
|
6
|
+
before do
|
7
|
+
conf.relation(:users) do
|
8
|
+
schema(infer: true)
|
11
9
|
end
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
12
|
+
it 'qualifies column names' do
|
13
|
+
expect(relations[:users].schema.qualified.(relations[:users]).dataset.sql)
|
14
|
+
.to eql('SELECT "users"."id", "users"."name" FROM "users" ORDER BY "users"."id"')
|
17
15
|
end
|
18
16
|
end
|
@@ -1,23 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe ROM::SQL::Schema, '#rename' do
|
4
|
-
include_context '
|
3
|
+
RSpec.describe ROM::SQL::Schema, '#rename', :postgres, seeds: false do
|
4
|
+
include_context 'users'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
schema(infer: true)
|
10
|
-
end
|
6
|
+
before do
|
7
|
+
conf.relation(:users) do
|
8
|
+
schema(infer: true)
|
11
9
|
end
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
it 'auto-projects a relation with renamed columns' do
|
13
|
+
expect(relations[:users].schema.rename(id: :user_id, name: :user_name).(relations[:users]).dataset.sql)
|
14
|
+
.to eql('SELECT "id" AS "user_id", "name" AS "user_name" FROM "users" ORDER BY "users"."id"')
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
17
|
+
it 'auto-projects a relation with renamed and qualified columns' do
|
18
|
+
expect(relations[:users].schema.qualified.rename(id: :user_id, name: :user_name).(relations[:users]).dataset.sql)
|
19
|
+
.to eql('SELECT "users"."id" AS "user_id", "users"."name" AS "user_name" FROM "users" ORDER BY "users"."id"')
|
22
20
|
end
|
23
21
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe 'Defining a view using schemas' do
|
4
|
-
include_context '
|
3
|
+
RSpec.describe 'Defining a view using schemas', seeds: false do
|
4
|
+
include_context 'users'
|
5
5
|
|
6
6
|
with_adapters do
|
7
7
|
describe 'defining a projected view' do
|
@@ -1,11 +1,7 @@
|
|
1
|
-
RSpec.describe 'ROM.container'
|
1
|
+
RSpec.describe 'ROM.container' do
|
2
2
|
include_context 'database setup'
|
3
3
|
|
4
4
|
with_adapters do
|
5
|
-
before do
|
6
|
-
conn.drop_table?(:dragons)
|
7
|
-
end
|
8
|
-
|
9
5
|
let(:rom) do
|
10
6
|
ROM.container(:sql, uri) do |conf|
|
11
7
|
conf.default.create_table(:dragons) do
|
@@ -15,6 +11,10 @@ RSpec.describe 'ROM.container', skip_tables: true do
|
|
15
11
|
end
|
16
12
|
end
|
17
13
|
|
14
|
+
after do
|
15
|
+
rom.gateways[:default].connection.drop_table(:dragons)
|
16
|
+
end
|
17
|
+
|
18
18
|
it 'creates tables within the setup block' do
|
19
19
|
expect(rom.relations[:dragons]).to be_kind_of(ROM::SQL::Relation)
|
20
20
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe 'ActiveSupport::Notifications support', :postgres do
|
3
|
+
RSpec.describe 'ActiveSupport::Notifications support', :postgres, seeds: false do
|
4
4
|
before do
|
5
5
|
ROM::SQL.load_extensions(:active_support_notifications, :rails_log_subscriber)
|
6
6
|
end
|
7
7
|
|
8
|
-
include_context '
|
8
|
+
include_context 'users'
|
9
9
|
|
10
10
|
it 'works' do
|
11
11
|
container.gateways[:default].use_logger(LOGGER)
|
@@ -2,14 +2,14 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
require 'active_support/log_subscriber/test_helper'
|
4
4
|
|
5
|
-
RSpec.describe 'Rails log subscriber', :postgres do
|
5
|
+
RSpec.describe 'Rails log subscriber', :postgres, seeds: false do
|
6
6
|
before do
|
7
7
|
ROM::SQL.load_extensions(:active_support_notifications, :rails_log_subscriber)
|
8
8
|
end
|
9
9
|
|
10
10
|
include ActiveSupport::LogSubscriber::TestHelper
|
11
11
|
|
12
|
-
include_context '
|
12
|
+
include_context 'users'
|
13
13
|
|
14
14
|
let(:test_query) do
|
15
15
|
%(SELECT * FROM "users" WHERE name = 'notification test')
|
@@ -0,0 +1,44 @@
|
|
1
|
+
RSpec.shared_context 'accounts' do
|
2
|
+
let(:accounts) { container.relations[:accounts] }
|
3
|
+
let(:cards) { container.relations[:cards] }
|
4
|
+
|
5
|
+
before do
|
6
|
+
inferrable_relations.concat %i(accounts cards subscriptions)
|
7
|
+
end
|
8
|
+
|
9
|
+
before do |example|
|
10
|
+
ctx = self
|
11
|
+
|
12
|
+
conn.create_table :accounts do
|
13
|
+
primary_key :id
|
14
|
+
Integer :user_id
|
15
|
+
String :number
|
16
|
+
|
17
|
+
if ctx.oracle?(example)
|
18
|
+
Number :balance
|
19
|
+
else
|
20
|
+
Decimal :balance, size: [10, 2]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
conn.create_table :cards do
|
25
|
+
primary_key :id
|
26
|
+
Integer :account_id
|
27
|
+
String :pan
|
28
|
+
end
|
29
|
+
|
30
|
+
conn.create_table :subscriptions do
|
31
|
+
primary_key :id
|
32
|
+
Integer :card_id
|
33
|
+
String :service
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
before do |example|
|
38
|
+
next if example.metadata[:seeds] == false
|
39
|
+
|
40
|
+
conn[:accounts].insert user_id: 1, number: '42', balance: 10_000.to_d
|
41
|
+
conn[:cards].insert id: 1, account_id: 1, pan: '*6789'
|
42
|
+
conn[:subscriptions].insert id: 1, card_id: 1, service: 'aws'
|
43
|
+
end
|
44
|
+
end
|
@@ -1,4 +1,19 @@
|
|
1
|
-
shared_context 'database setup' do
|
1
|
+
RSpec.shared_context 'database setup' do
|
2
|
+
all_tables = %i(users tasks users_tasks tags task_tags posts puppies
|
3
|
+
accounts cards subscriptions notes
|
4
|
+
destinations flights categories user_group
|
5
|
+
test_inferrence test_bidirectional people dragons
|
6
|
+
rabbits carrots names schema_migrations)
|
7
|
+
|
8
|
+
cleared_dbs = []
|
9
|
+
|
10
|
+
before do
|
11
|
+
unless cleared_dbs.include?(conn.database_type)
|
12
|
+
all_tables.reverse.each { |table| conn.drop_table?(table) }
|
13
|
+
cleared_dbs << conn.database_type
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
2
17
|
let(:uri) do |example|
|
3
18
|
meta = example.metadata
|
4
19
|
adapters = ADAPTERS.select { |adapter| meta[adapter] }
|
@@ -12,97 +27,43 @@ shared_context 'database setup' do
|
|
12
27
|
end
|
13
28
|
|
14
29
|
let(:conn) { Sequel.connect(uri) }
|
15
|
-
let(:
|
30
|
+
let(:database_type) { conn.database_type }
|
31
|
+
let(:inferrable_relations) { [] }
|
32
|
+
let(:conf) { ROM::Configuration.new(:sql, conn, inferrable_relations: inferrable_relations) }
|
16
33
|
let(:container) { ROM.container(conf) }
|
17
34
|
let(:relations) { container.relations }
|
18
35
|
let(:commands) { container.commands }
|
19
36
|
|
20
|
-
|
21
|
-
%i(task_tags users_tasks tasks tags
|
22
|
-
subscriptions cards accounts
|
23
|
-
posts users
|
24
|
-
rabbits carrots notes
|
25
|
-
puppies schema_migrations
|
26
|
-
).each do |name|
|
27
|
-
conn.drop_table?(name)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
before do |example|
|
32
|
-
ctx = self
|
37
|
+
before do
|
33
38
|
conn.loggers << LOGGER
|
39
|
+
end
|
34
40
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
check { char_length(name) > 2 } if ctx.postgres?(example)
|
42
|
-
end
|
43
|
-
|
44
|
-
conn.create_table :tasks do
|
45
|
-
primary_key :id
|
46
|
-
foreign_key :user_id, :users
|
47
|
-
String :title, unique: true
|
48
|
-
constraint(:title_length) { char_length(title) > 1 } if ctx.postgres?(example)
|
49
|
-
constraint(:title_length) { length(title) > 1 } if ctx.sqlite?(example)
|
50
|
-
end
|
51
|
-
|
52
|
-
conn.create_table :tags do
|
53
|
-
primary_key :id
|
54
|
-
String :name
|
55
|
-
end
|
56
|
-
|
57
|
-
conn.create_table :task_tags do
|
58
|
-
primary_key [:tag_id, :task_id]
|
59
|
-
Integer :tag_id
|
60
|
-
Integer :task_id
|
61
|
-
end
|
62
|
-
|
63
|
-
conn.create_table :posts do
|
64
|
-
primary_key :post_id
|
65
|
-
foreign_key :author_id, :users
|
66
|
-
String :title
|
67
|
-
String :body
|
68
|
-
end
|
69
|
-
|
70
|
-
conn.create_table :accounts do
|
71
|
-
primary_key :id
|
72
|
-
Integer :user_id
|
73
|
-
String :number
|
74
|
-
Decimal :balance
|
75
|
-
end
|
76
|
-
|
77
|
-
conn.create_table :cards do
|
78
|
-
primary_key :id
|
79
|
-
Integer :account_id
|
80
|
-
String :pan
|
81
|
-
end
|
82
|
-
|
83
|
-
conn.create_table :subscriptions do
|
84
|
-
primary_key :id
|
85
|
-
Integer :card_id
|
86
|
-
String :service
|
87
|
-
end
|
41
|
+
after do
|
42
|
+
conn.disconnect
|
43
|
+
# Prevent the auto-reconnect when the test completed
|
44
|
+
# This will save from hardly reproducible connection run outs
|
45
|
+
conn.pool.available_connections.freeze
|
46
|
+
end
|
88
47
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
TrueClass :cute, null: false, default: true
|
48
|
+
after do
|
49
|
+
inferrable_relations.reverse.each do |name|
|
50
|
+
conn.drop_table?(name)
|
93
51
|
end
|
52
|
+
end
|
94
53
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
DateTime :completed_at
|
101
|
-
Date :written
|
54
|
+
def db_true
|
55
|
+
if database_type == :oracle
|
56
|
+
'Y'
|
57
|
+
else
|
58
|
+
true
|
102
59
|
end
|
103
60
|
end
|
104
61
|
|
105
|
-
|
106
|
-
|
62
|
+
def db_false
|
63
|
+
if database_type == :oracle
|
64
|
+
'N'
|
65
|
+
else
|
66
|
+
false
|
67
|
+
end
|
107
68
|
end
|
108
69
|
end
|