paper_trail-association_tracking 1.1.0 → 1.1.1
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/CHANGELOG.md +12 -2
- data/README.md +1 -2
- data/lib/generators/paper_trail_association_tracking/add_foreign_type_to_version_associations_generator.rb +55 -0
- data/lib/generators/paper_trail_association_tracking/templates/add_foreign_type_to_version_associations.rb.erb +11 -0
- data/lib/generators/paper_trail_association_tracking/templates/create_version_associations.rb.erb +1 -1
- data/lib/paper_trail_association_tracking/reifiers/has_many.rb +1 -1
- data/lib/paper_trail_association_tracking/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 32ff5ab37c0c0ed5ffdbc1c51ecb7a436be425a15631da3bb2fb00b8dbb1653d
|
|
4
|
+
data.tar.gz: 40609621efbec9948e8bb880de590a251c98a95531356e0436fff8b88719af1f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad7e68bb6c2a890cfcdd1300796dc32c8ad1d428dd73f4041fb81339532573fab8b78cf0a5616b28630d558b95fcd8406d7b421a31c697d32dd4beb983cad573
|
|
7
|
+
data.tar.gz: 492671a7f7a042246fd294e78092b2b59498166d5180032cc4db83aa836e93aad029dabcc9321831ea56901c8b23869a369dbd959bed74791c80f12f6808fa23
|
data/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
-
## Unreleased
|
|
3
|
+
## 2.0.0 - Unreleased
|
|
4
4
|
|
|
5
|
-
-
|
|
5
|
+
- [#11](https://github.com/westonganger/paper_trail-association_tracking/issues/11) - Remove null constraint on `version_associations.foreign_type` column which was added in `v1.1.0`. This fixes issues adding the column to existing projects who are upgrading.
|
|
6
|
+
- Add generator `rails g paper_trail_association_tracking:add_foreign_type_to_version_associations` for `versions_associations.foreign_type` column for upgrading applications from `v1.0.0` or earlier.
|
|
7
|
+
|
|
8
|
+
### How to Upgrade from v1.0.0 or earlier
|
|
9
|
+
|
|
10
|
+
- Run `rails g paper_trail_association_tracking:add_foreign_type_to_version_associations` and then migrate your database.
|
|
11
|
+
|
|
12
|
+
## 1.1.1 - 2018-01-14
|
|
13
|
+
|
|
14
|
+
- Same as v2 release, this is released simply to maintain a working `v1` branch since `v1.1.0` was broken
|
|
6
15
|
|
|
7
16
|
## 1.1.0 - 2018-12-28
|
|
8
17
|
|
|
18
|
+
- Note: This release is somewhat broken, please upgrade to `v2.0.0` or stay on `v1.0.0`
|
|
9
19
|
- [#10](https://github.com/westonganger/paper_trail-association_tracking/pull/9) - The `has_many: true` option now reifies polymorphic associations. Previously they were skipped.
|
|
10
20
|
- [#9](https://github.com/westonganger/paper_trail-association_tracking/pull/9) - The `belongs_to: true` option now reifies polymorphic associations. Previously they were skipped.
|
|
11
21
|
|
data/README.md
CHANGED
|
@@ -9,8 +9,7 @@ Plugin for the [PaperTrail](https://github.com/paper-trail-gem/paper_trail.git)
|
|
|
9
9
|
**PR's will happily be accepted**
|
|
10
10
|
|
|
11
11
|
This gem was extracted from PaperTrail in v9.2 to simplify things in PaperTrail and association tracking seperately.
|
|
12
|
-
At this time, `paper_trail` has a
|
|
13
|
-
to association tracking. This arrangement will be maintained for a few years, if practical.
|
|
12
|
+
At this time, `paper_trail` only has a development dependency in order to run the tests. If you want use this gem in your project you must add it to your own Gemfile.
|
|
14
13
|
|
|
15
14
|
A little history lesson, discussed as early as 2009, and first implemented in late 2014, association
|
|
16
15
|
tracking was part of PT core until 2018 as an experimental feature and was use at your own risk. This gem now
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/generators"
|
|
4
|
+
require "rails/generators/active_record"
|
|
5
|
+
|
|
6
|
+
module PaperTrailAssociationTracking
|
|
7
|
+
# Installs PaperTrail in a rails app.
|
|
8
|
+
class AddForeignTypeToVersionAssociationsGenerator < ::Rails::Generators::Base
|
|
9
|
+
include ::Rails::Generators::Migration
|
|
10
|
+
|
|
11
|
+
# Class names of MySQL adapters.
|
|
12
|
+
# - `MysqlAdapter` - Used by gems: `mysql`, `activerecord-jdbcmysql-adapter`.
|
|
13
|
+
# - `Mysql2Adapter` - Used by `mysql2` gem.
|
|
14
|
+
MYSQL_ADAPTERS = [
|
|
15
|
+
"ActiveRecord::ConnectionAdapters::MysqlAdapter",
|
|
16
|
+
"ActiveRecord::ConnectionAdapters::Mysql2Adapter"
|
|
17
|
+
].freeze
|
|
18
|
+
|
|
19
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
20
|
+
|
|
21
|
+
desc "Generates (but does not run) a migration to add a the foreign_type column to the version_associations table after upgrading from v1.0 or earlier."
|
|
22
|
+
|
|
23
|
+
def create_migrations
|
|
24
|
+
add_paper_trail_migration("add_foreign_type_to_version_associations")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.next_migration_number(dirname)
|
|
28
|
+
::ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
protected
|
|
32
|
+
|
|
33
|
+
def add_paper_trail_migration(template)
|
|
34
|
+
migration_dir = File.expand_path("db/migrate")
|
|
35
|
+
if self.class.migration_exists?(migration_dir, template)
|
|
36
|
+
::Kernel.warn "Migration already exists: #{template}"
|
|
37
|
+
else
|
|
38
|
+
migration_template(
|
|
39
|
+
"#{template}.rb.erb",
|
|
40
|
+
"db/migrate/#{template}.rb",
|
|
41
|
+
migration_version: migration_version
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def migration_version
|
|
49
|
+
major = ActiveRecord::VERSION::MAJOR
|
|
50
|
+
if major >= 5
|
|
51
|
+
"[#{major}.#{ActiveRecord::VERSION::MINOR}]"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# This migration and AddTransactionIdColumnToVersions provide the necessary
|
|
2
|
+
# schema for tracking associations.
|
|
3
|
+
class AddForeignTypeToVersionAssociations < ActiveRecord::Migration<%= migration_version %>
|
|
4
|
+
def self.up
|
|
5
|
+
add_column :version_associations, :foreign_type, :string, index: true
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def self.down
|
|
9
|
+
remove_column :version_associations, :foreign_type
|
|
10
|
+
end
|
|
11
|
+
end
|
data/lib/generators/paper_trail_association_tracking/templates/create_version_associations.rb.erb
CHANGED
|
@@ -6,7 +6,7 @@ class CreateVersionAssociations < ActiveRecord::Migration<%= migration_version %
|
|
|
6
6
|
t.integer :version_id
|
|
7
7
|
t.string :foreign_key_name, null: false
|
|
8
8
|
t.integer :foreign_key_id
|
|
9
|
-
t.string :foreign_type
|
|
9
|
+
t.string :foreign_type
|
|
10
10
|
end
|
|
11
11
|
add_index :version_associations, [:version_id]
|
|
12
12
|
add_index :version_associations,
|
|
@@ -100,7 +100,7 @@ module PaperTrailAssociationTracking
|
|
|
100
100
|
select("MIN(version_id)").
|
|
101
101
|
where("foreign_key_name = ?", assoc.foreign_key).
|
|
102
102
|
where("foreign_key_id = ?", model.id).
|
|
103
|
-
where(
|
|
103
|
+
where(foreign_type: [model.class.name, nil]).
|
|
104
104
|
where("#{version_table}.item_type = ?", assoc.klass.base_class.name).
|
|
105
105
|
where("created_at >= ? OR transaction_id = ?", version_at, tx_id).
|
|
106
106
|
group("item_id").
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: paper_trail-association_tracking
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Weston Ganger
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2019-01-14 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: appraisal
|
|
@@ -210,7 +210,9 @@ files:
|
|
|
210
210
|
- LICENSE
|
|
211
211
|
- README.md
|
|
212
212
|
- Rakefile
|
|
213
|
+
- lib/generators/paper_trail_association_tracking/add_foreign_type_to_version_associations_generator.rb
|
|
213
214
|
- lib/generators/paper_trail_association_tracking/install_generator.rb
|
|
215
|
+
- lib/generators/paper_trail_association_tracking/templates/add_foreign_type_to_version_associations.rb.erb
|
|
214
216
|
- lib/generators/paper_trail_association_tracking/templates/add_transaction_id_column_to_versions.rb.erb
|
|
215
217
|
- lib/generators/paper_trail_association_tracking/templates/create_version_associations.rb.erb
|
|
216
218
|
- lib/paper_trail-association_tracking.rb
|
|
@@ -252,7 +254,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
252
254
|
- !ruby/object:Gem::Version
|
|
253
255
|
version: 1.3.6
|
|
254
256
|
requirements: []
|
|
255
|
-
|
|
257
|
+
rubyforge_project:
|
|
258
|
+
rubygems_version: 2.7.6
|
|
256
259
|
signing_key:
|
|
257
260
|
specification_version: 4
|
|
258
261
|
summary: Plugin for the PaperTrail gem to track and reify associations
|