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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5af11d8b9714d7d557f46cfe5ea9dbd6702d3bc85f5aa67e9ce09e44c6963238
|
|
4
|
+
data.tar.gz: 5fc99a08521c502aec93ebe725d9c82c18d9b49e6a7120fba5127db9bb620f6b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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(
|
|
24
|
+
ADD PRIMARY KEY (#{pk_columns.map { |c| quote_column_name(c) }.join(', ')})
|
|
23
25
|
SQL
|
|
24
26
|
end
|
|
25
27
|
end
|