changeset 542:23a9272bf766 feature_36

Feature #237: migration, new table with BibtexEntry Types and rake task to populate the table.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 28 Jul 2011 19:21:57 +0100
parents c3abeb11bc2e
children 85dd79181088
files vendor/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb vendor/plugins/redmine_bibliography/db/migrate/004_create_bibtex_entries.rb vendor/plugins/redmine_bibliography/db/migrate/006_create_bibtex_entry_types.rb vendor/plugins/redmine_bibliography/db/seed_data/bibtex_entry_types_list.txt vendor/plugins/redmine_bibliography/lib/tasks/seed_bibtex_entry_types.rake
diffstat 5 files changed, 51 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb	Thu Jul 28 19:21:57 2011 +0100
@@ -0,0 +1,2 @@
+class BibtexEntryType < ActiveRecord::Base
+end
--- a/vendor/plugins/redmine_bibliography/db/migrate/004_create_bibtex_entries.rb	Thu Jul 28 15:04:24 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/db/migrate/004_create_bibtex_entries.rb	Thu Jul 28 19:21:57 2011 +0100
@@ -2,7 +2,7 @@
   def self.up
     create_table :bibtex_entries do |t|
       t.column :publication_id, :integer
-      t.column :entry_type, :string
+      t.column :entry_type, :integer
       t.column :address, :string
       t.column :annote, :string
       t.column :booktitle, :string
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/db/migrate/006_create_bibtex_entry_types.rb	Thu Jul 28 19:21:57 2011 +0100
@@ -0,0 +1,13 @@
+class CreateBibtexEntryTypes < ActiveRecord::Migration
+  def self.up
+    create_table :bibtex_entry_types do |t|
+      t.string :name
+
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :bibtex_entry_types
+  end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/db/seed_data/bibtex_entry_types_list.txt	Thu Jul 28 19:21:57 2011 +0100
@@ -0,0 +1,14 @@
+article|1
+book|2
+booklet|3
+inbook|4
+incollection|5
+conference|6
+inproceedings|7
+manual|8
+masterthesis|9
+misc|10
+phdthesis|11
+proceedings|12
+techreport|13
+unpublished|14
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/lib/tasks/seed_bibtex_entry_types.rake	Thu Jul 28 19:21:57 2011 +0100
@@ -0,0 +1,21 @@
+namespace :redmine do
+  namespace :plugins do
+    namespace :redmine_bibliography do
+
+      task :seed_bibtex_entry_types  => :environment do    
+        desc "Seeds the Bibtex Entry Types Table"
+  
+        quoted = ActiveRecord::Base.connection.quote_table_name('bibtex_entry_types')
+        ActiveRecord::Base.connection.execute("TRUNCATE #{quoted}")
+
+        open(File.dirname(__FILE__) + "/../../db/seed_data/bibtex_entry_types_list.txt") do |bibtex_entry_types|
+          bibtex_entry_types.read.each_line do |bibtex_entry_type|
+            bibtype=bibtex_entry_type.split('|')
+            BibtexEntryType.create(:name => bibtype[0].chomp, :id => bibtype[1].chomp)
+          end
+        end
+      end 
+
+    end 
+  end
+end