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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bf00b350061ffb40ff9a7db9cb0f10d06bea1a20eb82062ac66029d5fd1ad52
4
- data.tar.gz: 6babe94e0d5f928b9bb3c14306850211c6ba4cd5660ee5cfebd6ace953e8be6a
3
+ metadata.gz: 5fb9ce62863408c33ab2b8db4bdfa7b21a67b15f14927f43d9b168dfe121604a
4
+ data.tar.gz: 8dc8ad54ec03529d82bab17e219389057a7040fb1340bc691a0c9de06566ef66
5
5
  SHA512:
6
- metadata.gz: 40dce12132b74bc1b53bb52bc1281e76c953fe8a486613ff362f742b4a51e6847b05938bfd84ea9be56230edec6112543263ef3d52caab25837c3a9ed0d2c837
7
- data.tar.gz: 9679c3a799b5472be0786085c060fa1bbfa6fa8ca160412797e1a5a79fe69b2db6137573ecf4095341d98948301077e285ef27c3f0e861f462a1c55b64356f05
6
+ metadata.gz: cda0e7157dfa1abd83dd92df6430bce8842500cc93aa58b07a0fa0216ea8c826f9ff61dec764bfa3bfbd915a67f32e8006987a960f7beede67d1a9357e68280d
7
+ data.tar.gz: 0e62ce8e6fb8d9ffe4d1caecfa32f6129842607452ed217116b0d7802c2c2d190ba48dc58f432c886a95dc902074308fad7071dd4b94a025d2856a73bd18783e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_tree (0.2.9)
4
+ active_tree (0.3)
5
5
  activerecord (~> 6.0)
6
6
  jwt (~> 2.2.3)
7
7
  pg_ltree (~> 1.1.8)
@@ -60,4 +60,4 @@ DEPENDENCIES
60
60
  rspec (~> 3.0)
61
61
 
62
62
  BUNDLED WITH
63
- 2.2.27
63
+ 2.2.29
data/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  # ActiveTree
4
4
 
5
- Storing, processing and working with hierarchical data has always been challenging. A multitude of data models and implementations exist already but every one of them makes huge compromises or lacks functionality.
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
- # TODO create partition indexes
39
-
40
- if ACTIVE_TREE_OPTIONS[:create_postgrest_roles]
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
- # grant privs
48
- active_tree_sql "grant all privileges on #{active_tree_table_name}_#{id} to #{ active_tree_role }"
49
- end
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveTree
4
- VERSION = "0.2.9"
4
+ VERSION = "0.3"
5
5
  end
@@ -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.2.9
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-08 00:00:00.000000000 Z
11
+ date: 2021-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord