dag_me 0.3.0 → 0.4.0
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/README.md +9 -0
- data/lib/dag_me/configuration.rb +23 -4
- data/lib/dag_me/macro.rb +2 -2
- data/lib/dag_me/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 74bbe571eab1c3286bee396dbe9516dff6de559e55ffe5a68bd9baa1c394db50
|
|
4
|
+
data.tar.gz: 9e7fce79faa9157888ef20fb3aef236e2a2f0da836d5b8aaa1fde56bb95a4097
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 680138923ec2d8ff9e9dec8cc048211dc82576c412b2b38f68e4bf0eb28ff12c90beb64b70ca173b5c3d16e09acb241cf9631393f78c391b26c3fd0d646e86ae
|
|
7
|
+
data.tar.gz: 25a79cf7c541f8a03b680f22c110ebdc9b274c178c5fb5c9e95ffb1f7b5e0084a8c5a41ed7a6ef4494d358c02bf5edbefdca6530c98014130e99f1429d511041
|
data/README.md
CHANGED
|
@@ -150,6 +150,15 @@ end
|
|
|
150
150
|
Generated tables (`orbital.station_dag_edges`, `orbital.station_dag_paths`) and
|
|
151
151
|
functions land in the node table's schema; trigger names stay plain identifiers.
|
|
152
152
|
|
|
153
|
+
Long table names would push generated identifiers past PostgreSQL's 63-byte
|
|
154
|
+
limit; pass a custom prefix instead of letting it truncate:
|
|
155
|
+
|
|
156
|
+
```ruby
|
|
157
|
+
class MaterialTracking::ProductBillOfMaterial < ApplicationRecord
|
|
158
|
+
dag_me prefix: 'bom_dag' # bom_dag_edges, bom_dag_paths, bom_dag_lock, ...
|
|
159
|
+
end
|
|
160
|
+
```
|
|
161
|
+
|
|
153
162
|
## Multi-tenancy
|
|
154
163
|
|
|
155
164
|
```ruby
|
data/lib/dag_me/configuration.rb
CHANGED
|
@@ -6,7 +6,8 @@ module DagMe
|
|
|
6
6
|
|
|
7
7
|
attr_reader :model, :name, :maintain, :prefix, :schema, :edge_table, :paths_table, :scope_columns
|
|
8
8
|
|
|
9
|
-
def initialize(model:, name: nil, maintain: :postgresql_closure, scope: nil,
|
|
9
|
+
def initialize(model:, name: nil, maintain: :postgresql_closure, scope: nil, prefix: nil,
|
|
10
|
+
edge_table: nil, paths_table: nil)
|
|
10
11
|
unless MAINTAIN_MODES.include?(maintain)
|
|
11
12
|
raise ArgumentError, "maintain must be one of #{MAINTAIN_MODES.inspect}, got #{maintain.inspect}"
|
|
12
13
|
end
|
|
@@ -19,9 +20,12 @@ module DagMe
|
|
|
19
20
|
# identifier - trigger and temp-table names cannot carry a schema - and
|
|
20
21
|
# place generated tables and functions in the node table's schema.
|
|
21
22
|
@schema, base_table = split_schema(model.table_name)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@
|
|
23
|
+
# A custom prefix keeps generated identifiers under PostgreSQL's 63-byte
|
|
24
|
+
# limit when the derived one (long table names) would silently truncate.
|
|
25
|
+
@prefix = prefix&.to_s || [base_table.singularize, @name, 'dag'].compact.join('_')
|
|
26
|
+
validate_prefix!
|
|
27
|
+
@edge_table = edge_table || qualify("#{@prefix}_edges")
|
|
28
|
+
@paths_table = paths_table || qualify("#{@prefix}_paths")
|
|
25
29
|
# Ivar peek keeps class load DB-free; composite keys must be declared
|
|
26
30
|
# before the macro. Array === because AR seeds a BasicObject sentinel.
|
|
27
31
|
@composite_pk = model.instance_variable_defined?(:@primary_key) &&
|
|
@@ -137,6 +141,21 @@ module DagMe
|
|
|
137
141
|
|
|
138
142
|
private
|
|
139
143
|
|
|
144
|
+
# The longest generated suffix is "_edge_insert_check" (18 bytes); reject
|
|
145
|
+
# prefixes whose identifiers PostgreSQL would silently truncate at 63.
|
|
146
|
+
def validate_prefix!
|
|
147
|
+
unless /\A[a-z_][a-z0-9_]*\z/.match?(@prefix)
|
|
148
|
+
raise ArgumentError, "prefix must be a lowercase SQL identifier, got #{@prefix.inspect}"
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
max = 63 - '_edge_insert_check'.length
|
|
152
|
+
return if @prefix.length <= max
|
|
153
|
+
|
|
154
|
+
raise ArgumentError,
|
|
155
|
+
"prefix #{@prefix.inspect} is #{@prefix.length} bytes; identifiers would exceed " \
|
|
156
|
+
"PostgreSQL's 63-byte limit (max prefix: #{max}). Pass dag_me prefix: '...' with a shorter name."
|
|
157
|
+
end
|
|
158
|
+
|
|
140
159
|
def split_schema(table_name)
|
|
141
160
|
return table_name.split('.', 2) if table_name.include?('.')
|
|
142
161
|
|
data/lib/dag_me/macro.rb
CHANGED
|
@@ -14,7 +14,7 @@ module DagMe
|
|
|
14
14
|
# relay.add_child(other, dag: :power)
|
|
15
15
|
# relay.comms_children
|
|
16
16
|
# Relay.dag(:power).rebuild!
|
|
17
|
-
def dag_me(name = nil, maintain: :postgresql_closure, scope: nil, edge_table: nil, paths_table: nil)
|
|
17
|
+
def dag_me(name = nil, maintain: :postgresql_closure, scope: nil, prefix: nil, edge_table: nil, paths_table: nil)
|
|
18
18
|
key = name&.to_sym || :default
|
|
19
19
|
unless include?(DagMe::Model)
|
|
20
20
|
class_attribute :dag_configs, instance_writer: false, instance_predicate: false, default: {}.freeze
|
|
@@ -22,7 +22,7 @@ module DagMe
|
|
|
22
22
|
end
|
|
23
23
|
raise ArgumentError, "#{self.name}: dag #{key.inspect} is already defined" if dag_configs.key?(key)
|
|
24
24
|
|
|
25
|
-
config = Configuration.new(model: self, name: name&.to_sym, maintain:, scope:, edge_table:, paths_table:)
|
|
25
|
+
config = Configuration.new(model: self, name: name&.to_sym, maintain:, scope:, prefix:, edge_table:, paths_table:)
|
|
26
26
|
self.dag_configs = dag_configs.merge(key => config).freeze
|
|
27
27
|
DagMe::Model.attach(self, config)
|
|
28
28
|
self
|
data/lib/dag_me/version.rb
CHANGED