purview 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +9 -0
  3. data/TODO +7 -6
  4. data/lib/purview/columns/base.rb +35 -3
  5. data/lib/purview/databases/base.rb +84 -231
  6. data/lib/purview/databases/mysql.rb +42 -108
  7. data/lib/purview/databases/postgresql.rb +45 -111
  8. data/lib/purview/exceptions/{could_not_baseline.rb → could_not_baseline_table.rb} +1 -1
  9. data/lib/purview/exceptions/{could_not_disable.rb → could_not_disable_table.rb} +1 -1
  10. data/lib/purview/exceptions/{could_not_enable.rb → could_not_enable_table.rb} +1 -1
  11. data/lib/purview/exceptions/{could_not_find_table_metadata.rb → could_not_find_metadata_for_table.rb} +1 -1
  12. data/lib/purview/exceptions/{could_not_initialize.rb → could_not_initialize_table.rb} +1 -1
  13. data/lib/purview/exceptions/{could_not_lock.rb → could_not_lock_table.rb} +1 -1
  14. data/lib/purview/exceptions/{could_not_sync.rb → could_not_sync_table.rb} +1 -1
  15. data/lib/purview/exceptions/{could_not_unlock.rb → could_not_unlock_table.rb} +1 -1
  16. data/lib/purview/exceptions/could_not_update_metadata_for_table.rb +9 -0
  17. data/lib/purview/exceptions/{database_already_assigned.rb → database_already_assigned_for_table.rb} +1 -1
  18. data/lib/purview/exceptions/{no_window.rb → no_window_for_table.rb} +1 -1
  19. data/lib/purview/exceptions/rows_outside_window_for_table.rb +18 -0
  20. data/lib/purview/exceptions/table_already_assigned_for_column.rb +17 -0
  21. data/lib/purview/exceptions/{table_already_assigned.rb → table_already_assigned_for_index.rb} +1 -1
  22. data/lib/purview/exceptions/{wrong_database.rb → wrong_database_for_table.rb} +1 -1
  23. data/lib/purview/exceptions.rb +15 -13
  24. data/lib/purview/indices/base.rb +6 -1
  25. data/lib/purview/loaders/base.rb +2 -25
  26. data/lib/purview/mixins/dialect.rb +29 -0
  27. data/lib/purview/mixins.rb +1 -0
  28. data/lib/purview/parsers/base.rb +3 -2
  29. data/lib/purview/parsers/csv.rb +13 -3
  30. data/lib/purview/pullers/base_sql.rb +6 -25
  31. data/lib/purview/structs/table_metadata.rb +0 -14
  32. data/lib/purview/tables/base.rb +28 -106
  33. data/lib/purview/tables/base_syncable.rb +113 -0
  34. data/lib/purview/tables/raw.rb +1 -1
  35. data/lib/purview/tables/table_metadata.rb +43 -0
  36. data/lib/purview/tables.rb +3 -0
  37. data/lib/purview/version.rb +1 -1
  38. metadata +20 -15
  39. data/lib/purview/exceptions/rows_outside_window.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bfebf90c2dfbac7b718635c204d78fb6921a779
4
- data.tar.gz: 7b2da04835cbf716b784300140e02b78d2188aa9
3
+ metadata.gz: 30aabf4950bc6dc20daf5b89eec19e9afe148765
4
+ data.tar.gz: 544c19c81308f7276a02a8b6149dd97bcd7f3312
5
5
  SHA512:
6
- metadata.gz: 5ec0e4d36ea4d42dd29c3d8bf1608c6c30db990ecc4e95b0fc6ddf7c951db243f2225b5a7be117f2f11597a7467cfada79f8b90073de2c5c13c60a6ce79932d8
7
- data.tar.gz: d43914f1565f2f3a6c4ec41245a4e06e00069c521fb9e892f378500640e16c6e277bc5c93595c95d98d4da34751c97e01afaf3f6e7b28390ab60d610a087b888
6
+ metadata.gz: 80b799628ae3f89c0eacab1cf449d1fadaf318d9f590c7408624e66849a9c527a9d7f1f280b9df03bbe54e62b496cf99d379091c0ae78aa571fdb9e6fbfe329e
7
+ data.tar.gz: 21600dcd05785d91a627338b14396290fed0dd3c4e18f9a116b9c9b23f25f3fd3715a48e749db0205d283ffd1a26b2764f7bf2339fb9ec90e2c0ea61d43a7708
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ Release 1.4.0 (2015-06-10)
2
+ --------------------------
3
+
4
+ * Add the ability to rename columns during pull/parse
5
+ * Create class to encapulate `table_metadata`
6
+ * Standardize `Exception` class names
7
+ * Allow `table` to be set for `Column(s)` & `Ind{ex,ices}` during instantiation
8
+ * Allow `database` to be set for `Table(s)` during instantiation
9
+
1
10
  Release 1.3.1 (2015-06-05)
2
11
  --------------------------
3
12
 
data/TODO CHANGED
@@ -44,6 +44,10 @@
44
44
  * Introduce [SQL] dialect(s)
45
45
  * Fix JRuby bundle/build
46
46
  * Fall back to logged in user if no [database-]username is provided
47
+ * Create class to encapulate `table_metadata` (in order to clean up the logic
48
+ in the `Database` class(es))
49
+ * Rename columns during pull/parse `source_name` & `target_name` perhaps? Maybe
50
+ create a new type of column?
47
51
 
48
52
  ... ONGOING TASKS ...
49
53
 
@@ -55,17 +59,16 @@
55
59
 
56
60
  * Add COPY `def copy(sql)` support to PostgreSQL connection
57
61
  * Leverage COPY support for PostgreSQL pulls
58
- * Create class to encapulate `table_metadata` (in order to clean up the logic
59
- in the `Database` and `TableMetadata` (struct) classes)
60
62
  * Further encapsulate `Dialect` logic (in order to DRY `Database` classes)
63
+ * Add support for MSSQL
61
64
 
62
65
  * Build out change-log tables
63
66
  * Build out canonical, fact and aggregate tables (and related transforms)
64
67
  * Configurable re-pull window (do this automatically once up to current?)
65
68
  * Add schema management capabilities (detect schema-deltas and suggestion
66
69
  modifications)
67
- * Consider refactoring mutator methods to be globally available (e.g. coalesced
68
- -> Coalesce, quoted -> Quote, etc.)
70
+ * Consider refactoring mutator methods to be globally available (e.g. quoted ->
71
+ Quote, etc.)
69
72
 
70
73
  ... CLOSED QUESTIONS ...
71
74
 
@@ -79,8 +82,6 @@
79
82
  ... OPEN QUESTIONS ...
80
83
 
81
84
  * Parallel pulls from the same "source"? Can this be done in one request?
82
- * Rename columns during pull/parse `source_name` & `target_name` perhaps? Maybe
83
- create a new type of column?
84
85
 
85
86
  ... INTEGRATION CONSIDERATIONS ...
86
87
 
@@ -1,11 +1,12 @@
1
1
  module Purview
2
2
  module Columns
3
3
  class Base
4
- attr_reader :name
4
+ attr_reader :name, :table
5
5
 
6
6
  def initialize(name, opts={})
7
7
  @name = name.to_sym
8
8
  @opts = default_opts.merge(opts)
9
+ @table = table_opt
9
10
  end
10
11
 
11
12
  def default
@@ -16,6 +17,24 @@ module Purview
16
17
  !!default
17
18
  end
18
19
 
20
+ def eql?(other)
21
+ self.class == other.class &&
22
+ limit == other.limit &&
23
+ name == other.name &&
24
+ nullable == other.nullable &&
25
+ primary_key == other.primary_key &&
26
+ type == other.type
27
+ end
28
+
29
+ def hash
30
+ default.hash +
31
+ limit.hash +
32
+ name.hash +
33
+ nullable.hash +
34
+ primary_key.hash +
35
+ type.hash
36
+ end
37
+
19
38
  def limit
20
39
  opts[:limit]
21
40
  end
@@ -25,7 +44,7 @@ module Purview
25
44
  end
26
45
 
27
46
  def nullable
28
- coalesced(opts[:nullable], true)
47
+ [nil, true].include?(opts[:nullable])
29
48
  end
30
49
 
31
50
  def nullable?
@@ -46,8 +65,17 @@ module Purview
46
65
  !!primary_key
47
66
  end
48
67
 
68
+ def source_name
69
+ (opts[:source_name] || name).to_sym
70
+ end
71
+
72
+ def table=(value)
73
+ raise Purview::Exceptions::TableAlreadyAssignedForColumn.new(self) if table
74
+ @table = value
75
+ end
76
+
49
77
  def type
50
- coalesced(opts[:type], Purview::Types::String)
78
+ opts[:type] || Purview::Types::String
51
79
  end
52
80
 
53
81
  private
@@ -59,6 +87,10 @@ module Purview
59
87
  def default_opts
60
88
  {}
61
89
  end
90
+
91
+ def table_opt
92
+ opts[:table]
93
+ end
62
94
  end
63
95
  end
64
96
  end
@@ -4,10 +4,10 @@ module Purview
4
4
  attr_reader :name, :tables
5
5
 
6
6
  def initialize(name, opts={})
7
- @name = name
7
+ @name = name.to_sym
8
8
  @opts = opts
9
9
  @tables = Set.new.tap do |result|
10
- (opts[:tables] || []).each do |table|
10
+ (default_tables + tables_opt).each do |table|
11
11
  table.database = self if result.add?(table)
12
12
  end
13
13
  end
@@ -15,7 +15,7 @@ module Purview
15
15
 
16
16
  def baseline_table(table)
17
17
  ensure_table_valid_for_database(table)
18
- raise Purview::Exceptions::CouldNotBaseline.new(table) \
18
+ raise Purview::Exceptions::CouldNotBaselineTable.new(table) \
19
19
  unless table_initialized?(table)
20
20
  table_name = table_name(table)
21
21
  with_context_logging("`baseline_table` for: #{table_name}") do
@@ -32,13 +32,12 @@ module Purview
32
32
 
33
33
  def create_index(index, opts={})
34
34
  ensure_index_valid_for_database(index)
35
- table_opts = extract_table_options(opts)
35
+ table_opts = extract_table_opts(opts)
36
36
  table_name = table_name(index.table, table_opts)
37
- index_opts = extract_index_options(opts)
38
- index_columns = index.columns
37
+ index_opts = extract_index_opts(opts)
39
38
  index_name = index_name(
40
39
  table_name,
41
- index_columns,
40
+ index,
42
41
  index_opts
43
42
  )
44
43
  with_context_logging("`create_index` for: #{index_name}") do
@@ -59,7 +58,7 @@ module Purview
59
58
  def create_table(table, opts={})
60
59
  ensure_table_valid_for_database(table)
61
60
  ensure_table_metadata_exists_for_table(table)
62
- table_opts = extract_table_options(opts)
61
+ table_opts = extract_table_opts(opts)
63
62
  table_name = table_name(table, table_opts)
64
63
  with_context_logging("`create_table` for: #{table_name}") do
65
64
  with_new_or_existing_connection(opts) do |connection|
@@ -92,7 +91,7 @@ module Purview
92
91
  with_new_connection do |connection|
93
92
  rows_affected = \
94
93
  connection.execute(disable_table_sql(table)).rows_affected
95
- raise Purview::Exceptions::CouldNotDisable.new(table) \
94
+ raise Purview::Exceptions::CouldNotDisableTable.new(table) \
96
95
  if zero?(rows_affected)
97
96
  end
98
97
  end
@@ -101,13 +100,12 @@ module Purview
101
100
 
102
101
  def drop_index(index, opts={})
103
102
  ensure_index_valid_for_database(index)
104
- table_opts = extract_table_options(opts)
103
+ table_opts = extract_table_opts(opts)
105
104
  table_name = table_name(index.table, table_opts)
106
- index_opts = extract_index_options(opts)
107
- index_columns = index.columns
105
+ index_opts = extract_index_opts(opts)
108
106
  index_name = index_name(
109
107
  table_name,
110
- index_columns,
108
+ index,
111
109
  index_opts
112
110
  )
113
111
  with_context_logging("`drop_index` for: #{index_name}") do
@@ -128,7 +126,7 @@ module Purview
128
126
  def drop_table(table, opts={})
129
127
  ensure_table_valid_for_database(table)
130
128
  ensure_table_metadata_absent_for_table(table)
131
- table_opts = extract_table_options(opts)
129
+ table_opts = extract_table_opts(opts)
132
130
  table_name = table_name(table, table_opts)
133
131
  with_context_logging("`drop_table` for: #{table_name}") do
134
132
  with_new_connection do |connection|
@@ -151,7 +149,7 @@ module Purview
151
149
  with_new_connection do |connection|
152
150
  rows_affected = \
153
151
  connection.execute(enable_table_sql(table, timestamp)).rows_affected
154
- raise Purview::Exceptions::CouldNotEnable.new(table) \
152
+ raise Purview::Exceptions::CouldNotEnableTable.new(table) \
155
153
  if zero?(rows_affected)
156
154
  end
157
155
  end
@@ -165,7 +163,7 @@ module Purview
165
163
  with_new_connection do |connection|
166
164
  rows_affected = \
167
165
  connection.execute(initialize_table_sql(table, timestamp)).rows_affected
168
- raise Purview::Exceptions::CouldNotInitialize.new(table) \
166
+ raise Purview::Exceptions::CouldNotInitializeTable.new(table) \
169
167
  if zero?(rows_affected)
170
168
  end
171
169
  end
@@ -179,7 +177,7 @@ module Purview
179
177
  with_new_connection do |connection|
180
178
  rows_affected = \
181
179
  connection.execute(lock_table_sql(table, timestamp)).rows_affected
182
- raise Purview::Exceptions::CouldNotLock.new(table) \
180
+ raise Purview::Exceptions::CouldNotLockTable.new(table) \
183
181
  if zero?(rows_affected)
184
182
  end
185
183
  end
@@ -198,7 +196,7 @@ module Purview
198
196
 
199
197
  def sync_table(table)
200
198
  ensure_table_valid_for_database(table)
201
- raise Purview::Exceptions::CouldNotSync.new(table) \
199
+ raise Purview::Exceptions::CouldNotSyncTable.new(table) \
202
200
  unless table_initialized?(table) && table_enabled?(table)
203
201
  table_name = table_name(table)
204
202
  with_context_logging("`sync_table` for: #{table_name}") do
@@ -213,10 +211,16 @@ module Purview
213
211
  table_name = table_name(table)
214
212
  with_context_logging("`table_metadata` for: #{table_name}") do
215
213
  with_new_connection do |connection|
216
- row = connection.execute(table_metadata_sql(table)).rows.first
217
- raise Purview::Exceptions::CouldNotFindTableMetadata.new(table) \
218
- unless row
219
- table_metadata = Purview::Structs::TableMetadata.new(row)
214
+ Purview::Structs::TableMetadata.new(
215
+ table_metadata_table.columns.reduce({}) do |memo, column|
216
+ memo[column.name] = get_table_metadata_value(
217
+ connection,
218
+ table,
219
+ column
220
+ )
221
+ memo
222
+ end
223
+ )
220
224
  end
221
225
  end
222
226
  table_metadata
@@ -229,7 +233,7 @@ module Purview
229
233
  with_new_connection do |connection|
230
234
  rows_affected = \
231
235
  connection.execute(unlock_table_sql(table)).rows_affected
232
- raise Purview::Exceptions::CouldNotUnlock.new(table) \
236
+ raise Purview::Exceptions::CouldNotUnlockTable.new(table) \
233
237
  if zero?(rows_affected)
234
238
  end
235
239
  end
@@ -239,6 +243,7 @@ module Purview
239
243
  private
240
244
 
241
245
  include Purview::Mixins::Connection
246
+ include Purview::Mixins::Dialect
242
247
  include Purview::Mixins::Helpers
243
248
  include Purview::Mixins::Logger
244
249
 
@@ -261,19 +266,12 @@ module Purview
261
266
  end
262
267
  end
263
268
 
264
- def column_names(columns)
265
- columns.map(&:name)
269
+ def column_names(index_or_table)
270
+ index_or_table.columns.map(&:name)
266
271
  end
267
272
 
268
- def column_definitions(table)
269
- [].tap do |result|
270
- result << column_definition(table.id_column)
271
- result << column_definition(table.created_timestamp_column)
272
- result << column_definition(table.updated_timestamp_column)
273
- table.data_columns.each do |column|
274
- result << column_definition(column)
275
- end
276
- end
273
+ def column_definitions(index_or_table)
274
+ index_or_table.columns.map { |column| column_definition(column) }
277
275
  end
278
276
 
279
277
  def connection_type
@@ -324,8 +322,8 @@ module Purview
324
322
  {}
325
323
  end
326
324
 
327
- def dialect
328
- dialect_type.new
325
+ def default_tables
326
+ []
329
327
  end
330
328
 
331
329
  def dialect_type
@@ -383,66 +381,30 @@ module Purview
383
381
  def ensure_table_valid_for_database(table)
384
382
  raise ArgumentError.new('Must provide a `Table`') \
385
383
  unless table
386
- raise Purview::Exceptions::WrongDatabase.new(table) \
384
+ raise Purview::Exceptions::WrongDatabaseForTable.new(table) \
387
385
  unless tables.include?(table)
388
386
  end
389
387
 
390
- def extract_index_options(opts)
388
+ def extract_index_opts(opts)
391
389
  opts[:index] || {}
392
390
  end
393
391
 
394
- def extract_table_options(opts)
392
+ def extract_table_opts(opts)
395
393
  opts[:table] || { :create_indices => true }
396
394
  end
397
395
 
398
- def false_value
399
- dialect.false_value
400
- end
401
-
402
- def get_enabled_at_for_table(connection, table)
403
- row = connection.execute(get_enabled_at_for_table_sql(table)).rows[0]
404
- timestamp = row[table_metadata_enabled_at_column_name]
405
- timestamp ? Time.parse(timestamp) : nil
406
- end
407
-
408
- def get_enabled_at_for_table_sql(table)
409
- raise %{All "#{Base}(s)" must override the "get_enabled_at_for_table_sql" method}
410
- end
411
-
412
- def get_last_pulled_at_for_table(connection, table)
413
- row = connection.execute(get_last_pulled_at_for_table_sql(table)).rows[0]
414
- timestamp = row[table_metadata_last_pulled_at_column_name]
415
- timestamp ? Time.parse(timestamp) : nil
416
- end
417
-
418
- def get_last_pulled_at_for_table_sql(table)
419
- raise %{All "#{Base}(s)" must override the "get_last_pulled_at_for_table_sql" method}
420
- end
421
-
422
- def get_locked_at_for_table(connection, table)
423
- row = connection.execute(get_locked_at_for_table_sql(table)).rows[0]
424
- timestamp = row[table_metadata_locked_at_column_name]
425
- timestamp ? Time.parse(timestamp) : nil
426
- end
427
-
428
- def get_locked_at_for_table_sql(table)
429
- raise %{All "#{Base}(s)" must override the "get_locked_at_for_table_sql" method}
430
- end
431
-
432
- def get_max_timestamp_pulled_for_table(connection, table)
433
- row = connection.execute(get_max_timestamp_pulled_for_table_sql(table)).rows[0]
434
- timestamp = row[table_metadata_max_timestamp_pulled_column_name]
435
- timestamp ? Time.parse(timestamp) : nil
436
- end
437
-
438
- def get_max_timestamp_pulled_for_table_sql(table)
439
- raise %{All "#{Base}(s)" must override the "get_max_timestamp_pulled_for_table_sql" method}
396
+ def get_table_metadata_value(connection, table, column)
397
+ row = connection.execute(get_table_metadata_value_sql(table, column)).rows[0]
398
+ raise CouldNotFindMetadataForTable.new(table) \
399
+ unless row
400
+ value = row[column.name]
401
+ value && column.type.parse(value)
440
402
  end
441
403
 
442
- def index_name(table_name, columns, index_opts={})
404
+ def index_name(table_name, index, index_opts={})
443
405
  index_opts[:name] || 'index_%s_on_%s' % [
444
406
  table_name,
445
- column_names(columns).join('_and_'),
407
+ column_names(index).join('_and_'),
446
408
  ]
447
409
  end
448
410
 
@@ -468,8 +430,8 @@ module Purview
468
430
 
469
431
  def next_table(connection, timestamp)
470
432
  row = connection.execute(next_table_sql(timestamp)).rows[0]
471
- table_name = row && row[table_metadata_table_name_column_name]
472
- table_name && tables_by_name[table_name]
433
+ value = row && row[table_metadata_table.table_name_column.name]
434
+ value && table_metadata_table.table_name_column.type.parse(value)
473
435
  end
474
436
 
475
437
  def next_table_sql(timestamp)
@@ -477,7 +439,11 @@ module Purview
477
439
  end
478
440
 
479
441
  def next_window(connection, table, timestamp)
480
- min = get_max_timestamp_pulled_for_table(connection, table)
442
+ min = get_table_metadata_value(
443
+ connection,
444
+ table,
445
+ table_metadata_table.max_timestamp_pulled_column
446
+ )
481
447
  max = min + table.window_size
482
448
  now = timestamp
483
449
  min > now ? nil : Purview::Structs::Window.new(
@@ -486,10 +452,6 @@ module Purview
486
452
  )
487
453
  end
488
454
 
489
- def null_value
490
- dialect.null_value
491
- end
492
-
493
455
  def nullable?(column)
494
456
  column.nullable?
495
457
  end
@@ -498,44 +460,11 @@ module Purview
498
460
  column.primary_key?
499
461
  end
500
462
 
501
- def quoted(value)
502
- dialect.quoted(value)
503
- end
504
-
505
- def sanitized(value)
506
- dialect.sanitized(value)
507
- end
508
-
509
- def set_enabled_at_for_table(connection, table, timestamp)
510
- connection.execute(set_enabled_at_for_table_sql(table, timestamp))
511
- end
512
-
513
- def set_enabled_at_for_table_sql(table, timestamp)
514
- raise %{All "#{Base}(s)" must override the "set_enabled_at_for_table_sql" method}
515
- end
516
-
517
- def set_last_pulled_at_for_table(connection, table, timestamp)
518
- connection.execute(set_last_pulled_at_for_table_sql(table, timestamp))
519
- end
520
-
521
- def set_last_pulled_at_for_table_sql(table, timestamp)
522
- raise %{All "#{Base}(s)" must override the "set_last_pulled_at_for_table_sql" method}
523
- end
524
-
525
- def set_locked_at_for_table(connection, table, timestamp)
526
- connection.execute(set_locked_at_for_table_sql(table, timestamp))
527
- end
528
-
529
- def set_locked_at_for_table_sql(table, timestamp)
530
- raise %{All "#{Base}(s)" must override the "set_locked_at_for_table_sql" method}
531
- end
532
-
533
- def set_max_timestamp_pulled_for_table(connection, table, timestamp)
534
- connection.execute(set_max_timestamp_pulled_for_table_sql(table, timestamp))
535
- end
536
-
537
- def set_max_timestamp_pulled_for_table_sql(table, timestamp)
538
- raise %{All "#{Base}(s)" must override the "set_max_timestamp_pulled_for_table_sql" method}
463
+ def set_table_metadata_value(connection, table, column, value)
464
+ rows_affected = \
465
+ connection.execute(set_table_metadata_value_sql(table, column, value)).rows_affected
466
+ raise CouldNotUpdateMetadataForTable.new(table) \
467
+ if zero?(rows_affected)
539
468
  end
540
469
 
541
470
  def sync_table_with_lock(table, timestamp)
@@ -552,14 +481,16 @@ module Purview
552
481
  with_new_connection do |connection|
553
482
  with_transaction(connection) do
554
483
  table.sync(connection, window)
555
- set_last_pulled_at_for_table(
484
+ set_table_metadata_value(
556
485
  connection,
557
486
  table,
487
+ table_metadata_table.last_pulled_at_column,
558
488
  timestamp
559
489
  )
560
- set_max_timestamp_pulled_for_table(
490
+ set_table_metadata_value(
561
491
  connection,
562
492
  table,
493
+ table_metadata_table.max_timestamp_pulled_column,
563
494
  window.max
564
495
  )
565
496
  last_window = window
@@ -575,116 +506,36 @@ module Purview
575
506
 
576
507
  def table_enabled?(table)
577
508
  with_new_connection do |connection|
578
- !!get_enabled_at_for_table(connection, table)
509
+ !!get_table_metadata_value(
510
+ connection,
511
+ table,
512
+ table_metadata_table.enabled_at_column
513
+ )
579
514
  end
580
515
  end
581
516
 
582
517
  def table_initialized?(table)
583
518
  with_new_connection do |connection|
584
- !!get_max_timestamp_pulled_for_table(connection, table)
519
+ !!get_table_metadata_value(
520
+ connection,
521
+ table,
522
+ table_metadata_table.max_timestamp_pulled_column
523
+ )
585
524
  end
586
525
  end
587
526
 
588
527
  def table_locked?(table)
589
528
  with_new_connection do |connection|
590
- !!get_locked_at_for_table(connection, table)
529
+ !!get_table_metadata_value(
530
+ connection,
531
+ table,
532
+ table_metadata_table.locked_at_column
533
+ )
591
534
  end
592
535
  end
593
536
 
594
- def table_metadata_column_definitions
595
- [
596
- table_metadata_table_name_column_definition,
597
- table_metadata_enabled_at_column_definition,
598
- table_metadata_last_pulled_at_column_definition,
599
- table_metadata_locked_at_column_definition,
600
- table_metadata_max_timestamp_pulled_column_definition,
601
- ]
602
- end
603
-
604
- def table_metadata_column_names
605
- table_metadata_columns.map(&:name)
606
- end
607
-
608
- def table_metadata_columns
609
- [
610
- table_metadata_table_name_column,
611
- table_metadata_enabled_at_column,
612
- table_metadata_last_pulled_at_column,
613
- table_metadata_locked_at_column,
614
- table_metadata_max_timestamp_pulled_column,
615
- ]
616
- end
617
-
618
- def table_metadata_enabled_at_column
619
- Purview::Columns::Timestamp.new(table_metadata_enabled_at_column_name)
620
- end
621
-
622
- def table_metadata_enabled_at_column_definition
623
- column_definition(table_metadata_enabled_at_column)
624
- end
625
-
626
- def table_metadata_enabled_at_column_name
627
- 'enabled_at'
628
- end
629
-
630
- def table_metadata_last_pulled_at_column
631
- Purview::Columns::Timestamp.new(table_metadata_last_pulled_at_column_name)
632
- end
633
-
634
- def table_metadata_last_pulled_at_column_definition
635
- column_definition(table_metadata_last_pulled_at_column)
636
- end
637
-
638
- def table_metadata_last_pulled_at_column_name
639
- 'last_pulled_at'
640
- end
641
-
642
- def table_metadata_locked_at_column
643
- Purview::Columns::Timestamp.new(table_metadata_locked_at_column_name)
644
- end
645
-
646
- def table_metadata_locked_at_column_definition
647
- column_definition(table_metadata_locked_at_column)
648
- end
649
-
650
- def table_metadata_locked_at_column_name
651
- 'locked_at'
652
- end
653
-
654
- def table_metadata_max_timestamp_pulled_column
655
- Purview::Columns::Timestamp.new(table_metadata_max_timestamp_pulled_column_name)
656
- end
657
-
658
- def table_metadata_max_timestamp_pulled_column_definition
659
- column_definition(table_metadata_max_timestamp_pulled_column)
660
- end
661
-
662
- def table_metadata_max_timestamp_pulled_column_name
663
- 'max_timestamp_pulled'
664
- end
665
-
666
- def table_metadata_sql(table)
667
- raise %{All "#{Base}(s)" must override the "table_metadata_sql" method}
668
- end
669
-
670
- def table_metadata_table_name
671
- 'table_metadata'
672
- end
673
-
674
- def table_metadata_table_name_column
675
- Purview::Columns::Id.new(
676
- table_metadata_table_name_column_name,
677
- :type => Purview::Types::String,
678
- :limit => 255,
679
- )
680
- end
681
-
682
- def table_metadata_table_name_column_definition
683
- column_definition(table_metadata_table_name_column)
684
- end
685
-
686
- def table_metadata_table_name_column_name
687
- 'table_name'
537
+ def table_metadata_table
538
+ @table_metadata_table ||= Purview::Tables::TableMetadata.new(self)
688
539
  end
689
540
 
690
541
  def table_name(table, table_opts={})
@@ -703,8 +554,8 @@ module Purview
703
554
  end
704
555
  end
705
556
 
706
- def true_value
707
- dialect.true_value
557
+ def tables_opt
558
+ opts[:tables] || []
708
559
  end
709
560
 
710
561
  def type(column)
@@ -731,7 +582,8 @@ module Purview
731
582
  def with_next_table(timestamp)
732
583
  with_new_connection do |connection|
733
584
  table = next_table(connection, timestamp)
734
- raise Purview::Exceptions::NoTable.new unless table
585
+ raise Purview::Exceptions::NoTable.new \
586
+ unless table
735
587
  yield table
736
588
  end
737
589
  end
@@ -743,7 +595,8 @@ module Purview
743
595
  table,
744
596
  timestamp
745
597
  )
746
- raise Purview::Exceptions::NoWindow.new(table) unless window
598
+ raise Purview::Exceptions::NoWindowForTable.new(table) \
599
+ unless window
747
600
  yield window
748
601
  end
749
602
  end