paper_trail 3.0.6 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.rspec +1 -2
  4. data/.travis.yml +14 -5
  5. data/CHANGELOG.md +215 -8
  6. data/CONTRIBUTING.md +84 -0
  7. data/README.md +922 -502
  8. data/Rakefile +2 -2
  9. data/doc/bug_report_template.rb +65 -0
  10. data/gemfiles/ar3.gemfile +61 -0
  11. data/lib/generators/paper_trail/install_generator.rb +22 -3
  12. data/lib/generators/paper_trail/templates/add_object_changes_to_versions.rb +6 -1
  13. data/lib/generators/paper_trail/templates/add_transaction_id_column_to_versions.rb +11 -0
  14. data/lib/generators/paper_trail/templates/create_version_associations.rb +17 -0
  15. data/lib/generators/paper_trail/templates/create_versions.rb +22 -1
  16. data/lib/paper_trail.rb +52 -22
  17. data/lib/paper_trail/attributes_serialization.rb +89 -0
  18. data/lib/paper_trail/cleaner.rb +32 -15
  19. data/lib/paper_trail/config.rb +35 -2
  20. data/lib/paper_trail/frameworks/active_record.rb +4 -5
  21. data/lib/paper_trail/frameworks/active_record/models/paper_trail/version_association.rb +7 -0
  22. data/lib/paper_trail/frameworks/rails.rb +1 -0
  23. data/lib/paper_trail/frameworks/rails/controller.rb +27 -11
  24. data/lib/paper_trail/frameworks/rspec.rb +5 -0
  25. data/lib/paper_trail/frameworks/sinatra.rb +3 -1
  26. data/lib/paper_trail/has_paper_trail.rb +304 -148
  27. data/lib/paper_trail/record_history.rb +59 -0
  28. data/lib/paper_trail/reifier.rb +270 -0
  29. data/lib/paper_trail/serializers/json.rb +13 -2
  30. data/lib/paper_trail/serializers/yaml.rb +16 -2
  31. data/lib/paper_trail/version_association_concern.rb +15 -0
  32. data/lib/paper_trail/version_concern.rb +160 -122
  33. data/lib/paper_trail/version_number.rb +3 -3
  34. data/paper_trail.gemspec +22 -9
  35. data/spec/generators/install_generator_spec.rb +4 -4
  36. data/spec/models/animal_spec.rb +36 -0
  37. data/spec/models/boolit_spec.rb +48 -0
  38. data/spec/models/callback_modifier_spec.rb +96 -0
  39. data/spec/models/fluxor_spec.rb +19 -0
  40. data/spec/models/gadget_spec.rb +14 -12
  41. data/spec/models/joined_version_spec.rb +9 -9
  42. data/spec/models/json_version_spec.rb +103 -0
  43. data/spec/models/kitchen/banana_spec.rb +14 -0
  44. data/spec/models/not_on_update_spec.rb +19 -0
  45. data/spec/models/post_with_status_spec.rb +3 -3
  46. data/spec/models/skipper_spec.rb +46 -0
  47. data/spec/models/thing_spec.rb +11 -0
  48. data/spec/models/version_spec.rb +195 -44
  49. data/spec/models/widget_spec.rb +136 -76
  50. data/spec/modules/paper_trail_spec.rb +27 -0
  51. data/spec/modules/version_concern_spec.rb +8 -8
  52. data/spec/modules/version_number_spec.rb +16 -16
  53. data/spec/paper_trail/config_spec.rb +52 -0
  54. data/spec/paper_trail_spec.rb +17 -17
  55. data/spec/rails_helper.rb +34 -0
  56. data/spec/requests/articles_spec.rb +10 -14
  57. data/spec/spec_helper.rb +81 -34
  58. data/spec/support/alt_db_init.rb +1 -1
  59. data/test/dummy/app/controllers/application_controller.rb +1 -1
  60. data/test/dummy/app/controllers/articles_controller.rb +4 -1
  61. data/test/dummy/app/models/animal.rb +2 -0
  62. data/test/dummy/app/models/book.rb +4 -0
  63. data/test/dummy/app/models/boolit.rb +4 -0
  64. data/test/dummy/app/models/callback_modifier.rb +45 -0
  65. data/test/dummy/app/models/chapter.rb +9 -0
  66. data/test/dummy/app/models/citation.rb +5 -0
  67. data/test/dummy/app/models/customer.rb +4 -0
  68. data/test/dummy/app/models/editor.rb +4 -0
  69. data/test/dummy/app/models/editorship.rb +5 -0
  70. data/test/dummy/app/models/fruit.rb +5 -0
  71. data/test/dummy/app/models/kitchen/banana.rb +5 -0
  72. data/test/dummy/app/models/line_item.rb +4 -0
  73. data/test/dummy/app/models/not_on_update.rb +4 -0
  74. data/test/dummy/app/models/order.rb +5 -0
  75. data/test/dummy/app/models/paragraph.rb +5 -0
  76. data/test/dummy/app/models/person.rb +13 -3
  77. data/test/dummy/app/models/post.rb +0 -1
  78. data/test/dummy/app/models/quotation.rb +5 -0
  79. data/test/dummy/app/models/section.rb +6 -0
  80. data/test/dummy/app/models/skipper.rb +6 -0
  81. data/test/dummy/app/models/song.rb +20 -0
  82. data/test/dummy/app/models/thing.rb +3 -0
  83. data/test/dummy/app/models/whatchamajigger.rb +4 -0
  84. data/test/dummy/app/models/widget.rb +5 -0
  85. data/test/dummy/app/versions/json_version.rb +3 -0
  86. data/test/dummy/app/versions/kitchen/banana_version.rb +5 -0
  87. data/test/dummy/config/application.rb +6 -0
  88. data/test/dummy/config/database.postgres.yml +1 -1
  89. data/test/dummy/config/environments/test.rb +5 -1
  90. data/test/dummy/config/initializers/paper_trail.rb +6 -1
  91. data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +143 -3
  92. data/test/dummy/db/schema.rb +169 -25
  93. data/test/functional/controller_test.rb +4 -2
  94. data/test/functional/modular_sinatra_test.rb +1 -1
  95. data/test/functional/sinatra_test.rb +1 -1
  96. data/test/paper_trail_test.rb +7 -0
  97. data/test/test_helper.rb +38 -2
  98. data/test/time_travel_helper.rb +15 -0
  99. data/test/unit/associations_test.rb +726 -0
  100. data/test/unit/inheritance_column_test.rb +6 -6
  101. data/test/unit/model_test.rb +109 -125
  102. data/test/unit/protected_attrs_test.rb +4 -3
  103. data/test/unit/serializer_test.rb +6 -6
  104. data/test/unit/serializers/json_test.rb +17 -4
  105. data/test/unit/serializers/yaml_test.rb +5 -1
  106. data/test/unit/version_test.rb +87 -69
  107. metadata +172 -75
  108. data/gemfiles/3.0.gemfile +0 -42
  109. data/test/dummy/public/404.html +0 -26
  110. data/test/dummy/public/422.html +0 -26
  111. data/test/dummy/public/500.html +0 -26
  112. data/test/dummy/public/favicon.ico +0 -0
  113. data/test/dummy/public/javascripts/application.js +0 -2
  114. data/test/dummy/public/javascripts/controls.js +0 -965
  115. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  116. data/test/dummy/public/javascripts/effects.js +0 -1123
  117. data/test/dummy/public/javascripts/prototype.js +0 -6001
  118. data/test/dummy/public/javascripts/rails.js +0 -175
  119. data/test/dummy/public/stylesheets/.gitkeep +0 -0
@@ -9,7 +9,7 @@ configs = YAML.load_file("#{Rails.root}/config/database.yml")
9
9
  db_directory = "#{Rails.root}/db"
10
10
  # setup alternate databases
11
11
  if ENV["DB"] == "sqlite"
12
- if RUBY_VERSION.to_f >= 1.9
12
+ if RUBY_VERSION >= '1.9'
13
13
  FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-foo.sqlite3"
14
14
  FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-bar.sqlite3"
15
15
  else
@@ -9,7 +9,7 @@ class ApplicationController < ActionController::Base
9
9
  def current_user
10
10
  @current_user ||= OpenStruct.new(:id => 153).tap do |obj|
11
11
  # Invoking `id` returns the `object_id` value in Ruby18 unless specifically overwritten
12
- def obj.id; 153; end if RUBY_VERSION.to_f < 1.9
12
+ def obj.id; 153; end if RUBY_VERSION < '1.9'
13
13
  end
14
14
  end
15
15
 
@@ -9,6 +9,9 @@ class ArticlesController < ApplicationController
9
9
  end
10
10
 
11
11
  def current_user
12
- 'foobar'
12
+ 'foobar'.tap do |string|
13
+ # Invoking `id` returns the `object_id` value in Ruby18 by default
14
+ string.class_eval { undef_method(:id) } if RUBY_VERSION < '1.9'
15
+ end
13
16
  end
14
17
  end
@@ -1,4 +1,6 @@
1
1
  class Animal < ActiveRecord::Base
2
2
  has_paper_trail
3
3
  self.inheritance_column = 'species'
4
+
5
+ attr_accessible :species, :name if ::PaperTrail.active_record_protected_attributes?
4
6
  end
@@ -1,5 +1,9 @@
1
1
  class Book < ActiveRecord::Base
2
2
  has_many :authorships, :dependent => :destroy
3
3
  has_many :authors, :through => :authorships, :source => :person
4
+
5
+ has_many :editorships, :dependent => :destroy
6
+ has_many :editors, :through => :editorships
7
+
4
8
  has_paper_trail
5
9
  end
@@ -0,0 +1,4 @@
1
+ class Boolit < ActiveRecord::Base
2
+ default_scope { where(:scoped => true) }
3
+ has_paper_trail
4
+ end
@@ -0,0 +1,45 @@
1
+ class CallbackModifier < ActiveRecord::Base
2
+ has_paper_trail :on => []
3
+
4
+ def test_destroy
5
+ transaction do
6
+ run_callbacks(:destroy) do
7
+ self.deleted = true
8
+ save!
9
+ end
10
+ end
11
+ end
12
+
13
+ def flagged_deleted?
14
+ deleted?
15
+ end
16
+ end
17
+
18
+ class BeforeDestroyModifier < CallbackModifier
19
+ has_paper_trail :on => []
20
+ paper_trail_on_destroy :before
21
+ end
22
+
23
+ class AfterDestroyModifier < CallbackModifier
24
+ has_paper_trail :on => []
25
+ paper_trail_on_destroy :after
26
+ end
27
+
28
+ class NoArgDestroyModifier < CallbackModifier
29
+ has_paper_trail :on => []
30
+ paper_trail_on_destroy
31
+ end
32
+
33
+ class UpdateModifier < CallbackModifier
34
+ has_paper_trail :on => []
35
+ paper_trail_on_update
36
+ end
37
+
38
+ class CreateModifier < CallbackModifier
39
+ has_paper_trail :on => []
40
+ paper_trail_on_create
41
+ end
42
+
43
+ class DefaultModifier < CallbackModifier
44
+ has_paper_trail
45
+ end
@@ -0,0 +1,9 @@
1
+ class Chapter < ActiveRecord::Base
2
+ has_many :sections, :dependent => :destroy
3
+ has_many :paragraphs, :through => :sections
4
+
5
+ has_many :quotations, :dependent => :destroy
6
+ has_many :citations, :through => :quotations
7
+
8
+ has_paper_trail
9
+ end
@@ -0,0 +1,5 @@
1
+ class Citation < ActiveRecord::Base
2
+ belongs_to :quotation
3
+
4
+ has_paper_trail
5
+ end
@@ -0,0 +1,4 @@
1
+ class Customer < ActiveRecord::Base
2
+ has_many :orders, :dependent => :destroy
3
+ has_paper_trail
4
+ end
@@ -0,0 +1,4 @@
1
+ # to demonstrate a has_through association that does not have paper_trail enabled
2
+ class Editor < ActiveRecord::Base
3
+ has_many :editorships, :dependent => :destroy
4
+ end
@@ -0,0 +1,5 @@
1
+ class Editorship < ActiveRecord::Base
2
+ belongs_to :book
3
+ belongs_to :editor
4
+ has_paper_trail
5
+ end
@@ -0,0 +1,5 @@
1
+ class Fruit < ActiveRecord::Base
2
+ if ENV['DB'] == 'postgres' || JsonVersion.table_exists?
3
+ has_paper_trail :class_name => 'JsonVersion'
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Kitchen
2
+ class Banana < ActiveRecord::Base
3
+ has_paper_trail :class_name => "Kitchen::BananaVersion"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ class LineItem < ActiveRecord::Base
2
+ belongs_to :order, :dependent => :destroy
3
+ has_paper_trail
4
+ end
@@ -0,0 +1,4 @@
1
+ # This model does not record versions when updated.
2
+ class NotOnUpdate < ActiveRecord::Base
3
+ has_paper_trail :on => [:create, :destroy]
4
+ end
@@ -0,0 +1,5 @@
1
+ class Order < ActiveRecord::Base
2
+ belongs_to :customer
3
+ has_many :line_items
4
+ has_paper_trail
5
+ end
@@ -0,0 +1,5 @@
1
+ class Paragraph < ActiveRecord::Base
2
+ belongs_to :section
3
+
4
+ has_paper_trail
5
+ end
@@ -15,12 +15,22 @@ class Person < ActiveRecord::Base
15
15
 
16
16
  # Store TimeZone objects as strings when serialized to database
17
17
  class TimeZoneSerializer
18
+ class << self
19
+ def dump(zone)
20
+ zone.try(:name)
21
+ end
22
+
23
+ def load(value)
24
+ ::Time.find_zone!(value) rescue nil
25
+ end
26
+ end
27
+
18
28
  def dump(zone)
19
- zone.try(:name)
29
+ self.class.dump(zone)
20
30
  end
21
-
31
+
22
32
  def load(value)
23
- ::Time.find_zone!(value) rescue nil
33
+ self.class.load(value)
24
34
  end
25
35
  end
26
36
 
@@ -1,4 +1,3 @@
1
1
  class Post < ActiveRecord::Base
2
2
  has_paper_trail :class_name => "PostVersion"
3
-
4
3
  end
@@ -0,0 +1,5 @@
1
+ class Quotation < ActiveRecord::Base
2
+ belongs_to :chapter
3
+ has_many :citations, :dependent => :destroy
4
+ has_paper_trail
5
+ end
@@ -0,0 +1,6 @@
1
+ class Section < ActiveRecord::Base
2
+ belongs_to :chapter
3
+ has_many :paragraphs, :dependent => :destroy
4
+
5
+ has_paper_trail
6
+ end
@@ -0,0 +1,6 @@
1
+ class Skipper < ActiveRecord::Base
2
+ has_paper_trail(
3
+ :ignore => [:created_at],
4
+ :skip => [:another_timestamp]
5
+ )
6
+ end
@@ -1,6 +1,7 @@
1
1
  # Example from 'Overwriting default accessors' in ActiveRecord::Base.
2
2
  class Song < ActiveRecord::Base
3
3
  has_paper_trail
4
+ attr_accessor :name
4
5
 
5
6
  # Uses an integer of seconds to hold the length of the song
6
7
  def length=(minutes)
@@ -9,4 +10,23 @@ class Song < ActiveRecord::Base
9
10
  def length
10
11
  read_attribute(:length) / 60
11
12
  end
13
+
14
+ # override attributes hashes like some libraries do
15
+ def attributes_with_name
16
+ if name
17
+ attributes_without_name.merge(:name => name)
18
+ else
19
+ attributes_without_name
20
+ end
21
+ end
22
+ alias_method_chain :attributes, :name
23
+
24
+ def changed_attributes_with_name
25
+ if name
26
+ changed_attributes_without_name.merge(:name => name)
27
+ else
28
+ changed_attributes_without_name
29
+ end
30
+ end
31
+ alias_method_chain :changed_attributes, :name
12
32
  end
@@ -0,0 +1,3 @@
1
+ class Thing < ActiveRecord::Base
2
+ has_paper_trail :save_changes => false
3
+ end
@@ -0,0 +1,4 @@
1
+ class Whatchamajigger < ActiveRecord::Base
2
+ has_paper_trail
3
+ belongs_to :owner, :polymorphic => true
4
+ end
@@ -1,6 +1,11 @@
1
1
  class Widget < ActiveRecord::Base
2
2
  has_paper_trail
3
3
  has_one :wotsit
4
+ has_many :whatchamajiggers, :as => :owner
5
+
6
+ EXCLUDED_NAME = 'Biglet'
7
+
8
+ validates :name, :exclusion => { :in => [EXCLUDED_NAME] }
4
9
 
5
10
  if ::ActiveRecord::VERSION::MAJOR >= 4 # `has_many` syntax for specifying order uses a lambda in Rails 4
6
11
  has_many :fluxors, lambda { order(:name) }
@@ -0,0 +1,3 @@
1
+ class JsonVersion < PaperTrail::Version
2
+ self.table_name = 'json_versions'
3
+ end
@@ -0,0 +1,5 @@
1
+ module Kitchen
2
+ class BananaVersion < PaperTrail::Version
3
+ self.table_name = 'banana_versions'
4
+ end
5
+ end
@@ -59,5 +59,11 @@ module Dummy
59
59
 
60
60
  # Rails 4 key for generating secret key
61
61
  config.secret_key_base = 'A fox regularly kicked the screaming pile of biscuits.'
62
+
63
+ # supress warnings about raises in transactional callbacks on AR 4.2+
64
+ config.active_record.raise_in_transactional_callbacks = true if ActiveRecord::VERSION::STRING >= '4.2'
65
+
66
+ # Set test order for Test::Unit if possible
67
+ config.active_support.test_order = :sorted if config.active_support.respond_to?(:test_order=)
62
68
  end
63
69
  end
@@ -12,4 +12,4 @@ foo:
12
12
 
13
13
  bar:
14
14
  <<: *test
15
- database: paper_trail_bar
15
+ database: paper_trail_bar
@@ -11,7 +11,11 @@ Dummy::Application.configure do
11
11
  config.eager_load = true
12
12
 
13
13
  # Configure static asset server for tests with Cache-Control for performance
14
- config.serve_static_assets = true
14
+ if config.respond_to?(:serve_static_files=)
15
+ config.serve_static_files = true
16
+ else
17
+ config.serve_static_assets = true
18
+ end
15
19
  config.static_cache_control = "public, max-age=3600"
16
20
 
17
21
  # Show full error reports and disable caching
@@ -1,5 +1,10 @@
1
+ # Turn on associations tracking when the test suite is run on Travis CI
2
+ PaperTrail.config.track_associations = true if ENV['TRAVIS']
3
+
1
4
  module PaperTrail
2
5
  class Version < ActiveRecord::Base
3
- attr_accessible :created_at, :updated_at, :answer, :action, :question, :article_id, :ip, :user_agent, :title if ::PaperTrail.active_record_protected_attributes?
6
+ if ::PaperTrail.active_record_protected_attributes?
7
+ attr_accessible :answer, :action, :question, :article_id, :ip, :user_agent, :title
8
+ end
4
9
  end
5
10
  end
@@ -1,5 +1,11 @@
1
1
  class SetUpTestTables < ActiveRecord::Migration
2
2
  def self.up
3
+ create_table :skippers, :force => true do |t|
4
+ t.string :name
5
+ t.datetime :another_timestamp
6
+ t.timestamps :null => true
7
+ end
8
+
3
9
  create_table :widgets, :force => true do |t|
4
10
  t.string :name
5
11
  t.text :a_text
@@ -12,7 +18,7 @@ class SetUpTestTables < ActiveRecord::Migration
12
18
  t.boolean :a_boolean
13
19
  t.string :sacrificial_column
14
20
  t.string :type
15
- t.timestamps
21
+ t.timestamps :null => true
16
22
  end
17
23
 
18
24
  create_table :versions, :force => true do |t|
@@ -22,6 +28,7 @@ class SetUpTestTables < ActiveRecord::Migration
22
28
  t.string :whodunnit
23
29
  t.text :object
24
30
  t.text :object_changes
31
+ t.integer :transaction_id
25
32
  t.datetime :created_at
26
33
 
27
34
  # Metadata columns.
@@ -37,6 +44,14 @@ class SetUpTestTables < ActiveRecord::Migration
37
44
  end
38
45
  add_index :versions, [:item_type, :item_id]
39
46
 
47
+ create_table :version_associations do |t|
48
+ t.integer :version_id
49
+ t.string :foreign_key_name, :null => false
50
+ t.integer :foreign_key_id
51
+ end
52
+ add_index :version_associations, [:version_id]
53
+ add_index :version_associations, [:foreign_key_name, :foreign_key_id], :name => 'index_version_associations_on_foreign_key'
54
+
40
55
  create_table :post_versions, :force => true do |t|
41
56
  t.string :item_type, :null => false
42
57
  t.integer :item_id, :null => false
@@ -51,10 +66,41 @@ class SetUpTestTables < ActiveRecord::Migration
51
66
  end
52
67
  add_index :post_versions, [:item_type, :item_id]
53
68
 
69
+ if ENV['DB'] == 'postgres' && ::ActiveRecord::VERSION::MAJOR >= 4
70
+ create_table :json_versions, :force => true do |t|
71
+ t.string :item_type, :null => false
72
+ t.integer :item_id, :null => false
73
+ t.string :event, :null => false
74
+ t.string :whodunnit
75
+ t.json :object
76
+ t.json :object_changes
77
+ t.datetime :created_at
78
+ end
79
+ add_index :json_versions, [:item_type, :item_id]
80
+ end
81
+
82
+ create_table :not_on_updates, :force => true do |t|
83
+ t.timestamps :null => true
84
+ end
85
+
86
+ create_table :bananas, :force => true do |t|
87
+ t.timestamps :null => true
88
+ end
89
+
90
+ create_table :banana_versions, :force => true do |t|
91
+ t.string :item_type, :null => false
92
+ t.integer :item_id, :null => false
93
+ t.string :event, :null => false
94
+ t.string :whodunnit
95
+ t.text :object
96
+ t.datetime :created_at
97
+ end
98
+ add_index :banana_versions, [:item_type, :item_id]
99
+
54
100
  create_table :wotsits, :force => true do |t|
55
101
  t.integer :widget_id
56
102
  t.string :name
57
- t.timestamps
103
+ t.timestamps :null => true
58
104
  end
59
105
 
60
106
  create_table :fluxors, :force => true do |t|
@@ -62,6 +108,12 @@ class SetUpTestTables < ActiveRecord::Migration
62
108
  t.string :name
63
109
  end
64
110
 
111
+ create_table :whatchamajiggers, :force => true do |t|
112
+ t.string :owner_type
113
+ t.integer :owner_id
114
+ t.string :name
115
+ end
116
+
65
117
  create_table :articles, :force => true do |t|
66
118
  t.string :title
67
119
  t.string :content
@@ -83,6 +135,15 @@ class SetUpTestTables < ActiveRecord::Migration
83
135
  t.string :time_zone
84
136
  end
85
137
 
138
+ create_table :editorships, :force => true do |t|
139
+ t.integer :book_id
140
+ t.integer :editor_id
141
+ end
142
+
143
+ create_table :editors, :force => true do |t|
144
+ t.string :name
145
+ end
146
+
86
147
  create_table :songs, :force => true do |t|
87
148
  t.integer :length
88
149
  end
@@ -110,6 +171,10 @@ class SetUpTestTables < ActiveRecord::Migration
110
171
  t.integer :version
111
172
  end
112
173
 
174
+ create_table :things, :force => true do |t|
175
+ t.string :name
176
+ end
177
+
113
178
  create_table :translations, :force => true do |t|
114
179
  t.string :headline
115
180
  t.string :content
@@ -120,28 +185,103 @@ class SetUpTestTables < ActiveRecord::Migration
120
185
  create_table :gadgets, :force => true do |t|
121
186
  t.string :name
122
187
  t.string :brand
123
- t.timestamps
188
+ t.timestamps :null => true
189
+ end
190
+
191
+ create_table :customers, :force => true do |t|
192
+ t.string :name
193
+ end
194
+
195
+ create_table :orders, :force => true do |t|
196
+ t.integer :customer_id
197
+ t.string :order_date
198
+ end
199
+
200
+ create_table :line_items, :force => true do |t|
201
+ t.integer :order_id
202
+ t.string :product
203
+ end
204
+
205
+ create_table :fruits, :force => true do |t|
206
+ t.string :name
207
+ t.string :color
208
+ end
209
+
210
+ create_table :boolits, :force => true do |t|
211
+ t.string :name
212
+ t.boolean :scoped, :default => true
213
+ end
214
+
215
+ create_table :callback_modifiers, :force => true do |t|
216
+ t.string :some_content
217
+ t.boolean :deleted, :default => false
218
+ end
219
+
220
+ create_table :chapters, :force => true do |t|
221
+ t.string :name
222
+ end
223
+
224
+ create_table :sections, :force => true do |t|
225
+ t.integer :chapter_id
226
+ t.string :name
227
+ end
228
+
229
+ create_table :paragraphs, :force => true do |t|
230
+ t.integer :section_id
231
+ t.string :name
232
+ end
233
+
234
+ create_table :quotations, :force => true do |t|
235
+ t.integer :chapter_id
236
+ end
237
+
238
+ create_table :citations, :force => true do |t|
239
+ t.integer :quotation_id
124
240
  end
125
241
  end
126
242
 
127
243
  def self.down
244
+ drop_table :citations
245
+ drop_table :quotations
128
246
  drop_table :animals
247
+ drop_table :skippers
248
+ drop_table :not_on_updates
129
249
  drop_table :posts
130
250
  drop_table :songs
251
+ drop_table :editors
252
+ drop_table :editorships
131
253
  drop_table :people
132
254
  drop_table :authorships
133
255
  drop_table :books
134
256
  drop_table :articles
257
+ drop_table :whatchamajiggers
135
258
  drop_table :fluxors
136
259
  drop_table :wotsits
137
260
  remove_index :post_versions, :column => [:item_type, :item_id]
138
261
  drop_table :post_versions
139
262
  remove_index :versions, :column => [:item_type, :item_id]
140
263
  drop_table :versions
264
+ if JsonVersion.table_exists?
265
+ remove_index :json_versions, :column => [:item_type, :item_id]
266
+ drop_table :json_versions
267
+ end
141
268
  drop_table :widgets
142
269
  drop_table :documents
143
270
  drop_table :legacy_widgets
271
+ drop_table :things
144
272
  drop_table :translations
145
273
  drop_table :gadgets
274
+ drop_table :customers
275
+ drop_table :orders
276
+ drop_table :line_items
277
+ drop_table :fruits
278
+ drop_table :boolits
279
+ drop_table :chapters
280
+ drop_table :sections
281
+ drop_table :paragraphs
282
+ remove_index :version_associations, :column => [:version_id]
283
+ remove_index :version_associations, :name => 'index_version_associations_on_foreign_key'
284
+ drop_table :version_associations
285
+ drop_table :callback_modifiers
146
286
  end
147
287
  end