code0-zero_track 0.0.8 → 0.0.9

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: d6150c745af141848ee0848ec9beda4db5c1809ece022f90b9006cf69df88f10
4
- data.tar.gz: 73128d1d5ab33dec7887b195831c8a1b591eb46999c5cb4e20eb79387d5d138e
3
+ metadata.gz: 5af11d8b9714d7d557f46cfe5ea9dbd6702d3bc85f5aa67e9ce09e44c6963238
4
+ data.tar.gz: 5fc99a08521c502aec93ebe725d9c82c18d9b49e6a7120fba5127db9bb620f6b
5
5
  SHA512:
6
- metadata.gz: 129416f538b904432c213a42a22d95244220fb9c35548b089d9a9ef4836b11b1b3fd0a93c910ab748dfd51d024d56d00ac525e7fd22855330916462b848a3824
7
- data.tar.gz: 78bba0f4d37e6a08b2d5b02a46478060e7ea944ee8a40c407a4f63c819c450ae41e86b33df9b47a28472ebb202dad28a49c2c95fa221de041d672de1164e8a6d
6
+ metadata.gz: fded2cb69f93aff4704e89b6c3094a0c9dd47a9891748ddd40af68e72eb2d432c150ecd62bf104cd864ceee65a5e782b3eef656fd7ac69ea338898f2cae713a7
7
+ data.tar.gz: db2a0b2c23fa93a22442e7f8e0c956ddae670a05bf4105c0a77ea98968c5827541b442b119331bdfb6f8b564b151ccedb9b1418cf45a8dd2fe243c7402748bb8
data/README.md CHANGED
@@ -87,9 +87,10 @@ config.zero_track.db_partitioning.base_ar_class = 'ActiveRecord::Base' # default
87
87
  Include the migration helpers by inheriting from `Code0::ZeroTrack::Database::Migration[1.0]` (or the
88
88
  appropriate version). The following methods become available:
89
89
 
90
- `create_partition_by_date_table(table_name, partition_column:, **options, &block)` creates a table
91
- partitioned by range on the given column. It automatically sets up a composite primary key
92
- of `(id, partition_column)`.
90
+ `create_partition_by_date_table(table_name, partition_column:, primary_key: nil, **options, &block)` creates a table
91
+ partitioned by range on the given column. By default, it adds a `bigserial` id column and sets up a composite
92
+ primary key of `(id, partition_column)`. If `primary_key` is provided (e.g. `primary_key: %i[date other_column]`),
93
+ the id column is omitted and the given columns are used as the primary key instead.
93
94
 
94
95
  `create_dynamic_partition_schema` / `drop_dynamic_partition_schema` creates or drops the schema
95
96
  used for storing dynamic partitions.
@@ -5,21 +5,23 @@ module Code0
5
5
  module Database
6
6
  module MigrationHelpers
7
7
  module TablePartitioning
8
- def create_partition_by_date_table(table_name, partition_column:, **options, &block)
8
+ def create_partition_by_date_table(table_name, partition_column:, primary_key: nil, **options, &block)
9
9
  options[:options] = "PARTITION BY RANGE (#{quote_column_name(partition_column)})"
10
10
  options[:id] = false
11
11
 
12
12
  create_table(table_name, **options) do |t|
13
- t.bigserial :id, null: false
13
+ t.bigserial :id, null: false unless primary_key
14
14
 
15
15
  block.call(t)
16
16
  end
17
17
 
18
+ pk_columns = primary_key || [:id, partition_column]
19
+
18
20
  reversible do |dir|
19
21
  dir.up do
20
22
  execute <<~SQL.squish
21
23
  ALTER TABLE #{quote_table_name(table_name)}
22
- ADD PRIMARY KEY (#{quote_column_name(:id)}, #{quote_column_name(partition_column)})
24
+ ADD PRIMARY KEY (#{pk_columns.map { |c| quote_column_name(c) }.join(', ')})
23
25
  SQL
24
26
  end
25
27
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Code0
4
4
  module ZeroTrack
5
- VERSION = '0.0.8'
5
+ VERSION = '0.0.9'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code0-zero_track
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niklas van Schrick