active_tree 0.2.9 → 0.3
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/Gemfile.lock +2 -2
- data/README.md +9 -3
- data/lib/active_tree/models/concerns/active_tree_able.rb +13 -6
- data/lib/active_tree/version.rb +1 -1
- data/lib/generators/active_tree/templates/migration.rb.tt +10 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fb9ce62863408c33ab2b8db4bdfa7b21a67b15f14927f43d9b168dfe121604a
|
4
|
+
data.tar.gz: 8dc8ad54ec03529d82bab17e219389057a7040fb1340bc691a0c9de06566ef66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cda0e7157dfa1abd83dd92df6430bce8842500cc93aa58b07a0fa0216ea8c826f9ff61dec764bfa3bfbd915a67f32e8006987a960f7beede67d1a9357e68280d
|
7
|
+
data.tar.gz: 0e62ce8e6fb8d9ffe4d1caecfa32f6129842607452ed217116b0d7802c2c2d190ba48dc58f432c886a95dc902074308fad7071dd4b94a025d2856a73bd18783e
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
|
3
3
|
# ActiveTree
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
This gem implements a denormalized database model for tree data as well as several vectors for convenient querying.
|
5
|
+
This gem implements a denormalized database model for tree data backed up by the Postgres LTREE extension.
|
8
6
|
|
9
7
|
## Installation
|
10
8
|
|
@@ -91,6 +89,14 @@ The `ActiveTree::Metadata` model can store key-value pairs queryable through Act
|
|
91
89
|
ActiveTree::Model.match_path("*.Battery.*").metadata.where(key: "Shipping weight").sum(:value)
|
92
90
|
```
|
93
91
|
|
92
|
+
## Partitioning
|
93
|
+
|
94
|
+
All data is partitioned for each owner using the owner_id as partition index. Through the yml configuration you can choose how the gem behaves when deleting an owner record - either delete the partition and all the data, or detach the partition and keep the data for later use.
|
95
|
+
|
96
|
+
Through subsequent ActiveRecord migrations the data can be federated from a separate Postgres server.
|
97
|
+
|
98
|
+
The main table as well as its partitions can be queried through PostgREST using the role attached to the owner model.
|
99
|
+
|
94
100
|
## Caveats
|
95
101
|
|
96
102
|
`pg_ltree` .child / .parent queries do not work across different models due to an ActiveRecord limitation that requires results to be related via inheritance.
|
@@ -35,18 +35,25 @@ module ActiveTree
|
|
35
35
|
|
36
36
|
# create data partition
|
37
37
|
active_tree_sql "create table if not exists #{active_tree_table_name}_#{id} partition of #{active_tree_table_name} for values in (#{id})"
|
38
|
-
#
|
39
|
-
|
40
|
-
|
38
|
+
# create partition indexes
|
39
|
+
active_tree_sql "create index index_#{id}_by_id on #{active_tree_table_name}_#{id} (id)"
|
40
|
+
active_tree_sql "create index index_#{id}_by_owner_id on #{active_tree_table_name}_#{id} (owner_id)"
|
41
|
+
active_tree_sql "create index index_#{id}_by_type on #{active_tree_table_name}_#{id} (type)"
|
42
|
+
active_tree_sql "create index index_#{id}_by_parent_entity_id on #{active_tree_table_name}_#{id} (parent_entity_id)"
|
43
|
+
active_tree_sql "create index index_#{id}_by_path on #{active_tree_table_name}_#{id} using gist (path)"
|
44
|
+
active_tree_sql "create index index_#{id}_by_data_provider_and_data_external_id on #{active_tree_table_name}_#{id} (data_provider, data_external_id)"
|
45
|
+
|
46
|
+
|
47
|
+
if ACTIVE_TREE_OPTIONS[:create_postgrest_roles]
|
41
48
|
# drop role if it exists
|
42
49
|
active_tree_sql "drop role if exists #{ active_tree_role }"
|
43
50
|
|
44
51
|
# create role
|
45
52
|
active_tree_sql "create role #{ active_tree_role }"
|
46
53
|
|
47
|
-
|
48
|
-
|
49
|
-
|
54
|
+
# grant privs
|
55
|
+
active_tree_sql "grant all privileges on #{active_tree_table_name}_#{id} to #{ active_tree_role }"
|
56
|
+
end
|
50
57
|
|
51
58
|
end # create_storage
|
52
59
|
|
data/lib/active_tree/version.rb
CHANGED
@@ -40,9 +40,6 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version
|
|
40
40
|
) partition by list(owner_id)
|
41
41
|
SQL
|
42
42
|
|
43
|
-
# create an "others" partition for when the owner is undefined/unknown? just in case / may help in some edge cases
|
44
|
-
execute "CREATE TABLE #{ACTIVE_TREE_OPTIONS[:table_name]}_others PARTITION OF #{ACTIVE_TREE_OPTIONS[:table_name]} DEFAULT"
|
45
|
-
|
46
43
|
|
47
44
|
# add indexes
|
48
45
|
add_index ACTIVE_TREE_OPTIONS[:table_name], :id
|
@@ -55,6 +52,16 @@ SQL
|
|
55
52
|
add_index ACTIVE_TREE_OPTIONS[:table_name], [:data_provider, :data_external_id]
|
56
53
|
|
57
54
|
|
55
|
+
# create an "others" partition for when the owner is undefined/unknown? just in case / may help in some edge cases
|
56
|
+
execute "CREATE TABLE #{ACTIVE_TREE_OPTIONS[:table_name]}_others PARTITION OF #{ACTIVE_TREE_OPTIONS[:table_name]} DEFAULT"
|
57
|
+
|
58
|
+
execute "create index index_others_by_id on #{ACTIVE_TREE_OPTIONS[:table_name]}_others (id)"
|
59
|
+
execute "create index index_others_by_owner_id on #{ACTIVE_TREE_OPTIONS[:table_name]}_others (owner_id)"
|
60
|
+
execute "create index index_others_by_type on #{ACTIVE_TREE_OPTIONS[:table_name]}_others (type)"
|
61
|
+
execute "create index index_others_by_parent_entity_id on #{ACTIVE_TREE_OPTIONS[:table_name]}_others (parent_entity_id)"
|
62
|
+
execute "create index index_others_by_path on #{ACTIVE_TREE_OPTIONS[:table_name]}_others using gist (path)"
|
63
|
+
execute "create index index_others_by_data_provider_and_data_external_id on #{ACTIVE_TREE_OPTIONS[:table_name]}_others (data_provider, data_external_id)"
|
64
|
+
|
58
65
|
# when postgrest is enabled...
|
59
66
|
if ACTIVE_TREE_OPTIONS[:create_postgrest_roles]
|
60
67
|
# create postgrest anon user with no privs
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick @ Earthster
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|