diff --git a/app/logical/anonymous_user.rb b/app/logical/anonymous_user.rb index 2772b420a..9215ace0c 100644 --- a/app/logical/anonymous_user.rb +++ b/app/logical/anonymous_user.rb @@ -132,7 +132,7 @@ class AnonymousUser def decrement!(field) end - + def role :anonymous end diff --git a/app/models/note.rb b/app/models/note.rb index 7ab277a15..d7a75cea6 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -123,7 +123,8 @@ class Note < ActiveRecord::Base end def create_version - CurrentUser.increment!(:note_update_count) + CurrentUser.user.increment!(:note_update_count) + update_column(:version, version.to_i + 1) versions.create( :updater_id => updater_id, @@ -134,7 +135,8 @@ class Note < ActiveRecord::Base :width => width, :height => height, :is_active => is_active, - :body => body + :body => body, + :version => version ) end diff --git a/app/views/note_versions/index.html.erb b/app/views/note_versions/index.html.erb index ee93011bf..05efde2e2 100644 --- a/app/views/note_versions/index.html.erb +++ b/app/views/note_versions/index.html.erb @@ -22,7 +22,7 @@ <%= link_to note_version.post_id, post_path(note_version.post_id) %> - <%= link_to "#{note_version.note_id}.#{note_version.id}", note_versions_path(:search => {:note_id => note_version.note_id}) %> + <%= link_to "#{note_version.note_id}.#{note_version.version}", note_versions_path(:search => {:note_id => note_version.note_id}) %> <%= h(note_version.body) %> <% unless note_version.is_active? %>(deleted)<% end %> <% if CurrentUser.is_janitor? %> diff --git a/db/migrate/20130322173859_add_version_to_notes.rb b/db/migrate/20130322173859_add_version_to_notes.rb new file mode 100644 index 000000000..2e96bbb39 --- /dev/null +++ b/db/migrate/20130322173859_add_version_to_notes.rb @@ -0,0 +1,7 @@ +class AddVersionToNotes < ActiveRecord::Migration + def change + execute("set statement_timeout = 0") + add_column :notes, :version, :integer, :null => false, :default => 0 + add_column :note_versions, :version, :integer, :null => false, :default => 0 + end +end diff --git a/db/structure.sql b/db/structure.sql index 95e946037..1d0a27c8b 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1938,7 +1938,8 @@ CREATE TABLE note_versions ( is_active boolean DEFAULT true NOT NULL, body text NOT NULL, created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + updated_at timestamp without time zone NOT NULL, + version integer DEFAULT 0 NOT NULL ); @@ -1977,7 +1978,8 @@ CREATE TABLE notes ( body text NOT NULL, body_index tsvector NOT NULL, created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + updated_at timestamp without time zone NOT NULL, + version integer DEFAULT 0 NOT NULL ); @@ -6269,4 +6271,6 @@ INSERT INTO schema_migrations (version) VALUES ('20130321144736'); INSERT INTO schema_migrations (version) VALUES ('20130322162059'); -INSERT INTO schema_migrations (version) VALUES ('20130322173202'); \ No newline at end of file +INSERT INTO schema_migrations (version) VALUES ('20130322173202'); + +INSERT INTO schema_migrations (version) VALUES ('20130322173859'); \ No newline at end of file diff --git a/script/fixes/009.rb b/script/fixes/009.rb index 46ee0767e..235d24401 100644 --- a/script/fixes/009.rb +++ b/script/fixes/009.rb @@ -5,3 +5,13 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', ActiveRecord::Base.connection.execute("set statement_timeout = 0") ActiveRecord::Base.connection.execute("update wiki_pages set updater_id = (select _.updater_id from wiki_page_versions _ where _.wiki_page_id = wiki_pages.id order by _.updated_at desc limit 1)") + +Note.find_each do |note| + i = 0 + versions = note.versions + versions.each do |version| + i += 1 + version.update_column(:version, i) + end + note.update_column(:version, i) +end