archiving 0.3.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 625ce4210ddc7e954aea6fe6556b27e8884a0ea2
4
- data.tar.gz: 040e266a335f12c771500bb5a2999cf1a3b1990a
2
+ SHA256:
3
+ metadata.gz: 5a4bc5f5c7e8a7ce1705038d689bbdf34ab24e0c25a6e1b8f0688b136281104d
4
+ data.tar.gz: 4e75065f21a03f1880c2be564a404b4a51844e7714f0d19712ef69fed2617f9a
5
5
  SHA512:
6
- metadata.gz: 5a961a4e848ee2fee3785cdde176f036734f3f15c678097fdddda1ca626d1a08c23b1505541bf31223fc7d300691b670ceda970925c12e3240e0785cde0a283e
7
- data.tar.gz: 31a6b1c13717dafc353dd362e78fe96472d193219545f34403bc15f9162e6870387ec9b7bc52c7cd613941b3b7b7864e07d5ff76220eb98556819e7bf2a8b953
6
+ metadata.gz: 05dd8dd98757f8262f5446aa0b545e7b3969c0dfda0ee3051d19ee8f25dd6265b2f187108dba3c0bed4a9d9a1ec6c73b43b42e53325a15fe2eaf9d3693fd19b6
7
+ data.tar.gz: 66042222f70b71aa49d7453858897fc33d760fe62ce5d26f2ad8174af87651b478b9e9e64f00070b1f6097800ea6264e48f0d6134a03805f8d7616201fa65341
data/Rakefile CHANGED
@@ -20,9 +20,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
-
24
-
25
-
26
23
  Bundler::GemHelper.install_tasks
27
24
 
28
25
  require 'rake/testtask'
@@ -8,11 +8,13 @@ module Archiving
8
8
  module ClassMethods
9
9
  attr_accessor :archive_table
10
10
 
11
- def has_archive_table(connection: nil)
11
+ def has_archive_table(connection: nil, read_only: true)
12
12
  model = name.constantize
13
13
  @archive_model = model.const_set("Archive", Class.new(model))
14
- @archive_model.after_initialize do |record|
15
- record.readonly! unless record.new_record?
14
+ if read_only
15
+ @archive_model.after_initialize do |record|
16
+ record.readonly! unless record.new_record?
17
+ end
16
18
  end
17
19
  @archive_model.table_name = "#{table_name}_archive"
18
20
  if connection
@@ -93,6 +93,7 @@ class ArchiveTableTest < ActiveSupport::TestCase
93
93
  test "new archive records can be persisted" do
94
94
  assert_nothing_raised do
95
95
  Post::Archive.create!
96
+ Postrw::Archive.create!
96
97
  end
97
98
  end
98
99
 
@@ -103,6 +104,14 @@ class ArchiveTableTest < ActiveSupport::TestCase
103
104
  assert_raises(ActiveRecord::ReadOnlyRecord) do
104
105
  archive.update_attribute(:title, "New post")
105
106
  end
107
+
108
+ # unless they are not
109
+ archive = Postrw::Archive.create!
110
+ archive = Postrw::Archive.find(archive.id)
111
+
112
+ assert_nothing_raised do
113
+ archive.update_attribute(:title, "New post")
114
+ end
106
115
  end
107
116
 
108
117
  test "existing archive records fetched with with_archive are read only" do
@@ -114,6 +123,16 @@ class ArchiveTableTest < ActiveSupport::TestCase
114
123
  archive.title = "New post"
115
124
  archive.save!
116
125
  end
126
+
127
+ # unless they are not
128
+ Postrw::Archive.create!
129
+
130
+ archive = Postrw.with_archive.first
131
+
132
+ assert_nothing_raised do
133
+ archive.title = "New post"
134
+ archive.save!
135
+ end
117
136
  end
118
137
 
119
138
  test "archiving aged records" do
@@ -0,0 +1,3 @@
1
+ class Postrw < ActiveRecord::Base
2
+ has_archive_table read_only: false
3
+ end
@@ -1,4 +1,11 @@
1
- class CreatePosts < ActiveRecord::Migration
1
+ migration_class =
2
+ if ActiveRecord::VERSION::MAJOR >= 5
3
+ ActiveRecord::Migration[4.2]
4
+ else
5
+ ActiveRecord::Migration
6
+ end
7
+
8
+ class CreatePosts < migration_class
2
9
  def change
3
10
  create_table :posts do |t|
4
11
  t.string :title
@@ -1,4 +1,11 @@
1
- class PostsArchive < ActiveRecord::Migration
1
+ migration_class =
2
+ if ActiveRecord::VERSION::MAJOR >= 5
3
+ ActiveRecord::Migration[4.2]
4
+ else
5
+ ActiveRecord::Migration
6
+ end
7
+
8
+ class PostsArchive < migration_class
2
9
  def change
3
10
  create_table :posts_archive do |t|
4
11
  t.string :title
@@ -1,4 +1,11 @@
1
- class PostsTag < ActiveRecord::Migration
1
+ migration_class =
2
+ if ActiveRecord::VERSION::MAJOR >= 5
3
+ ActiveRecord::Migration[4.2]
4
+ else
5
+ ActiveRecord::Migration
6
+ end
7
+
8
+ class PostsTag < migration_class
2
9
  def change
3
10
  add_column :posts, :tag, :string
4
11
  add_column :posts_archive, :tag, :string
@@ -1,4 +1,11 @@
1
- class CreateLogs < ActiveRecord::Migration
1
+ migration_class =
2
+ if ActiveRecord::VERSION::MAJOR >= 5
3
+ ActiveRecord::Migration[4.2]
4
+ else
5
+ ActiveRecord::Migration
6
+ end
7
+
8
+ class CreateLogs < migration_class
2
9
  def change
3
10
  create_table :log_days do |t|
4
11
  t.references :post
@@ -1,4 +1,11 @@
1
- class CreatePostableOnLogDay < ActiveRecord::Migration
1
+ migration_class =
2
+ if ActiveRecord::VERSION::MAJOR >= 5
3
+ ActiveRecord::Migration[4.2]
4
+ else
5
+ ActiveRecord::Migration
6
+ end
7
+
8
+ class CreatePostableOnLogDay < migration_class
2
9
  def change
3
10
  %w(log_days log_days_archive).each do |table|
4
11
  add_column table, :postable_type, :string
@@ -1,4 +1,11 @@
1
- class CreateLogOther < ActiveRecord::Migration
1
+ migration_class =
2
+ if ActiveRecord::VERSION::MAJOR >= 5
3
+ ActiveRecord::Migration[4.2]
4
+ else
5
+ ActiveRecord::Migration
6
+ end
7
+
8
+ class CreateLogOther < migration_class
2
9
  def change
3
10
  create_table :log_others do |t|
4
11
  t.references :post
@@ -1,4 +1,17 @@
1
- class CreateLogOtherArchive < ActiveRecord::Migration
1
+ class OtherConnection < ActiveRecord::Base
2
+ self.abstract_class = true
3
+
4
+ establish_connection :"other_#{Rails.env}"
5
+ end
6
+
7
+ migration_class =
8
+ if ActiveRecord::VERSION::MAJOR >= 5
9
+ ActiveRecord::Migration[4.2]
10
+ else
11
+ ActiveRecord::Migration
12
+ end
13
+
14
+ class CreateLogOtherArchive < migration_class
2
15
  def up
3
16
  set_connection do
4
17
  create_table :log_others_archive do |t|
@@ -16,11 +29,10 @@ class CreateLogOtherArchive < ActiveRecord::Migration
16
29
 
17
30
  def set_connection
18
31
  connection_was = @connection
19
- @connection = ActiveRecord::Base.establish_connection(:"other_#{Rails.env}").connection
32
+ @connection = OtherConnection.connection
20
33
  yield
21
34
  ensure
22
35
  @connection = connection_was
23
- ActiveRecord::Base.remove_connection
24
- ActiveRecord::Base.establish_connection
36
+ OtherConnection.remove_connection
25
37
  end
26
38
  end
@@ -0,0 +1,23 @@
1
+ migration_class =
2
+ if ActiveRecord::VERSION::MAJOR >= 5
3
+ ActiveRecord::Migration[4.2]
4
+ else
5
+ ActiveRecord::Migration
6
+ end
7
+
8
+ class CreatePostrws < migration_class
9
+ def change
10
+ create_table :postrws do |t|
11
+ t.string :title
12
+ t.text :body
13
+
14
+ t.timestamps
15
+ end
16
+ create_table :postrws_archive do |t|
17
+ t.string :title
18
+ t.text :body
19
+
20
+ t.timestamps
21
+ end
22
+ end
23
+ end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
@@ -11,56 +10,70 @@
11
10
  #
12
11
  # It's strongly recommended that you check this file into your version control system.
13
12
 
14
- ActiveRecord::Schema.define(version: 20161103110724) do
13
+ ActiveRecord::Schema.define(version: 2019_07_11_112558) do
15
14
 
16
- create_table "log_days", force: :cascade do |t|
17
- t.integer "post_id", limit: 4
18
- t.date "day"
19
- t.string "postable_type", limit: 255
20
- t.integer "postable_id", limit: 4
15
+ create_table "log_days", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci", force: :cascade do |t|
16
+ t.integer "post_id"
17
+ t.date "day"
18
+ t.string "postable_type"
19
+ t.integer "postable_id"
21
20
  end
22
21
 
23
- create_table "log_days_archive", force: :cascade do |t|
24
- t.integer "post_id", limit: 4
25
- t.date "day"
26
- t.string "postable_type", limit: 255
27
- t.integer "postable_id", limit: 4
22
+ create_table "log_days_archive", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci", force: :cascade do |t|
23
+ t.integer "post_id"
24
+ t.date "day"
25
+ t.string "postable_type"
26
+ t.integer "postable_id"
28
27
  end
29
28
 
30
- create_table "log_lines", force: :cascade do |t|
31
- t.integer "log_day_id", limit: 4
32
- t.string "descr", limit: 255
29
+ create_table "log_lines", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci", force: :cascade do |t|
30
+ t.integer "log_day_id"
31
+ t.string "descr"
33
32
  end
34
33
 
35
- create_table "log_lines_archive", force: :cascade do |t|
36
- t.integer "log_day_id", limit: 4
37
- t.string "descr", limit: 255
34
+ create_table "log_lines_archive", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci", force: :cascade do |t|
35
+ t.integer "log_day_id"
36
+ t.string "descr"
38
37
  end
39
38
 
40
- create_table "log_others", force: :cascade do |t|
41
- t.integer "post_id", limit: 4
42
- t.string "note", limit: 255
39
+ create_table "log_others", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci", force: :cascade do |t|
40
+ t.integer "post_id"
41
+ t.string "note"
43
42
  end
44
43
 
45
- create_table "log_others_archive", force: :cascade do |t|
46
- t.integer "post_id", limit: 4
47
- t.string "note", limit: 255
44
+ create_table "log_others_archive", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci", force: :cascade do |t|
45
+ t.integer "post_id"
46
+ t.string "note"
48
47
  end
49
48
 
50
- create_table "posts", force: :cascade do |t|
51
- t.string "title", limit: 255
52
- t.text "body", limit: 65535
49
+ create_table "postrws", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
50
+ t.string "title"
51
+ t.text "body"
53
52
  t.datetime "created_at"
54
53
  t.datetime "updated_at"
55
- t.string "tag", limit: 255
56
54
  end
57
55
 
58
- create_table "posts_archive", force: :cascade do |t|
59
- t.string "title", limit: 255
60
- t.text "body", limit: 65535
56
+ create_table "postrws_archive", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
57
+ t.string "title"
58
+ t.text "body"
61
59
  t.datetime "created_at"
62
60
  t.datetime "updated_at"
63
- t.string "tag", limit: 255
61
+ end
62
+
63
+ create_table "posts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci", force: :cascade do |t|
64
+ t.string "title"
65
+ t.text "body"
66
+ t.datetime "created_at"
67
+ t.datetime "updated_at"
68
+ t.string "tag"
69
+ end
70
+
71
+ create_table "posts_archive", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci", force: :cascade do |t|
72
+ t.string "title"
73
+ t.text "body"
74
+ t.datetime "created_at"
75
+ t.datetime "updated_at"
76
+ t.string "tag"
64
77
  end
65
78
 
66
79
  end
@@ -4,7 +4,14 @@ class Comment < ActiveRecord::Base
4
4
  has_archive_table
5
5
  end
6
6
 
7
- class CreateComments < ActiveRecord::Migration
7
+ migration_class =
8
+ if ActiveRecord::VERSION::MAJOR >= 5
9
+ ActiveRecord::Migration[4.2]
10
+ else
11
+ ActiveRecord::Migration
12
+ end
13
+
14
+ class CreateComments < migration_class
8
15
  def up
9
16
  create_table :comments do |t|
10
17
  t.string :author
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archiving
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Vangberg
8
8
  - Michael Kyed
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-03 00:00:00.000000000 Z
12
+ date: 2022-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: '4.2'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '6.0'
23
+ version: '7.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: '4.2'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '6.0'
33
+ version: '7.0'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: mysql2
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '4.2'
55
55
  - - "<"
56
56
  - !ruby/object:Gem::Version
57
- version: '6.0'
57
+ version: '7.0'
58
58
  type: :development
59
59
  prerelease: false
60
60
  version_requirements: !ruby/object:Gem::Requirement
@@ -64,7 +64,7 @@ dependencies:
64
64
  version: '4.2'
65
65
  - - "<"
66
66
  - !ruby/object:Gem::Version
67
- version: '6.0'
67
+ version: '7.0'
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: jquery-rails
70
70
  requirement: !ruby/object:Gem::Requirement
@@ -147,6 +147,7 @@ files:
147
147
  - test/dummy/app/models/log_line.rb
148
148
  - test/dummy/app/models/log_other.rb
149
149
  - test/dummy/app/models/post.rb
150
+ - test/dummy/app/models/postrw.rb
150
151
  - test/dummy/app/views/layouts/application.html.erb
151
152
  - test/dummy/bin/bundle
152
153
  - test/dummy/bin/rails
@@ -175,9 +176,8 @@ files:
175
176
  - test/dummy/db/migrate/20140414124125_create_postable_on_log_day.rb
176
177
  - test/dummy/db/migrate/20161103093656_create_log_other.rb
177
178
  - test/dummy/db/migrate/20161103100644_create_log_other_archive.rb
179
+ - test/dummy/db/migrate/20190711112558_create_postrws.rb
178
180
  - test/dummy/db/schema.rb
179
- - test/dummy/log/development.log
180
- - test/dummy/log/test.log
181
181
  - test/dummy/public/404.html
182
182
  - test/dummy/public/422.html
183
183
  - test/dummy/public/500.html
@@ -189,7 +189,7 @@ files:
189
189
  homepage: https://github.com/firmafon/archiving
190
190
  licenses: []
191
191
  metadata: {}
192
- post_install_message:
192
+ post_install_message:
193
193
  rdoc_options: []
194
194
  require_paths:
195
195
  - lib
@@ -204,60 +204,59 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
204
  - !ruby/object:Gem::Version
205
205
  version: '0'
206
206
  requirements: []
207
- rubyforge_project:
208
- rubygems_version: 2.4.5.1
209
- signing_key:
207
+ rubygems_version: 3.1.6
208
+ signing_key:
210
209
  specification_version: 4
211
210
  summary: MySQL Archive Tables
212
211
  test_files:
213
- - test/archive_table_test.rb
214
212
  - test/archiving_test.rb
215
- - test/dummy/app/assets/javascripts/application.js
216
- - test/dummy/app/assets/stylesheets/application.css
217
- - test/dummy/app/controllers/application_controller.rb
218
- - test/dummy/app/helpers/application_helper.rb
213
+ - test/dummy/app/models/postrw.rb
214
+ - test/dummy/app/models/log_other.rb
219
215
  - test/dummy/app/models/log_day.rb
220
216
  - test/dummy/app/models/log_line.rb
221
- - test/dummy/app/models/log_other.rb
222
217
  - test/dummy/app/models/post.rb
218
+ - test/dummy/app/controllers/application_controller.rb
223
219
  - test/dummy/app/views/layouts/application.html.erb
220
+ - test/dummy/app/assets/javascripts/application.js
221
+ - test/dummy/app/assets/stylesheets/application.css
222
+ - test/dummy/app/helpers/application_helper.rb
223
+ - test/dummy/test/unit/post_test.rb
224
+ - test/dummy/bin/rake
224
225
  - test/dummy/bin/bundle
225
226
  - test/dummy/bin/rails
226
- - test/dummy/bin/rake
227
- - test/dummy/config/application.rb
228
- - test/dummy/config/boot.rb
229
- - test/dummy/config/database.yml
230
- - test/dummy/config/environment.rb
231
- - test/dummy/config/environments/development.rb
227
+ - test/dummy/config/routes.rb
228
+ - test/dummy/config/locales/en.yml
232
229
  - test/dummy/config/environments/production.rb
230
+ - test/dummy/config/environments/development.rb
233
231
  - test/dummy/config/environments/test.rb
232
+ - test/dummy/config/environment.rb
233
+ - test/dummy/config/application.rb
234
+ - test/dummy/config/database.yml
235
+ - test/dummy/config/boot.rb
234
236
  - test/dummy/config/initializers/backtrace_silencers.rb
235
- - test/dummy/config/initializers/filter_parameter_logging.rb
236
- - test/dummy/config/initializers/inflections.rb
237
237
  - test/dummy/config/initializers/mime_types.rb
238
- - test/dummy/config/initializers/secret_token.rb
238
+ - test/dummy/config/initializers/filter_parameter_logging.rb
239
239
  - test/dummy/config/initializers/session_store.rb
240
240
  - test/dummy/config/initializers/wrap_parameters.rb
241
- - test/dummy/config/locales/en.yml
242
- - test/dummy/config/routes.rb
241
+ - test/dummy/config/initializers/secret_token.rb
242
+ - test/dummy/config/initializers/inflections.rb
243
243
  - test/dummy/config.ru
244
- - test/dummy/db/migrate/20140220134827_create_posts.rb
245
- - test/dummy/db/migrate/20140220140852_posts_archive.rb
246
- - test/dummy/db/migrate/20140220140952_posts_tag.rb
247
- - test/dummy/db/migrate/20140317201702_create_logs.rb
244
+ - test/dummy/script/rails
245
+ - test/dummy/Rakefile
246
+ - test/dummy/public/favicon.ico
247
+ - test/dummy/public/422.html
248
+ - test/dummy/public/500.html
249
+ - test/dummy/public/404.html
250
+ - test/dummy/db/schema.rb
248
251
  - test/dummy/db/migrate/20140414124125_create_postable_on_log_day.rb
252
+ - test/dummy/db/migrate/20190711112558_create_postrws.rb
253
+ - test/dummy/db/migrate/20140220134827_create_posts.rb
249
254
  - test/dummy/db/migrate/20161103093656_create_log_other.rb
255
+ - test/dummy/db/migrate/20140317201702_create_logs.rb
250
256
  - test/dummy/db/migrate/20161103100644_create_log_other_archive.rb
251
- - test/dummy/db/schema.rb
252
- - test/dummy/log/development.log
253
- - test/dummy/log/test.log
254
- - test/dummy/public/404.html
255
- - test/dummy/public/422.html
256
- - test/dummy/public/500.html
257
- - test/dummy/public/favicon.ico
258
- - test/dummy/Rakefile
257
+ - test/dummy/db/migrate/20140220140952_posts_tag.rb
258
+ - test/dummy/db/migrate/20140220140852_posts_archive.rb
259
259
  - test/dummy/README.rdoc
260
- - test/dummy/script/rails
261
- - test/dummy/test/unit/post_test.rb
262
260
  - test/migrations_test.rb
261
+ - test/archive_table_test.rb
263
262
  - test/test_helper.rb