purview 1.3.0 → 1.3.1
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 +17 -12
- data/TODO +6 -4
- data/lib/purview/databases/base.rb +74 -12
- data/lib/purview/databases/mysql.rb +11 -6
- data/lib/purview/databases/postgresql.rb +11 -6
- data/lib/purview/exceptions/could_not_find_table_metadata.rb +9 -0
- data/lib/purview/exceptions.rb +1 -0
- data/lib/purview/structs/table_metadata.rb +39 -0
- data/lib/purview/structs.rb +1 -0
- data/lib/purview/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bfebf90c2dfbac7b718635c204d78fb6921a779
|
4
|
+
data.tar.gz: 7b2da04835cbf716b784300140e02b78d2188aa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ec0e4d36ea4d42dd29c3d8bf1608c6c30db990ecc4e95b0fc6ddf7c951db243f2225b5a7be117f2f11597a7467cfada79f8b90073de2c5c13c60a6ce79932d8
|
7
|
+
data.tar.gz: d43914f1565f2f3a6c4ec41245a4e06e00069c521fb9e892f378500640e16c6e277bc5c93595c95d98d4da34751c97e01afaf3f6e7b28390ab60d610a087b888
|
data/CHANGELOG
CHANGED
@@ -1,36 +1,41 @@
|
|
1
|
-
Release 1.3.
|
2
|
-
|
1
|
+
Release 1.3.1 (2015-06-05)
|
2
|
+
--------------------------
|
3
|
+
|
4
|
+
* Add `table_metadata` helper to `Database` class
|
5
|
+
|
6
|
+
Release 1.3.0 (2015-06-04)
|
7
|
+
--------------------------
|
3
8
|
|
4
9
|
* Add support for easily adding additional indices + clean-up
|
5
10
|
* DEPRECATION: `create_temporary_table` deprecated in favor of `create_table`
|
6
11
|
with the `temporary` option specified
|
7
12
|
|
8
|
-
Release 1.2.0
|
9
|
-
|
13
|
+
Release 1.2.0 (2015-06-03)
|
14
|
+
--------------------------
|
10
15
|
|
11
16
|
* Use system-time as opposed to assuming/forcing UTC time
|
12
17
|
* Add `sync_table` helper to `Database` class
|
13
18
|
* Eliminate explicit `return(s)` -- they were causing issues w/ `yield`
|
14
19
|
|
15
|
-
Release 1.1.1
|
16
|
-
|
20
|
+
Release 1.1.1 (2015-06-02)
|
21
|
+
--------------------------
|
17
22
|
|
18
23
|
* Add `baseline_table` helper to `Database` class
|
19
24
|
|
20
|
-
Release 1.1.0
|
21
|
-
|
25
|
+
Release 1.1.0 (2015-06-01)
|
26
|
+
--------------------------
|
22
27
|
|
23
28
|
* Change how `starting_timestamp` is configured
|
24
29
|
* BUGFIX: Fix/standardize exception class/file names
|
25
30
|
|
26
|
-
Release 1.0.1
|
27
|
-
|
31
|
+
Release 1.0.1 (2015-05-29)
|
32
|
+
--------------------------
|
28
33
|
|
29
34
|
* Use consistent naming for database connection-opts (this allowed some DRYing)
|
30
35
|
* OPPREF: Only update `table_metadata` when creating/dropping tables
|
31
36
|
|
32
|
-
Release 1.0.0
|
33
|
-
|
37
|
+
Release 1.0.0 (2015-05-28)
|
38
|
+
--------------------------
|
34
39
|
|
35
40
|
* Support on JRuby, MRI, and RBX for pulling, validating, parsing and loading
|
36
41
|
CSV/TSV and SQL data (ETL)
|
data/TODO
CHANGED
@@ -55,15 +55,17 @@
|
|
55
55
|
|
56
56
|
* Add COPY `def copy(sql)` support to PostgreSQL connection
|
57
57
|
* Leverage COPY support for PostgreSQL pulls
|
58
|
-
* Create class to encapulate `table_metadata` logic
|
59
|
-
|
58
|
+
* Create class to encapulate `table_metadata` (in order to clean up the logic
|
59
|
+
in the `Database` and `TableMetadata` (struct) classes)
|
60
|
+
* Further encapsulate `Dialect` logic (in order to DRY `Database` classes)
|
61
|
+
|
60
62
|
* Build out change-log tables
|
61
63
|
* Build out canonical, fact and aggregate tables (and related transforms)
|
62
64
|
* Configurable re-pull window (do this automatically once up to current?)
|
63
65
|
* Add schema management capabilities (detect schema-deltas and suggestion
|
64
66
|
modifications)
|
65
|
-
*
|
66
|
-
quoted -> Quote, etc.)
|
67
|
+
* Consider refactoring mutator methods to be globally available (e.g. coalesced
|
68
|
+
-> Coalesce, quoted -> Quote, etc.)
|
67
69
|
|
68
70
|
... CLOSED QUESTIONS ...
|
69
71
|
|
@@ -207,6 +207,21 @@ module Purview
|
|
207
207
|
table_name
|
208
208
|
end
|
209
209
|
|
210
|
+
def table_metadata(table)
|
211
|
+
ensure_table_valid_for_database(table)
|
212
|
+
table_metadata = nil
|
213
|
+
table_name = table_name(table)
|
214
|
+
with_context_logging("`table_metadata` for: #{table_name}") do
|
215
|
+
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)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
table_metadata
|
223
|
+
end
|
224
|
+
|
210
225
|
def unlock_table(table)
|
211
226
|
ensure_table_valid_for_database(table)
|
212
227
|
table_name = table_name(table)
|
@@ -576,53 +591,96 @@ module Purview
|
|
576
591
|
end
|
577
592
|
end
|
578
593
|
|
579
|
-
def
|
580
|
-
|
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)
|
581
620
|
end
|
582
621
|
|
583
622
|
def table_metadata_enabled_at_column_definition
|
584
|
-
|
585
|
-
column_definition(column)
|
623
|
+
column_definition(table_metadata_enabled_at_column)
|
586
624
|
end
|
587
625
|
|
588
626
|
def table_metadata_enabled_at_column_name
|
589
627
|
'enabled_at'
|
590
628
|
end
|
591
629
|
|
630
|
+
def table_metadata_last_pulled_at_column
|
631
|
+
Purview::Columns::Timestamp.new(table_metadata_last_pulled_at_column_name)
|
632
|
+
end
|
633
|
+
|
592
634
|
def table_metadata_last_pulled_at_column_definition
|
593
|
-
|
594
|
-
column_definition(column)
|
635
|
+
column_definition(table_metadata_last_pulled_at_column)
|
595
636
|
end
|
596
637
|
|
597
638
|
def table_metadata_last_pulled_at_column_name
|
598
639
|
'last_pulled_at'
|
599
640
|
end
|
600
641
|
|
642
|
+
def table_metadata_locked_at_column
|
643
|
+
Purview::Columns::Timestamp.new(table_metadata_locked_at_column_name)
|
644
|
+
end
|
645
|
+
|
601
646
|
def table_metadata_locked_at_column_definition
|
602
|
-
|
603
|
-
column_definition(column)
|
647
|
+
column_definition(table_metadata_locked_at_column)
|
604
648
|
end
|
605
649
|
|
606
650
|
def table_metadata_locked_at_column_name
|
607
651
|
'locked_at'
|
608
652
|
end
|
609
653
|
|
654
|
+
def table_metadata_max_timestamp_pulled_column
|
655
|
+
Purview::Columns::Timestamp.new(table_metadata_max_timestamp_pulled_column_name)
|
656
|
+
end
|
657
|
+
|
610
658
|
def table_metadata_max_timestamp_pulled_column_definition
|
611
|
-
|
612
|
-
column_definition(column)
|
659
|
+
column_definition(table_metadata_max_timestamp_pulled_column)
|
613
660
|
end
|
614
661
|
|
615
662
|
def table_metadata_max_timestamp_pulled_column_name
|
616
663
|
'max_timestamp_pulled'
|
617
664
|
end
|
618
665
|
|
666
|
+
def table_metadata_sql(table)
|
667
|
+
raise %{All "#{Base}(s)" must override the "table_metadata_sql" method}
|
668
|
+
end
|
669
|
+
|
619
670
|
def table_metadata_table_name
|
620
671
|
'table_metadata'
|
621
672
|
end
|
622
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
|
+
|
623
682
|
def table_metadata_table_name_column_definition
|
624
|
-
|
625
|
-
column_definition(column)
|
683
|
+
column_definition(table_metadata_table_name_column)
|
626
684
|
end
|
627
685
|
|
628
686
|
def table_metadata_table_name_column_name
|
@@ -633,6 +691,10 @@ module Purview
|
|
633
691
|
table_opts[:name] || table.name
|
634
692
|
end
|
635
693
|
|
694
|
+
def table_unlocked?(table)
|
695
|
+
!table_locked?(table)
|
696
|
+
end
|
697
|
+
|
636
698
|
def tables_by_name
|
637
699
|
@tables_by_name ||= {}.tap do |result|
|
638
700
|
tables.each do |table|
|
@@ -88,13 +88,9 @@ module Purview
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def ensure_table_metadata_table_exists_sql
|
91
|
-
'CREATE TABLE IF NOT EXISTS %s (%s
|
91
|
+
'CREATE TABLE IF NOT EXISTS %s (%s)' % [
|
92
92
|
table_metadata_table_name,
|
93
|
-
|
94
|
-
table_metadata_enabled_at_column_definition,
|
95
|
-
table_metadata_last_pulled_at_column_definition,
|
96
|
-
table_metadata_locked_at_column_definition,
|
97
|
-
table_metadata_max_timestamp_pulled_column_definition,
|
93
|
+
table_metadata_column_definitions.join(', '),
|
98
94
|
]
|
99
95
|
end
|
100
96
|
|
@@ -212,6 +208,15 @@ module Purview
|
|
212
208
|
]
|
213
209
|
end
|
214
210
|
|
211
|
+
def table_metadata_sql(table)
|
212
|
+
'SELECT %s FROM %s WHERE %s = %s' % [
|
213
|
+
table_metadata_column_names.join(', '),
|
214
|
+
table_metadata_table_name,
|
215
|
+
table_metadata_table_name_column_name,
|
216
|
+
quoted(table.name),
|
217
|
+
]
|
218
|
+
end
|
219
|
+
|
215
220
|
def type_map
|
216
221
|
super.merge(
|
217
222
|
Purview::Types::Money => 'decimal',
|
@@ -88,13 +88,9 @@ module Purview
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def ensure_table_metadata_table_exists_sql
|
91
|
-
'CREATE TABLE IF NOT EXISTS %s (%s
|
91
|
+
'CREATE TABLE IF NOT EXISTS %s (%s)' % [
|
92
92
|
table_metadata_table_name,
|
93
|
-
|
94
|
-
table_metadata_enabled_at_column_definition,
|
95
|
-
table_metadata_last_pulled_at_column_definition,
|
96
|
-
table_metadata_locked_at_column_definition,
|
97
|
-
table_metadata_max_timestamp_pulled_column_definition,
|
93
|
+
table_metadata_column_definitions.join(', '),
|
98
94
|
]
|
99
95
|
end
|
100
96
|
|
@@ -215,6 +211,15 @@ module Purview
|
|
215
211
|
]
|
216
212
|
end
|
217
213
|
|
214
|
+
def table_metadata_sql(table)
|
215
|
+
'SELECT %s FROM %s WHERE %s = %s' % [
|
216
|
+
table_metadata_column_names.join(', '),
|
217
|
+
table_metadata_table_name,
|
218
|
+
table_metadata_table_name_column_name,
|
219
|
+
quoted(table.name),
|
220
|
+
]
|
221
|
+
end
|
222
|
+
|
218
223
|
def type_map
|
219
224
|
super.merge(
|
220
225
|
Purview::Types::Money => 'money',
|
data/lib/purview/exceptions.rb
CHANGED
@@ -4,6 +4,7 @@ require 'purview/exceptions/base_table'
|
|
4
4
|
require 'purview/exceptions/could_not_baseline'
|
5
5
|
require 'purview/exceptions/could_not_disable'
|
6
6
|
require 'purview/exceptions/could_not_enable'
|
7
|
+
require 'purview/exceptions/could_not_find_table_metadata'
|
7
8
|
require 'purview/exceptions/could_not_initialize'
|
8
9
|
require 'purview/exceptions/could_not_lock'
|
9
10
|
require 'purview/exceptions/could_not_sync'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Purview
|
2
|
+
module Structs
|
3
|
+
class TableMetadata < Base
|
4
|
+
def initialize(row)
|
5
|
+
enabled_at = row.enabled_at && Time.parse(row.enabled_at)
|
6
|
+
last_pulled_at = row.last_pulled_at && Time.parse(row.last_pulled_at)
|
7
|
+
locked_at = row.locked_at && Time.parse(row.locked_at)
|
8
|
+
max_timestamp_pulled = row.max_timestamp_pulled && Time.parse(row.max_timestamp_pulled)
|
9
|
+
super(
|
10
|
+
:table_name => row.table_name,
|
11
|
+
:enabled_at => enabled_at,
|
12
|
+
:last_pulled_at => last_pulled_at,
|
13
|
+
:locked_at => locked_at,
|
14
|
+
:max_timestamp_pulled => max_timestamp_pulled,
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def diabled?
|
19
|
+
!enabled?
|
20
|
+
end
|
21
|
+
|
22
|
+
def enabled?
|
23
|
+
!!enabled_at
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialized?
|
27
|
+
!!max_timestamp_pulled
|
28
|
+
end
|
29
|
+
|
30
|
+
def locked?
|
31
|
+
!!locked_at
|
32
|
+
end
|
33
|
+
|
34
|
+
def unlocked?
|
35
|
+
!locked?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/purview/structs.rb
CHANGED
data/lib/purview/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: purview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan W. Zaleski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/purview/exceptions/could_not_baseline.rb
|
116
116
|
- lib/purview/exceptions/could_not_disable.rb
|
117
117
|
- lib/purview/exceptions/could_not_enable.rb
|
118
|
+
- lib/purview/exceptions/could_not_find_table_metadata.rb
|
118
119
|
- lib/purview/exceptions/could_not_initialize.rb
|
119
120
|
- lib/purview/exceptions/could_not_lock.rb
|
120
121
|
- lib/purview/exceptions/could_not_sync.rb
|
@@ -167,6 +168,7 @@ files:
|
|
167
168
|
- lib/purview/structs/base.rb
|
168
169
|
- lib/purview/structs/result.rb
|
169
170
|
- lib/purview/structs/row.rb
|
171
|
+
- lib/purview/structs/table_metadata.rb
|
170
172
|
- lib/purview/structs/window.rb
|
171
173
|
- lib/purview/tables.rb
|
172
174
|
- lib/purview/tables/base.rb
|