rails_db_views 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 377a7268197020fe62a087261f12cd94ead05b30
4
- data.tar.gz: 90090417d3607056ba577fa159f6b29366ca870b
3
+ metadata.gz: b7e969668533cd8b06db487903d6c8f98cdcef46
4
+ data.tar.gz: 8d14a8ff8d30f9d82a4a4f75854932776d9ce611
5
5
  SHA512:
6
- metadata.gz: a1f7de8e87be5f0de472bcc4a19d11934b69bee78520ed7704c0b33c686e7d942af8755c66a644757c076b073d1e77490aab5f945f219f61046b6efc3ddef446
7
- data.tar.gz: 13c1b6a148618a475a9185fcaaba6b41e7905de85eaa0d4a45b7c373fa169b679b51748fe7a319361a6ec3fb860ec8bde007dc6dcbcfd03aedbecf8ed1d5b8cc
6
+ metadata.gz: 08f002d1eb0b886d94315875e02006e8d59d7b8d1cc9491be92429df638aee5f51c9beb35b35d9b51afb6c89ce4fce2cb8fdc46db83aff50ca876a2fc7b62547
7
+ data.tar.gz: 790a04c20ab6a88abb9f8b84102141fa8ea3fec7078f66a60a8db949efa7d113582897ee04e2964cc854d440f8992ab37a1a925ebc9413f86b8cf03d7b85abc0
@@ -1,9 +1,10 @@
1
1
  module RailsDbViews
2
2
  unless defined?(Rails)
3
- raise "This gem is made for Ruby on Rails!"
3
+ raise LoadError, "rails_db_views gem is made for Ruby on Rails !"
4
4
  end
5
5
  end
6
6
 
7
+ require 'rails_db_views/exceptions'
7
8
  require 'rails_db_views/railtie'
8
9
  require 'rails_db_views/database_symbol'
9
10
  require 'rails_db_views/view'
@@ -1,10 +1,9 @@
1
1
  class RailsDbViews::DatabaseSymbol
2
- class CircularReferenceError < RuntimeError; end
3
- class SymbolNotFound < RuntimeError; end
4
-
5
2
  attr_accessor :path, :sql_content, :status, :required, :inverse_of_required, :marked_as_deleted, :name
6
3
  alias :marked_as_deleted? :marked_as_deleted
7
4
 
5
+ STRING_INTERPOLATION = /((.?)\#\{([^\}]*)\})/
6
+
8
7
  module Status
9
8
  LOADED = :loaded
10
9
  IN_PROGRESS = :in_progress
@@ -48,8 +47,19 @@ class RailsDbViews::DatabaseSymbol
48
47
  status == Status::UNLOADED
49
48
  end
50
49
 
50
+
51
+ def process_string_interpolation str
52
+ str.gsub(STRING_INTERPOLATION) do |x|
53
+ if $2 == '\\'
54
+ $1[1..-1] #Rendering the whole expression because of escape char.
55
+ else
56
+ $2 + (TOPLEVEL_BINDING.eval($3)).to_s
57
+ end
58
+ end
59
+ end
60
+
51
61
  def uncommented_sql_content
52
- sql_content.split("\n").reject{|x| x=~ COMMENTS }.join("\n")
62
+ process_string_interpolation(sql_content.split("\n").reject{|x| x=~ COMMENTS }.join("\n"))
53
63
  end
54
64
 
55
65
  def create!
@@ -117,11 +127,11 @@ protected
117
127
  COMMENTS = /#{COMMENTS_TWO_DASH}|#{COMMENTS_SHARP}/
118
128
 
119
129
  def circular_reference_error
120
- raise CircularReferenceError, "Circular file reference! (file: #{path})"
130
+ raise RailsDbViews::CircularReferenceError, "Circular file reference! (file: #{path})"
121
131
  end
122
132
 
123
133
  def not_found_error(symbol_name)
124
- raise SymbolNotFound, "#{self.class.name} `#{symbol_name}` referenced in file #{path} cannot be found..."
134
+ raise RailsDbViews::SymbolNotFound, "#{self.class.name} `#{symbol_name}` referenced in file #{path} cannot be found..."
125
135
  end
126
136
 
127
137
  def load_directives
@@ -135,10 +145,10 @@ protected
135
145
  case d
136
146
  when /^require /
137
147
  self.required += d.split(/[ \t]+/)[1..-1]
138
- when /^delete(d?) /
148
+ when /^delete(d?)/
139
149
  self.mark_as_delete!
140
150
  else
141
- raise IllegalDirective, "I don't know what to do with `#{d}` (in #{path})"
151
+ raise RailsDbViews::IllegalDirective, "I don't know what to do with `#{d}` (in #{path})"
142
152
  end
143
153
  end
144
154
 
@@ -0,0 +1,7 @@
1
+ module RailsDbViews
2
+ class CircularReferenceError < RuntimeError; end
3
+
4
+ class SymbolNotFound < RuntimeError; end
5
+ class IllegalDirective < RuntimeError; end
6
+ class AmbigousNameError < RuntimeError; end
7
+ end
@@ -1,6 +1,5 @@
1
1
 
2
2
  class RailsDbViews::Factory
3
- class AmbigousNameError < RuntimeError; end
4
3
 
5
4
  @symbols = {}
6
5
 
@@ -14,7 +13,7 @@ class RailsDbViews::Factory
14
13
  symbol = symbol_class.new(file)
15
14
 
16
15
  if s=@symbols[symbol_class.to_s][symbol.name]
17
- raise AmbigousNameError, "between #{file} and #{s.path}"
16
+ raise RailsDbViews::AmbigousNameError, "between #{file} and #{s.path}"
18
17
  end
19
18
 
20
19
  @symbols[symbol_class.to_s][symbol.name] = symbol
@@ -1,3 +1,3 @@
1
1
  module RailsDbViews
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  # This is the request for virtual chat object.
2
2
  # !require messages
3
- SELECT tuple_sort(ARRAY[sender_id, receiver_id]) AS ids,
3
+ SELECT #{"tuple_sort"}(ARRAY[sender_id, receiver_id]) AS ids,
4
4
  MIN(created_at) as created_at, MAX(updated_at) as updated_at, COUNT(*) as number_of_messages
5
5
  FROM messages
6
6
  GROUP BY tuple_sort(ARRAY[sender_id, receiver_id])
@@ -2,7 +2,7 @@
2
2
  -- output:
3
3
  -- receiver_name, receiver_id, sender_name, sender_id, content, updated_at, created_at
4
4
  SELECT DISTINCT _.receiver_name, _.receiver_id, _.sender_name, _.sender_id, _.content, _.updated_at, _.created_at
5
- FROM
5
+ FROM #{puts "This is evaluated in Ruby."; ""}
6
6
  (SELECT u2.name as receiver_name, u2.id as receiver_id,
7
7
  u1.name as sender_name, u1.id as sender_id,
8
8
  um.content as content, um.updated_at as updated_at, um.created_at as created_at
@@ -1,533 +1,29 @@
1
-  (1.5ms) CREATE VIEW hello_world AS SELECT 'HelloWorld'
2
-  (0.2ms) CREATE VIEW hello_world AS SELECT 'HelloWorld'
3
- SQLite3::SQLException: table hello_world already exists: CREATE VIEW hello_world AS SELECT 'HelloWorld'
4
-  (0.3ms) CREATE VIEW hello_world AS SELECT 'HelloWorld'
5
- SQLite3::SQLException: table hello_world already exists: CREATE VIEW hello_world AS SELECT 'HelloWorld'
6
-  (1.6ms) DROP VIEW hello_world
7
-  (0.1ms) DROP VIEW required
8
- SQLite3::SQLException: no such view: required: DROP VIEW required
9
-  (0.9ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
10
-  (0.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
11
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
12
-  (1.0ms) CREATE VIEW hello_world AS SELECT 'HelloWorld'
13
-  (0.8ms) CREATE VIEW required AS SELECT 1
14
-  (2.0ms) DROP VIEW hello_world
15
-  (1.0ms) DROP VIEW required
16
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
17
-  (0.1ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT * AS required ) = 1
18
- SQLite3::SQLException: near "AS": syntax error: CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT * AS required ) = 1
19
-  (0.3ms) DROP VIEW hello_world
20
- SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
21
-  (0.1ms) DROP VIEW required
22
- SQLite3::SQLException: no such view: required: DROP VIEW required
23
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
24
-  (0.1ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id AS required ) IN (1)
25
- SQLite3::SQLException: no such column: id: CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id AS required ) IN (1)
26
-  (0.3ms) DROP VIEW hello_world
27
- SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
28
-  (0.1ms) DROP VIEW required
29
- SQLite3::SQLException: no such view: required: DROP VIEW required
30
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
31
-  (0.1ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
32
- SQLite3::SQLException: no such table: main.required: CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
33
-  (0.4ms) DROP VIEW hello_world
34
- SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
35
-  (0.1ms) DROP VIEW required
36
- SQLite3::SQLException: no such view: required: DROP VIEW required
37
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
38
-  (0.2ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
39
- SQLite3::SQLException: no such table: main.required: CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
40
-  (0.3ms) DROP VIEW hello_world
41
- SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
42
-  (0.1ms) DROP VIEW required
43
- SQLite3::SQLException: no such view: required: DROP VIEW required
44
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
45
-  (0.1ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
46
- SQLite3::SQLException: no such table: main.required: CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
47
-  (0.3ms) DROP VIEW hello_world
48
- SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
49
-  (0.1ms) DROP VIEW required
50
- SQLite3::SQLException: no such view: required: DROP VIEW required
51
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
52
-  (0.2ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
53
- SQLite3::SQLException: no such table: main.required: CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
54
-  (0.3ms) DROP VIEW hello_world
55
- SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
56
-  (0.1ms) DROP VIEW required
57
- SQLite3::SQLException: no such view: required: DROP VIEW required
58
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
59
-  (1.3ms) CREATE VIEW hello_world AS SELECT 1 as id
60
-  (0.1ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
61
- SQLite3::SQLException: table hello_world already exists: CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
62
-  (1.9ms) DROP VIEW hello_world
63
-  (0.2ms) DROP VIEW required
64
- SQLite3::SQLException: no such view: required: DROP VIEW required
65
-  (0.5ms) DROP VIEW hello_world
66
- SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
67
-  (0.1ms) DROP VIEW required
68
- SQLite3::SQLException: no such view: required: DROP VIEW required
69
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
70
-  (0.9ms) CREATE VIEW hello_world AS SELECT 1 as id
71
-  (0.1ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
72
- SQLite3::SQLException: table hello_world already exists: CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
73
-  (1.6ms) DROP VIEW hello_world
74
-  (0.1ms) DROP VIEW required
75
- SQLite3::SQLException: no such view: required: DROP VIEW required
76
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
77
-  (1.0ms) CREATE VIEW hello_world AS SELECT 1 as id
78
-  (0.1ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
79
- SQLite3::SQLException: table hello_world already exists: CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
80
-  (2.1ms) DROP VIEW hello_world
81
-  (0.2ms) DROP VIEW required
82
- SQLite3::SQLException: no such view: required: DROP VIEW required
83
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
84
-  (1.0ms) CREATE VIEW hello_world AS SELECT 1 as id
85
-  (0.1ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
86
- SQLite3::SQLException: table hello_world already exists: CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
87
-  (1.2ms) DROP VIEW hello_world
88
-  (0.1ms) DROP VIEW required
89
- SQLite3::SQLException: no such view: required: DROP VIEW required
90
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
91
-  (0.3ms) DROP VIEW hello_world
92
- SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
93
-  (0.1ms) DROP VIEW required
94
- SQLite3::SQLException: no such view: required: DROP VIEW required
95
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
96
-  (0.3ms) DROP VIEW hello_world
97
- SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
98
-  (0.1ms) DROP VIEW required
99
- SQLite3::SQLException: no such view: required: DROP VIEW required
100
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
101
-  (0.1ms) SELECT 1 as id
102
-  (0.1ms) SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
103
- SQLite3::SQLException: no such table: required: SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
104
-  (0.4ms) DROP VIEW hello_world
105
- SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
106
-  (0.1ms) DROP VIEW required
107
- SQLite3::SQLException: no such view: required: DROP VIEW required
108
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
109
-  (0.1ms) SELECT 1 as id
110
-  (0.1ms) SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
111
- SQLite3::SQLException: no such table: required: SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
112
-  (0.3ms) DROP VIEW required
113
- SQLite3::SQLException: no such view: required: DROP VIEW required
114
-  (0.2ms) DROP VIEW hello_world
115
- SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
116
-  (0.1ms) DROP VIEW required
117
- SQLite3::SQLException: no such view: required: DROP VIEW required
118
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
119
-  (0.1ms) SELECT 1 as id
120
-  (0.1ms) SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
121
- SQLite3::SQLException: no such table: required: SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
122
-  (0.3ms) DROP VIEW required
123
- SQLite3::SQLException: no such view: required: DROP VIEW required
124
-  (0.1ms) DROP VIEW hello_world
125
- SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
126
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
127
-  (0.1ms) SELECT 1 as id
128
-  (0.1ms) SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
129
- SQLite3::SQLException: no such table: required: SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
130
-  (0.1ms) DROP VIEW DROP VIEW required
131
- SQLite3::SQLException: near "DROP": syntax error: DROP VIEW DROP VIEW required
132
-  (0.1ms) DROP VIEW DROP VIEW hello_world
133
- SQLite3::SQLException: near "DROP": syntax error: DROP VIEW DROP VIEW hello_world
134
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
135
-  (1.1ms) CREATE VIEW required AS SELECT 1 as id
136
-  (1.1ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
137
-  (0.1ms) DROP VIEW DROP VIEW required
138
- SQLite3::SQLException: near "DROP": syntax error: DROP VIEW DROP VIEW required
139
-  (0.1ms) DROP VIEW DROP VIEW hello_world
140
- SQLite3::SQLException: near "DROP": syntax error: DROP VIEW DROP VIEW hello_world
141
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
142
-  (0.1ms) CREATE VIEW required AS SELECT 1 as id
143
- SQLite3::SQLException: table required already exists: CREATE VIEW required AS SELECT 1 as id
144
-  (2.2ms) DROP VIEW required
145
-  (0.9ms) DROP VIEW hello_world
146
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
147
-  (1.0ms) CREATE VIEW required AS SELECT 1 as id
148
-  (0.9ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
149
-  (2.1ms) DROP VIEW required
150
-  (1.1ms) DROP VIEW hello_world
151
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
152
-  (1.1ms) CREATE VIEW required AS SELECT 1 as id
153
-  (0.9ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
154
-  (1.8ms) DROP VIEW required
155
-  (0.8ms) DROP VIEW hello_world
156
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
157
-  (0.8ms) CREATE VIEW required AS SELECT 1 as id
158
-  (0.9ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
159
-  (1.8ms) DROP VIEW required
160
-  (0.9ms) DROP VIEW hello_world
161
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
162
-  (0.8ms) CREATE VIEW required AS SELECT 1 as id
163
-  (0.8ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
164
-  (1.6ms) DROP VIEW required
165
-  (1.0ms) DROP VIEW hello_world
166
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
167
-  (0.9ms) CREATE VIEW required AS SELECT 1 as id
168
-  (1.1ms) CREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
169
-  (0.2ms) CREATE OR REPLACE FUNCTION (x integer, y integer) RETURNS integer AS $$
170
- BEGIN
171
- RETURN x + y;
172
- END;
173
- $$ LANGUAGE plpgsql; add.sql
174
- SQLite3::SQLException: near "OR": syntax error: CREATE OR REPLACE FUNCTION (x integer, y integer) RETURNS integer AS $$
175
- BEGIN
176
- RETURN x + y;
177
- END;
178
- $$ LANGUAGE plpgsql; add.sql
179
-  (0.2ms) DROP FUNCTION add.sql
180
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
181
-  (0.1ms) DROP FUNCTION add.sql
182
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
183
-  (0.2ms) DROP FUNCTION add.sql
184
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
185
-  (0.1ms) DROP FUNCTION add.sql
186
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
187
-  (0.2ms) DROP FUNCTION add.sql
188
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
189
-  (0.2ms) DROP FUNCTION add.sql
190
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
191
-  (0.2ms) DROP FUNCTION add.sql
192
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
193
-  (0.2ms) DROP FUNCTION add.sql
194
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
195
-  (0.2ms) DROP FUNCTION add.sql
196
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
197
-  (0.2ms) DROP FUNCTION add.sql
198
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
199
-  (0.1ms) DROP FUNCTION add.sql
200
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
201
-  (0.2ms) DROP FUNCTION add.sql
202
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
203
-  (0.2ms) DROP FUNCTION add
204
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
205
-  (0.2ms) CREATE VIEW required
206
- SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
207
-  (0.1ms) CREATE VIEW hello_world
208
- SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
209
-  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
210
-  (0.1ms) select sqlite_version(*)
211
-  (0.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
212
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
213
-  (0.1ms) CREATE VIEW SELECT 1 as id
214
- SQLite3::SQLException: near "SELECT": syntax error: CREATE VIEW SELECT 1 as id
215
-  (0.2ms) DROP FUNCTION add
216
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
217
-  (0.2ms) CREATE VIEW required
218
- SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
219
-  (0.2ms) CREATE VIEW hello_world
220
- SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
221
-  (1.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
222
-  (0.1ms) select sqlite_version(*)
223
-  (0.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
224
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
225
-  (0.1ms) CREATE VIEW SELECT 1 as id
226
- SQLite3::SQLException: near "SELECT": syntax error: CREATE VIEW SELECT 1 as id
227
-  (0.2ms) DROP FUNCTION add
228
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
229
-  (0.1ms) CREATE VIEW required
230
- SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
231
-  (0.1ms) CREATE VIEW hello_world
232
- SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
233
-  (1.9ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
234
-  (0.1ms) select sqlite_version(*)
235
-  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
236
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
237
-  (1.0ms) CREATE VIEW required AS SELECT 1 as id
238
-  (0.2ms) DROP FUNCTION add
239
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
240
-  (0.1ms) CREATE VIEW required
241
- SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
242
-  (0.1ms) CREATE VIEW hello_world
243
- SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
244
-  (1.4ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
245
-  (0.1ms) select sqlite_version(*)
246
-  (0.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
247
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
248
-  (0.7ms) CREATE VIEW required AS SELECT 1 as id
249
-  (0.9ms) CREATE VIEW hello_world AS --!require required
250
- SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
251
-  (0.2ms) DROP FUNCTION add
252
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
253
-  (0.1ms) CREATE VIEW required
254
- SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
255
-  (0.1ms) CREATE VIEW hello_world
256
- SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
257
-  (1.4ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
258
-  (0.1ms) select sqlite_version(*)
259
-  (0.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
260
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
261
-  (0.8ms) CREATE VIEW required AS SELECT 1 as id
262
-  (0.9ms) CREATE VIEW hello_world AS --!require required
263
- SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
264
-  (0.2ms) DROP FUNCTION add
265
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
266
-  (0.1ms) CREATE VIEW required
267
- SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
268
-  (0.1ms) CREATE VIEW hello_world
269
- SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
270
-  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
271
-  (0.1ms) select sqlite_version(*)
272
-  (1.0ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
273
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
274
-  (0.9ms) CREATE VIEW required AS SELECT 1 as id
275
-  (0.8ms) CREATE VIEW hello_world AS --!require required
276
- SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
277
-  (0.2ms) DROP FUNCTION add
278
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
279
-  (0.1ms) CREATE VIEW required
280
- SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
281
-  (0.1ms) CREATE VIEW hello_world
282
- SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
283
-  (1.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
284
-  (0.1ms) select sqlite_version(*)
285
-  (0.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
286
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
287
-  (0.8ms) CREATE VIEW required AS SELECT 1 as id
288
-  (1.1ms) CREATE VIEW hello_world AS --!require required
289
- SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
290
-  (0.2ms) CREATE VIEW required
291
- SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
292
-  (0.1ms) CREATE VIEW hello_world
293
- SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
294
-  (1.1ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
295
-  (0.1ms) select sqlite_version(*)
296
-  (0.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
297
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
298
-  (3.9ms) CREATE VIEW required AS SELECT 1 as id
299
-  (0.9ms) CREATE VIEW hello_world AS --!require required
300
- SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
301
-  (0.2ms) DROP FUNCTION add
302
- SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
303
-  (0.2ms) CREATE VIEW required
304
- SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
305
-  (0.4ms) DROP VIEW required
306
- SQLite3::SQLException: no such view: required: DROP VIEW required
307
-  (0.3ms) DROP VIEW required
308
- SQLite3::SQLException: no such view: required: DROP VIEW required
309
-  (0.3ms) DROP VIEW required
310
- SQLite3::SQLException: no such view: required: DROP VIEW required
311
-  (0.3ms) DROP VIEW required
312
- SQLite3::SQLException: no such view: required: DROP VIEW required
313
-  (0.1ms) DROP VIEW hello_world
314
- SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
315
-  (1.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
316
-  (0.1ms) select sqlite_version(*)
317
-  (0.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
318
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
319
-  (0.7ms) CREATE VIEW required AS SELECT 1 as id
320
-  (0.7ms) CREATE VIEW hello_world AS --!require required
321
- SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
322
-  (0.3ms) DROP VIEW required
323
- SQLite3::SQLException: no such view: required: DROP VIEW required
324
-  (0.2ms) DROP VIEW hello_world
325
- SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
326
-  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
327
-  (0.1ms) select sqlite_version(*)
328
-  (0.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
329
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
330
-  (4.8ms) CREATE VIEW required AS SELECT 1 as id
331
-  (1.3ms) CREATE VIEW hello_world AS --!require required
332
- SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
333
-  (0.9ms) CREATE OR REPLACE FUNCTION (x integer, y integer) RETURNS integer AS $$
334
- BEGIN
335
- RETURN x + y;
336
- END;
337
- $$ LANGUAGE plpgsql; add
338
- PG::SyntaxError: ERROR: syntax error at or near "("
339
- LINE 1: CREATE OR REPLACE FUNCTION (x integer, y integer) RETURNS in...
340
- ^
341
- : CREATE OR REPLACE FUNCTION (x integer, y integer) RETURNS integer AS $$
342
- BEGIN
343
- RETURN x + y;
344
- END;
345
- $$ LANGUAGE plpgsql; add
346
-  (0.3ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
347
- BEGIN
348
- RETURN x + y;
349
- END;
350
- $$ LANGUAGE plpgsql; add
351
- PG::SyntaxError: ERROR: syntax error at or near "add"
352
- LINE 5: $$ LANGUAGE plpgsql; add
353
- ^
354
- : CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
355
- BEGIN
356
- RETURN x + y;
357
- END;
358
- $$ LANGUAGE plpgsql; add
359
-  (8.7ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
360
- BEGIN
361
- RETURN x + y;
362
- END;
363
- $$ LANGUAGE plpgsql;
364
-  (17.7ms) DROP VIEW required
365
- PG::UndefinedTable: ERROR: view "required" does not exist
366
- : DROP VIEW required
367
-  (0.3ms) DROP VIEW hello_world
368
- PG::UndefinedTable: ERROR: view "hello_world" does not exist
369
- : DROP VIEW hello_world
370
-  (24.1ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL)
371
-  (1.0ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
372
- ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
373
-  (23.3ms) CREATE VIEW required AS SELECT 1 as id
374
-  (5.5ms) CREATE VIEW hello_world AS --!require required
375
- SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
376
-  (12.3ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
377
- BEGIN
378
- RETURN x + y;
379
- END;
380
- $$ LANGUAGE plpgsql;
381
-  (10.6ms) DROP VIEW required
382
- PG::DependentObjectsStillExist: ERROR: cannot drop view required because other objects depend on it
383
- DETAIL: view hello_world depends on view required
384
- HINT: Use DROP ... CASCADE to drop the dependent objects too.
385
- : DROP VIEW required
386
-  (18.0ms) DROP VIEW hello_world
387
- ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
388
-  (0.2ms) CREATE VIEW required AS SELECT 1 as id
389
- PG::DuplicateTable: ERROR: relation "required" already exists
390
- : CREATE VIEW required AS SELECT 1 as id
391
-  (2.5ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
392
- BEGIN
393
- RETURN x + y;
394
- END;
395
- $$ LANGUAGE plpgsql;
396
-  (1.0ms) DROP VIEW required
397
-  (0.4ms) DROP VIEW hello_world
398
- PG::UndefinedTable: ERROR: view "hello_world" does not exist
399
- : DROP VIEW hello_world
400
- ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
401
-  (8.1ms) CREATE VIEW required AS SELECT 1 as id
402
-  (6.6ms) CREATE VIEW hello_world AS --!require required
403
- SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
404
-  (2.0ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
405
- BEGIN
406
- RETURN x + y;
407
- END;
408
- $$ LANGUAGE plpgsql;
409
-  (0.6ms) DROP VIEW required
410
- PG::DependentObjectsStillExist: ERROR: cannot drop view required because other objects depend on it
411
- DETAIL: view hello_world depends on view required
412
- HINT: Use DROP ... CASCADE to drop the dependent objects too.
413
- : DROP VIEW required
414
-  (0.9ms) DROP VIEW hello_world
415
- ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
416
-  (0.3ms) CREATE VIEW required AS SELECT 1 as id
417
- PG::DuplicateTable: ERROR: relation "required" already exists
418
- : CREATE VIEW required AS SELECT 1 as id
419
-  (2.1ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
420
- BEGIN
421
- RETURN x + y;
422
- END;
423
- $$ LANGUAGE plpgsql;
424
-  (0.9ms) DROP VIEW required
425
-  (0.3ms) DROP VIEW hello_world
426
- PG::UndefinedTable: ERROR: view "hello_world" does not exist
427
- : DROP VIEW hello_world
428
-  (2.0ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
429
- BEGIN
430
- RETURN x + y;
431
- END;
432
- $$ LANGUAGE plpgsql;
433
-  (0.3ms) DROP VIEW required
434
- PG::UndefinedTable: ERROR: view "required" does not exist
435
- : DROP VIEW required
436
-  (2.1ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
1
+  (32.7ms) CREATE OR REPLACE FUNCTION tuple_sort (x int[]) RETURNS int[] AS $$
437
2
  BEGIN
438
- RETURN x + y;
439
- END;
440
- $$ LANGUAGE plpgsql;
441
-  (0.3ms) DROP VIEW required
442
- PG::UndefinedTable: ERROR: view "required" does not exist
443
- : DROP VIEW required
444
-  (2.0ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
445
- BEGIN
446
- RETURN x + y;
447
- END;
448
- $$ LANGUAGE plpgsql;
449
-  (0.3ms) DROP VIEW required
450
- PG::UndefinedTable: ERROR: view "required" does not exist
451
- : DROP VIEW required
452
-  (0.2ms) DROP VIEW hello_world
453
- PG::UndefinedTable: ERROR: view "hello_world" does not exist
454
- : DROP VIEW hello_world
455
- ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
456
-  (6.7ms) CREATE VIEW required AS SELECT 1 as id
457
-  (6.6ms) CREATE VIEW hello_world AS --!require required
458
- SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
459
-  (2.3ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
460
- BEGIN
461
- RETURN x + y;
462
- END;
463
- $$ LANGUAGE plpgsql;
464
-  (0.7ms) DROP VIEW required
465
- PG::DependentObjectsStillExist: ERROR: cannot drop view required because other objects depend on it
466
- DETAIL: view hello_world depends on view required
467
- HINT: Use DROP ... CASCADE to drop the dependent objects too.
468
- : DROP VIEW required
469
-  (3.0ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
470
- BEGIN
471
- RETURN x + y;
472
- END;
473
- $$ LANGUAGE plpgsql;
474
-  (1.4ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
475
- BEGIN
476
- RETURN x + y;
477
- END;
478
- $$ LANGUAGE plpgsql;
479
-  (1.2ms) DROP VIEW hello_world
480
-  (0.6ms) DROP VIEW required
481
- ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
482
-  (12.4ms) CREATE VIEW required AS SELECT 1 as id
483
-  (12.6ms) CREATE VIEW hello_world AS --!require required
484
- SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
485
-  (2.3ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
486
- BEGIN
487
- RETURN x + y;
488
- END;
489
- $$ LANGUAGE plpgsql;
490
-  (7.2ms) DROP VIEW hello_world
491
-  (6.7ms) DROP VIEW required
492
- ActiveRecord::SchemaMigration Load (0.7ms) SELECT "schema_migrations".* FROM "schema_migrations"
493
-  (13.2ms) CREATE VIEW required AS SELECT 1 as id
494
-  (7.1ms) CREATE VIEW hello_world AS --!require required
495
- SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
496
- ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
497
-  (2.0ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
498
- BEGIN
499
- RETURN x + y;
500
- END;
501
- $$ LANGUAGE plpgsql;
502
-  (6.1ms) CREATE OR REPLACE FUNCTION tuple_sort (x int[]) RETURNS int[] AS $$
503
- BEGIN
504
- IF x[0] > x[1] THEN
505
- RETURN ARRAY[x[1], x[0]];
3
+ -- Note to myself: selection in array start at 1, not at zero !
4
+ IF x[1]::int > x[2]::int THEN
5
+ RETURN ARRAY[x[2], x[1]];
506
6
  ELSE
507
7
  RETURN x;
508
8
  END IF;
509
9
  END;
510
- $$ LANGUAGE plpgsql;
511
-  (0.4ms) DROP VIEW chats
512
- PG::UndefinedTable: ERROR: view "chats" does not exist
513
- : DROP VIEW chats
514
-  (0.2ms) DROP VIEW messages
515
- PG::UndefinedTable: ERROR: view "messages" does not exist
516
- : DROP VIEW messages
517
-  (7.3ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL) 
518
-  (0.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
519
- ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
10
+ $$ LANGUAGE plpgsql;
11
+  (28.1ms) DROP VIEW chats
12
+  (0.2ms) DROP VIEW messages
13
+  (25.0ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL)
14
+  (0.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
15
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
520
16
  Migrating to CreateTestTables (20160208084226)
521
-  (0.1ms) BEGIN
522
-  (3.7ms) CREATE TABLE "users" ("id" serial primary key, "name" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) 
523
-  (0.8ms) CREATE INDEX "index_users_on_name" ON "users" ("name")
524
-  (2.4ms) CREATE TABLE "user_messages" ("id" serial primary key, "from_id" integer, "to_id" integer, "content" text, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) 
525
-  (0.7ms) CREATE INDEX "index_user_messages_on_from_id" ON "user_messages" ("from_id")
526
-  (0.8ms) CREATE INDEX "index_user_messages_on_to_id" ON "user_messages" ("to_id")
527
- SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20160208084226"]]
528
-  (0.5ms) COMMIT
529
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
530
-  (1.8ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
17
+  (0.1ms) BEGIN
18
+  (25.7ms) CREATE TABLE "users" ("id" serial primary key, "name" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
19
+  (0.8ms) CREATE INDEX "index_users_on_name" ON "users" ("name")
20
+  (2.4ms) CREATE TABLE "user_messages" ("id" serial primary key, "from_id" integer, "to_id" integer, "content" text, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
21
+  (0.6ms) CREATE INDEX "index_user_messages_on_from_id" ON "user_messages" ("from_id")
22
+  (1.1ms) CREATE INDEX "index_user_messages_on_to_id" ON "user_messages" ("to_id")
23
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20160208084226"]]
24
+  (5.9ms) COMMIT
25
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
26
+  (1.9ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
531
27
  FROM pg_constraint c
532
28
  JOIN pg_class t1 ON c.conrelid = t1.oid
533
29
  JOIN pg_class t2 ON c.confrelid = t2.oid
@@ -538,8 +34,8 @@ WHERE c.contype = 'f'
538
34
  AND t1.relname = 'user_messages'
539
35
  AND t3.nspname = ANY (current_schemas(false))
540
36
  ORDER BY c.conname
541
- 
542
-  (1.5ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
37
+
38
+  (1.5ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
543
39
  FROM pg_constraint c
544
40
  JOIN pg_class t1 ON c.conrelid = t1.oid
545
41
  JOIN pg_class t2 ON c.confrelid = t2.oid
@@ -550,8 +46,8 @@ WHERE c.contype = 'f'
550
46
  AND t1.relname = 'users'
551
47
  AND t3.nspname = ANY (current_schemas(false))
552
48
  ORDER BY c.conname
553
-
554
-  (10.5ms) CREATE VIEW messages AS SELECT DISTINCT _.receiver_name, _.receiver_id, _.sender_name, _.sender_id, _.content, _.updated_at, _.created_at
49
+ 
50
+  (7.5ms) CREATE VIEW messages AS SELECT DISTINCT _.receiver_name, _.receiver_id, _.sender_name, _.sender_id, _.content, _.updated_at, _.created_at
555
51
  FROM
556
52
  (SELECT u2.name as receiver_name, u2.id as receiver_id,
557
53
  u1.name as sender_name, u1.id as sender_id,
@@ -567,30 +63,37 @@ FROM
567
63
  INNER JOIN user_messages um ON ( u1.id = um.to_id )
568
64
  INNER JOIN users u2 ON ( u2.id = um.from_id )
569
65
  ORDER BY created_at ASC
570
- ) AS _
571
-  (7.1ms) CREATE VIEW chats AS SELECT tuple_sort(ARRAY[sender_id, receiver_id]) AS ids,
66
+ ) AS _
67
+  (12.1ms) CREATE VIEW chats AS SELECT tuple_sort(ARRAY[sender_id, receiver_id]) AS ids,
572
68
  MIN(created_at) as created_at, MAX(updated_at) as updated_at, COUNT(*) as number_of_messages
573
69
  FROM messages
574
- GROUP BY tuple_sort(ARRAY[sender_id, receiver_id])
575
-  (1.5ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
576
- BEGIN
577
- RETURN x + y;
578
- END;
579
- $$ LANGUAGE plpgsql;
580
-  (0.7ms) CREATE OR REPLACE FUNCTION tuple_sort (x int[]) RETURNS int[] AS $$
70
+ GROUP BY tuple_sort(ARRAY[sender_id, receiver_id])
71
+  (20.7ms) CREATE OR REPLACE FUNCTION tuple_sort (x int[]) RETURNS int[] AS $$
581
72
  BEGIN
582
- IF x[0] > x[1] THEN
583
- RETURN ARRAY[x[1], x[0]];
73
+ -- Note to myself: selection in array start at 1, not at zero !
74
+ IF x[1]::int > x[2]::int THEN
75
+ RETURN ARRAY[x[2], x[1]];
584
76
  ELSE
585
77
  RETURN x;
586
78
  END IF;
587
79
  END;
588
- $$ LANGUAGE plpgsql;
589
-  (1.6ms) DROP VIEW chats
590
-  (0.8ms) DROP VIEW messages
591
- ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
592
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
593
-  (1.9ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
80
+ $$ LANGUAGE plpgsql;
81
+  (6.0ms) DROP VIEW chats
82
+  (0.2ms) DROP VIEW messages
83
+  (17.9ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL)
84
+  (5.4ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
85
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
86
+ Migrating to CreateTestTables (20160208084226)
87
+  (0.1ms) BEGIN
88
+  (18.4ms) CREATE TABLE "users" ("id" serial primary key, "name" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
89
+  (5.2ms) CREATE INDEX "index_users_on_name" ON "users" ("name")
90
+  (2.0ms) CREATE TABLE "user_messages" ("id" serial primary key, "from_id" integer, "to_id" integer, "content" text, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
91
+  (0.6ms) CREATE INDEX "index_user_messages_on_from_id" ON "user_messages" ("from_id")
92
+  (0.5ms) CREATE INDEX "index_user_messages_on_to_id" ON "user_messages" ("to_id")
93
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20160208084226"]]
94
+  (11.9ms) COMMIT
95
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
96
+  (1.9ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
594
97
  FROM pg_constraint c
595
98
  JOIN pg_class t1 ON c.conrelid = t1.oid
596
99
  JOIN pg_class t2 ON c.confrelid = t2.oid
@@ -601,8 +104,8 @@ WHERE c.contype = 'f'
601
104
  AND t1.relname = 'user_messages'
602
105
  AND t3.nspname = ANY (current_schemas(false))
603
106
  ORDER BY c.conname
604
- 
605
-  (1.4ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
107
+
108
+  (1.4ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
606
109
  FROM pg_constraint c
607
110
  JOIN pg_class t1 ON c.conrelid = t1.oid
608
111
  JOIN pg_class t2 ON c.confrelid = t2.oid
@@ -613,8 +116,8 @@ WHERE c.contype = 'f'
613
116
  AND t1.relname = 'users'
614
117
  AND t3.nspname = ANY (current_schemas(false))
615
118
  ORDER BY c.conname
616
-
617
-  (8.5ms) CREATE VIEW messages AS SELECT DISTINCT _.receiver_name, _.receiver_id, _.sender_name, _.sender_id, _.content, _.updated_at, _.created_at
119
+ 
120
+  (13.8ms) CREATE VIEW messages AS SELECT DISTINCT _.receiver_name, _.receiver_id, _.sender_name, _.sender_id, _.content, _.updated_at, _.created_at
618
121
  FROM
619
122
  (SELECT u2.name as receiver_name, u2.id as receiver_id,
620
123
  u1.name as sender_name, u1.id as sender_id,
@@ -630,53 +133,37 @@ FROM
630
133
  INNER JOIN user_messages um ON ( u1.id = um.to_id )
631
134
  INNER JOIN users u2 ON ( u2.id = um.from_id )
632
135
  ORDER BY created_at ASC
633
- ) AS _
634
-  (7.6ms) CREATE VIEW chats AS SELECT tuple_sort(ARRAY[sender_id, receiver_id]) AS ids,
136
+ ) AS _
137
+  (6.7ms) CREATE VIEW chats AS SELECT tuple_sort(ARRAY[sender_id, receiver_id]) AS ids,
635
138
  MIN(created_at) as created_at, MAX(updated_at) as updated_at, COUNT(*) as number_of_messages
636
139
  FROM messages
637
- GROUP BY tuple_sort(ARRAY[sender_id, receiver_id])
638
-  (0.1ms) SELECT 1;
639
-  (0.3ms) SELECT 1;
640
-  (0.3ms) SELECT 2;
641
-  (0.2ms) SELECT 2;
642
-  (0.3ms) SELECT 2
643
-  (8.3ms) SELECT tuple_sort(ARRAY[1,3])
644
-  (0.9ms) SELECT tuple_sort(ARRAY[3,1])
645
-  (0.9ms) SELECT tuple_sort(ARRAY[3,1])
646
-  (2.4ms) CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
140
+ GROUP BY tuple_sort(ARRAY[sender_id, receiver_id])
141
+  (8.3ms) CREATE OR REPLACE FUNCTION tuple_sort (x int[]) RETURNS int[] AS $$
647
142
  BEGIN
648
- RETURN x + y;
649
- END;
650
- $$ LANGUAGE plpgsql;
651
-  (0.6ms) CREATE OR REPLACE FUNCTION tuple_sort (x int[]) RETURNS int[] AS $$
652
- BEGIN
653
- IF x[0]::int > x[1]::int THEN
654
- RETURN ARRAY[x[1], x[0]];
143
+ -- Note to myself: selection in array start at 1, not at zero !
144
+ IF x[1]::int > x[2]::int THEN
145
+ RETURN ARRAY[x[2], x[1]];
655
146
  ELSE
656
147
  RETURN x;
657
148
  END IF;
658
149
  END;
659
- $$ LANGUAGE plpgsql;
660
-  (0.3ms) DROP VIEW chats
661
- PG::UndefinedTable: ERROR: view "chats" does not exist
662
- : DROP VIEW chats
663
-  (0.2ms) DROP VIEW messages
664
- PG::UndefinedTable: ERROR: view "messages" does not exist
665
- : DROP VIEW messages
666
-  (2.3ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL) 
667
-  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
668
- ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
150
+ $$ LANGUAGE plpgsql;
151
+  (5.5ms) DROP VIEW chats
152
+  (0.2ms) DROP VIEW messages
153
+  (17.5ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL)
154
+  (5.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
155
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
669
156
  Migrating to CreateTestTables (20160208084226)
670
-  (0.1ms) BEGIN
671
-  (5.8ms) CREATE TABLE "users" ("id" serial primary key, "name" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) 
672
-  (0.6ms) CREATE INDEX "index_users_on_name" ON "users" ("name")
673
-  (2.2ms) CREATE TABLE "user_messages" ("id" serial primary key, "from_id" integer, "to_id" integer, "content" text, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) 
674
-  (0.6ms) CREATE INDEX "index_user_messages_on_from_id" ON "user_messages" ("from_id")
675
-  (0.6ms) CREATE INDEX "index_user_messages_on_to_id" ON "user_messages" ("to_id")
676
- SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20160208084226"]]
677
-  (0.5ms) COMMIT
678
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
679
-  (2.0ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
157
+  (0.1ms) BEGIN
158
+  (18.8ms) CREATE TABLE "users" ("id" serial primary key, "name" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
159
+  (4.1ms) CREATE INDEX "index_users_on_name" ON "users" ("name")
160
+  (2.1ms) CREATE TABLE "user_messages" ("id" serial primary key, "from_id" integer, "to_id" integer, "content" text, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
161
+  (0.5ms) CREATE INDEX "index_user_messages_on_from_id" ON "user_messages" ("from_id")
162
+  (0.6ms) CREATE INDEX "index_user_messages_on_to_id" ON "user_messages" ("to_id")
163
+ SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20160208084226"]]
164
+  (11.0ms) COMMIT
165
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
166
+  (2.0ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
680
167
  FROM pg_constraint c
681
168
  JOIN pg_class t1 ON c.conrelid = t1.oid
682
169
  JOIN pg_class t2 ON c.confrelid = t2.oid
@@ -687,8 +174,8 @@ WHERE c.contype = 'f'
687
174
  AND t1.relname = 'user_messages'
688
175
  AND t3.nspname = ANY (current_schemas(false))
689
176
  ORDER BY c.conname
690
- 
691
-  (1.5ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
177
+
178
+  (1.4ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
692
179
  FROM pg_constraint c
693
180
  JOIN pg_class t1 ON c.conrelid = t1.oid
694
181
  JOIN pg_class t2 ON c.confrelid = t2.oid
@@ -699,9 +186,9 @@ WHERE c.contype = 'f'
699
186
  AND t1.relname = 'users'
700
187
  AND t3.nspname = ANY (current_schemas(false))
701
188
  ORDER BY c.conname
702
-
703
-  (7.7ms) CREATE VIEW messages AS SELECT DISTINCT _.receiver_name, _.receiver_id, _.sender_name, _.sender_id, _.content, _.updated_at, _.created_at
704
- FROM
189
+ 
190
+  (7.3ms) CREATE VIEW messages AS SELECT DISTINCT _.receiver_name, _.receiver_id, _.sender_name, _.sender_id, _.content, _.updated_at, _.created_at
191
+ FROM
705
192
  (SELECT u2.name as receiver_name, u2.id as receiver_id,
706
193
  u1.name as sender_name, u1.id as sender_id,
707
194
  um.content as content, um.updated_at as updated_at, um.created_at as created_at
@@ -716,10 +203,8 @@ FROM
716
203
  INNER JOIN user_messages um ON ( u1.id = um.to_id )
717
204
  INNER JOIN users u2 ON ( u2.id = um.from_id )
718
205
  ORDER BY created_at ASC
719
- ) AS _
720
-  (7.7ms) CREATE VIEW chats AS SELECT tuple_sort(ARRAY[sender_id, receiver_id]) AS ids,
206
+ ) AS _
207
+  (6.3ms) CREATE VIEW chats AS SELECT tuple_sort(ARRAY[sender_id, receiver_id]) AS ids,
721
208
  MIN(created_at) as created_at, MAX(updated_at) as updated_at, COUNT(*) as number_of_messages
722
209
  FROM messages
723
- GROUP BY tuple_sort(ARRAY[sender_id, receiver_id])
724
-  (1.0ms) SELECT tuple_sort(ARRAY[3,1])
725
-  (2.1ms) SELECT tuple_sort(ARRAY[1,3])
210
+ GROUP BY tuple_sort(ARRAY[sender_id, receiver_id])