diff --git a/lib/generators/sufia/sufia_generator.rb b/lib/generators/sufia/sufia_generator.rb index a9dfe2d0a8..bdba769c7e 100644 --- a/lib/generators/sufia/sufia_generator.rb +++ b/lib/generators/sufia/sufia_generator.rb @@ -1,85 +1,46 @@ # -*- encoding : utf-8 -*- require 'rails/generators' -require 'rails/generators/migration' +require 'rails/generators/migration' class SufiaGenerator < Rails::Generators::Base include Rails::Generators::Migration source_root File.expand_path('../templates', __FILE__) - + argument :model_name, :type => :string , :default => "user" desc """ This generator makes the following changes to your application: - 1. Creates several database migrations if they do not exist in /db/migrate - 2. Adds user behavior to the user model - 3. Adds controller behavior to the application controller - 4. Creates the sufia.rb configuration file - 5. Copies the catalog controller into the local app - 6. Adds Sufia::SolrDocumentBehavior to app/models/solr_document.rb - 7. Generates mailboxer - """ - - # Implement the required interface for Rails::Generators::Migration. - # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb - def self.next_migration_number(path) - unless @prev_migration_nr - @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i - else - @prev_migration_nr += 1 - end - @prev_migration_nr.to_s - end + 1. Runs sufia-models:install + 2. Adds controller behavior to the application controller + 3. Copies the catalog controller into the local app + """ - # Setup the database migrations - def copy_migrations - # Can't get this any more DRY, because we need this order. - %w{acts_as_follower_migration.rb add_social_to_users.rb create_single_use_links.rb add_ldap_attrs_to_user.rb -add_avatars_to_users.rb create_checksum_audit_logs.rb create_version_committers.rb -add_groups_to_users.rb create_local_authorities.rb create_trophies.rb}.each do |f| - better_migration_template f - end - end - - # Add behaviors to the user model - def inject_sufia_user_behavior - file_path = "app/models/#{model_name.underscore}.rb" - if File.exists?(file_path) - inject_into_class file_path, model_name.classify do - "# Connects this user object to Sufia behaviors. " + - "\n include Sufia::User\n" - end - else - puts " \e[31mFailure\e[0m Sufia requires a user object. This generators assumes that the model is defined in the file #{file_path}, which does not exist. If you used a different name, please re-run the generator and provide that name as an argument. Such as \b rails -g sufia client" - end + def run_required_generators + generate "blacklight --devise" + generate "hydra:head -f" + generate "sufia:models:install" end # Add behaviors to the application controller - def inject_sufia_controller_behavior + def inject_sufia_controller_behavior controller_name = "ApplicationController" file_path = "app/controllers/application_controller.rb" - if File.exists?(file_path) - insert_into_file file_path, :after => 'include Blacklight::Controller' do - " \n# Adds Sufia behaviors into the application controller \n" + + if File.exists?(file_path) + insert_into_file file_path, :after => 'include Blacklight::Controller' do + " \n# Adds Sufia behaviors into the application controller \n" + " include Sufia::Controller\n" end gsub_file file_path, "layout 'blacklight'", "layout :search_layout" else - puts " \e[31mFailure\e[0m Could not find #{file_path}. To add Sufia behaviors to your Controllers, you must include the Sufia::Controller module in the Controller class definition." + puts " \e[31mFailure\e[0m Could not find #{file_path}. To add Sufia behaviors to your Controllers, you must include the Sufia::Controller module in the Controller class definition." end end - - def create_configuration_files - copy_file "config/sufia.rb", "config/initializers/sufia.rb" - copy_file "config/redis.yml", "config/redis.yml" - copy_file "config/redis_config.rb", "config/initializers/redis_config.rb" - copy_file "config/resque_admin.rb", "config/initializers/resque_admin.rb" - copy_file "config/resque_config.rb", "config/initializers/resque_config.rb" - end + def catalog_controller copy_file "catalog_controller.rb", "app/controllers/catalog_controller.rb" end - + # The engine routes have to come after the devise routes so that /users/sign_in will work def inject_routes @@ -92,37 +53,9 @@ def inject_routes mount Sufia::Engine => '/'\n" sentinel = /devise_for :users/ inject_into_file 'config/routes.rb', routing_code, { :after => sentinel, :verbose => false } - - end - - # Add behaviors to the SolrDocument model - def inject_sufia_solr_document_behavior - file_path = "app/models/solr_document.rb" - if File.exists?(file_path) - inject_into_class file_path, "SolrDocument" do - " # Adds Sufia behaviors to the SolrDocument.\n" + - " include Sufia::SolrDocumentBehavior\n" - end - else - puts " \e[31mFailure\e[0m Sufia requires a SolrDocument object. This generators assumes that the model is defined in the file #{file_path}, which does not exist." - end - end - def install_mailboxer - generate "mailboxer:install" - end - - private - - def better_migration_template (file) - begin - migration_template "migrations/#{file}", "db/migrate/#{file}" - sleep 1 # ensure scripts have different time stamps - rescue - puts " \e[1m\e[34mMigrations\e[0m " + $!.message - end end -end +end diff --git a/lib/generators/sufia/templates/config/clamav.rb b/lib/generators/sufia/templates/config/clamav.rb deleted file mode 100644 index 7e6c2e948b..0000000000 --- a/lib/generators/sufia/templates/config/clamav.rb +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright © 2012 The Pennsylvania State University -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -ClamAV.instance.loaddb() if defined? ClamAV diff --git a/lib/generators/sufia/templates/config/mailboxer.rb b/lib/generators/sufia/templates/config/mailboxer.rb deleted file mode 100644 index ac7c5ef961..0000000000 --- a/lib/generators/sufia/templates/config/mailboxer.rb +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright © 2012 The Pennsylvania State University -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -Mailboxer.setup do |config| - - #Configures if you applications uses or no the email sending for Notifications and Messages - config.uses_emails = true - - #Configures the default from for the email sent for Messages and Notifications of Mailboxer - config.default_from = "no-reply@mailboxer.com" - - #Configures the methods needed by mailboxer - config.email_method = :mailboxer_email - config.name_method = :name - - #Configures if you use or not a search engine and wich one are you using - #Supported enignes: [:solr,:sphinx] - config.search_enabled = false - config.search_engine = :solr -end diff --git a/lib/generators/sufia/templates/config/setup_mail.rb b/lib/generators/sufia/templates/config/setup_mail.rb deleted file mode 100644 index 7fe216605d..0000000000 --- a/lib/generators/sufia/templates/config/setup_mail.rb +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright © 2012 The Pennsylvania State University -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -ActionMailer::Base.smtp_settings = { - :address => "smtp.psu.edu" -} diff --git a/lib/generators/sufia/templates/config/sufia.rb b/lib/generators/sufia/templates/config/sufia.rb deleted file mode 100644 index c62dea47d8..0000000000 --- a/lib/generators/sufia/templates/config/sufia.rb +++ /dev/null @@ -1,82 +0,0 @@ -# Returns an array containing the vhost 'CoSign service' value and URL -Sufia.config do |config| - - config.fits_to_desc_mapping= { - :file_title => :title, - :file_author => :creator - } - - # Specify a different template for your repositories unique identifiers - # config.noid_template = ".reeddeeddk" - - config.max_days_between_audits = 7 - - config.cc_licenses = { - 'Attribution 3.0 United States' => 'http://creativecommons.org/licenses/by/3.0/us/', - 'Attribution-ShareAlike 3.0 United States' => 'http://creativecommons.org/licenses/by-sa/3.0/us/', - 'Attribution-NonCommercial 3.0 United States' => 'http://creativecommons.org/licenses/by-nc/3.0/us/', - 'Attribution-NoDerivs 3.0 United States' => 'http://creativecommons.org/licenses/by-nd/3.0/us/', - 'Attribution-NonCommercial-NoDerivs 3.0 United States' => 'http://creativecommons.org/licenses/by-nc-nd/3.0/us/', - 'Attribution-NonCommercial-ShareAlike 3.0 United States' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/us/', - 'Public Domain Mark 1.0' => 'http://creativecommons.org/publicdomain/mark/1.0/', - 'CC0 1.0 Universal' => 'http://creativecommons.org/publicdomain/zero/1.0/', - 'All rights reserved' => 'All rights reserved' - } - - config.cc_licenses_reverse = Hash[*config.cc_licenses.to_a.flatten.reverse] - - config.resource_types = { - "Article" => "Article", - "Audio" => "Audio", - "Book" => "Book", - "Capstone Project" => "Capstone Project", - "Conference Proceeding" => "Conference Proceeding", - "Dataset" => "Dataset", - "Dissertation" => "Dissertation", - "Image" => "Image", - "Journal" => "Journal", - "Map or Cartographic Material" => "Map or Cartographic Material", - "Masters Thesis" => "Masters Thesis", - "Part of Book" => "Part of Book", - "Poster" => "Poster", - "Presentation" => "Presentation", - "Project" => "Project", - "Report" => "Report", - "Research Paper" => "Research Paper", - "Software or Program Code" => "Software or Program Code", - "Video" => "Video", - "Other" => "Other", - } - - config.permission_levels = { - "Choose Access"=>"none", - "View/Download" => "read", - "Edit" => "edit" - } - - config.owner_permission_levels = { - "Edit" => "edit" - } - - config.queue = Sufia::Resque::Queue - - # Map hostnames onto Google Analytics tracking IDs - # config.google_analytics_id = 'UA-99999999-1' - - - # Where to store tempfiles, leave blank for the system temp directory (e.g. /tmp) - # config.temp_file_base = '/home/developer1' - - # If you have ffmpeg installed and want to transcode audio and video uncomment this line - # config.enable_ffmpeg = true - - # Specify the Fedora pid prefix: - # config.id_namespace = "sufia" - - # Specify the path to the file characterization tool: - # config.fits_path = "fits.sh" - -end - -Date::DATE_FORMATS[:standard] = "%m/%d/%Y" - diff --git a/sufia-models/lib/generators/sufia/models/install_generator.rb b/sufia-models/lib/generators/sufia/models/install_generator.rb new file mode 100644 index 0000000000..b8399f48fe --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/install_generator.rb @@ -0,0 +1,99 @@ +# -*- encoding : utf-8 -*- +require 'rails/generators' +require 'rails/generators/migration' + +class Sufia::Models::InstallGenerator < Rails::Generators::Base + include Rails::Generators::Migration + + source_root File.expand_path('../templates', __FILE__) + + argument :model_name, :type => :string , :default => "user" + desc """ +This generator makes the following changes to your application: + 1. Creates several database migrations if they do not exist in /db/migrate + 2. Adds user behavior to the user model + 3. Creates the sufia.rb configuration file + 4. Adds Sufia::SolrDocumentBehavior to app/models/solr_document.rb + 5. Generates mailboxer + """ + + # Implement the required interface for Rails::Generators::Migration. + # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb + def self.next_migration_number(path) + unless @prev_migration_nr + @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i + else + @prev_migration_nr += 1 + end + @prev_migration_nr.to_s + end + + # Setup the database migrations + def copy_migrations + # Can't get this any more DRY, because we need this order. + [ + "acts_as_follower_migration.rb", + "add_social_to_users.rb", + "create_single_use_links.rb", + "add_ldap_attrs_to_user.rb", + "add_avatars_to_users.rb", + "create_checksum_audit_logs.rb", + "create_version_committers.rb", + "add_groups_to_users.rb", + "create_local_authorities.rb", + "create_trophies.rb" + ].each do |f| + better_migration_template f + end + end + + # Add behaviors to the user model + def inject_sufia_user_behavior + file_path = "app/models/#{model_name.underscore}.rb" + if File.exists?(file_path) + inject_into_class file_path, model_name.classify do + "# Connects this user object to Sufia behaviors. " + + "\n include Sufia::User\n" + end + else + puts " \e[31mFailure\e[0m Sufia requires a user object. This generators assumes that the model is defined in the file #{file_path}, which does not exist. If you used a different name, please re-run the generator and provide that name as an argument. Such as \b rails -g sufia client" + end + end + + def create_configuration_files + copy_file "config/sufia.rb", "config/initializers/sufia.rb" + copy_file "config/redis.yml", "config/redis.yml" + copy_file "config/redis_config.rb", "config/initializers/redis_config.rb" + copy_file "config/resque_admin.rb", "config/initializers/resque_admin.rb" + copy_file "config/resque_config.rb", "config/initializers/resque_config.rb" + end + + # Add behaviors to the SolrDocument model + def inject_sufia_solr_document_behavior + file_path = "app/models/solr_document.rb" + if File.exists?(file_path) + inject_into_class file_path, "SolrDocument" do + " # Adds Sufia behaviors to the SolrDocument.\n" + + " include Sufia::SolrDocumentBehavior\n" + end + else + puts " \e[31mFailure\e[0m Sufia requires a SolrDocument object. This generators assumes that the model is defined in the file #{file_path}, which does not exist." + end + end + + def install_mailboxer + generate "mailboxer:install" + end + + private + + def better_migration_template(file) + begin + migration_template "migrations/#{file}", "db/migrate/#{file}" + sleep 1 # ensure scripts have different time stamps + rescue + puts " \e[1m\e[34mMigrations\e[0m " + $!.message + end + end + +end diff --git a/sufia-models/lib/generators/sufia/models/templates/config/clamav.rb b/sufia-models/lib/generators/sufia/models/templates/config/clamav.rb new file mode 100644 index 0000000000..a47ec2aa0c --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/templates/config/clamav.rb @@ -0,0 +1 @@ +ClamAV.instance.loaddb() if defined? ClamAV diff --git a/sufia-models/lib/generators/sufia/models/templates/config/mailboxer.rb b/sufia-models/lib/generators/sufia/models/templates/config/mailboxer.rb new file mode 100644 index 0000000000..4d9011dd28 --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/templates/config/mailboxer.rb @@ -0,0 +1,17 @@ +Mailboxer.setup do |config| + + #Configures if you applications uses or no the email sending for Notifications and Messages + config.uses_emails = true + + #Configures the default from for the email sent for Messages and Notifications of Mailboxer + config.default_from = "no-reply@mailboxer.com" + + #Configures the methods needed by mailboxer + config.email_method = :mailboxer_email + config.name_method = :name + + #Configures if you use or not a search engine and wich one are you using + #Supported enignes: [:solr,:sphinx] + config.search_enabled = false + config.search_engine = :solr +end diff --git a/lib/generators/sufia/templates/config/redis.yml b/sufia-models/lib/generators/sufia/models/templates/config/redis.yml similarity index 100% rename from lib/generators/sufia/templates/config/redis.yml rename to sufia-models/lib/generators/sufia/models/templates/config/redis.yml diff --git a/lib/generators/sufia/templates/config/redis_config.rb b/sufia-models/lib/generators/sufia/models/templates/config/redis_config.rb similarity index 96% rename from lib/generators/sufia/templates/config/redis_config.rb rename to sufia-models/lib/generators/sufia/models/templates/config/redis_config.rb index 37cc2df7d4..432d2e5368 100644 --- a/lib/generators/sufia/templates/config/redis_config.rb +++ b/sufia-models/lib/generators/sufia/models/templates/config/redis_config.rb @@ -7,7 +7,7 @@ config = YAML::load(ERB.new(IO.read(File.join(Rails.root, 'config', 'redis.yml'))).result)[Rails.env].with_indifferent_access # The important two lines - $redis.client.disconnect if $redis + $redis.client.disconnect if $redis $redis = Redis.new(host: config[:host], port: config[:port], thread_safe: true) rescue nil Resque.redis = $redis Resque.redis.client.reconnect if Resque.redis diff --git a/lib/generators/sufia/templates/config/resque_admin.rb b/sufia-models/lib/generators/sufia/models/templates/config/resque_admin.rb similarity index 100% rename from lib/generators/sufia/templates/config/resque_admin.rb rename to sufia-models/lib/generators/sufia/models/templates/config/resque_admin.rb diff --git a/lib/generators/sufia/templates/config/resque_config.rb b/sufia-models/lib/generators/sufia/models/templates/config/resque_config.rb similarity index 100% rename from lib/generators/sufia/templates/config/resque_config.rb rename to sufia-models/lib/generators/sufia/models/templates/config/resque_config.rb diff --git a/sufia-models/lib/generators/sufia/models/templates/config/setup_mail.rb b/sufia-models/lib/generators/sufia/models/templates/config/setup_mail.rb new file mode 100644 index 0000000000..4558e3f427 --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/templates/config/setup_mail.rb @@ -0,0 +1,3 @@ +ActionMailer::Base.smtp_settings = { + :address => "smtp.psu.edu" +} diff --git a/sufia-models/lib/generators/sufia/models/templates/config/sufia.rb b/sufia-models/lib/generators/sufia/models/templates/config/sufia.rb new file mode 100644 index 0000000000..04f45c14e0 --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/templates/config/sufia.rb @@ -0,0 +1,81 @@ +# Returns an array containing the vhost 'CoSign service' value and URL +Sufia.config do |config| + + config.fits_to_desc_mapping= { + :file_title => :title, + :file_author => :creator + } + + # Specify a different template for your repositories unique identifiers + # config.noid_template = ".reeddeeddk" + + config.max_days_between_audits = 7 + + config.cc_licenses = { + 'Attribution 3.0 United States' => 'http://creativecommons.org/licenses/by/3.0/us/', + 'Attribution-ShareAlike 3.0 United States' => 'http://creativecommons.org/licenses/by-sa/3.0/us/', + 'Attribution-NonCommercial 3.0 United States' => 'http://creativecommons.org/licenses/by-nc/3.0/us/', + 'Attribution-NoDerivs 3.0 United States' => 'http://creativecommons.org/licenses/by-nd/3.0/us/', + 'Attribution-NonCommercial-NoDerivs 3.0 United States' => 'http://creativecommons.org/licenses/by-nc-nd/3.0/us/', + 'Attribution-NonCommercial-ShareAlike 3.0 United States' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/us/', + 'Public Domain Mark 1.0' => 'http://creativecommons.org/publicdomain/mark/1.0/', + 'CC0 1.0 Universal' => 'http://creativecommons.org/publicdomain/zero/1.0/', + 'All rights reserved' => 'All rights reserved' + } + + config.cc_licenses_reverse = Hash[*config.cc_licenses.to_a.flatten.reverse] + + config.resource_types = { + "Article" => "Article", + "Audio" => "Audio", + "Book" => "Book", + "Capstone Project" => "Capstone Project", + "Conference Proceeding" => "Conference Proceeding", + "Dataset" => "Dataset", + "Dissertation" => "Dissertation", + "Image" => "Image", + "Journal" => "Journal", + "Map or Cartographic Material" => "Map or Cartographic Material", + "Masters Thesis" => "Masters Thesis", + "Part of Book" => "Part of Book", + "Poster" => "Poster", + "Presentation" => "Presentation", + "Project" => "Project", + "Report" => "Report", + "Research Paper" => "Research Paper", + "Software or Program Code" => "Software or Program Code", + "Video" => "Video", + "Other" => "Other", + } + + config.permission_levels = { + "Choose Access"=>"none", + "View/Download" => "read", + "Edit" => "edit" + } + + config.owner_permission_levels = { + "Edit" => "edit" + } + + config.queue = Sufia::Resque::Queue + + # Map hostnames onto Google Analytics tracking IDs + # config.google_analytics_id = 'UA-99999999-1' + + + # Where to store tempfiles, leave blank for the system temp directory (e.g. /tmp) + # config.temp_file_base = '/home/developer1' + + # If you have ffmpeg installed and want to transcode audio and video uncomment this line + # config.enable_ffmpeg = true + + # Specify the Fedora pid prefix: + # config.id_namespace = "sufia" + + # Specify the path to the file characterization tool: + # config.fits_path = "fits.sh" + +end + +Date::DATE_FORMATS[:standard] = "%m/%d/%Y" diff --git a/sufia-models/lib/generators/sufia/models/templates/migrations/acts_as_follower_migration.rb b/sufia-models/lib/generators/sufia/models/templates/migrations/acts_as_follower_migration.rb new file mode 100644 index 0000000000..d6a60c0e0d --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/templates/migrations/acts_as_follower_migration.rb @@ -0,0 +1,17 @@ +class ActsAsFollowerMigration < ActiveRecord::Migration + def self.up + create_table :follows, :force => true do |t| + t.references :followable, :polymorphic => true, :null => false + t.references :follower, :polymorphic => true, :null => false + t.boolean :blocked, :default => false, :null => false + t.timestamps + end + + add_index :follows, ["follower_id", "follower_type"], :name => "fk_follows" + add_index :follows, ["followable_id", "followable_type"], :name => "fk_followables" + end + + def self.down + drop_table :follows + end +end diff --git a/sufia-models/lib/generators/sufia/models/templates/migrations/add_avatars_to_users.rb b/sufia-models/lib/generators/sufia/models/templates/migrations/add_avatars_to_users.rb new file mode 100644 index 0000000000..2b856eb1be --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/templates/migrations/add_avatars_to_users.rb @@ -0,0 +1,9 @@ +class AddAvatarsToUsers < ActiveRecord::Migration + def self.up + add_attachment :users, :avatar + end + + def self.down + remove_attachment :users, :avatar + end +end diff --git a/sufia-models/lib/generators/sufia/models/templates/migrations/add_groups_to_users.rb b/sufia-models/lib/generators/sufia/models/templates/migrations/add_groups_to_users.rb new file mode 100644 index 0000000000..2cb388767f --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/templates/migrations/add_groups_to_users.rb @@ -0,0 +1,11 @@ +class AddGroupsToUsers < ActiveRecord::Migration + def self.up + add_column :users, :group_list, :text + add_column :users, :groups_last_update, :datetime + end + + def self.down + remove_column :users, :group_list + remove_column :users, :groups_last_update + end +end diff --git a/sufia-models/lib/generators/sufia/models/templates/migrations/add_ldap_attrs_to_user.rb b/sufia-models/lib/generators/sufia/models/templates/migrations/add_ldap_attrs_to_user.rb new file mode 100644 index 0000000000..66be26cb83 --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/templates/migrations/add_ldap_attrs_to_user.rb @@ -0,0 +1,27 @@ +class AddLdapAttrsToUser < ActiveRecord::Migration + def self.up + add_column :users, :display_name, :string + add_column :users, :address, :string + add_column :users, :admin_area, :string + add_column :users, :department, :string + add_column :users, :title, :string + add_column :users, :office, :string + add_column :users, :chat_id, :string + add_column :users, :website, :string + add_column :users, :affiliation, :string + add_column :users, :telephone, :string + end + + def self.down + remove_column :users, :display_name + remove_column :users, :address + remove_column :users, :admin_area + remove_column :users, :department + remove_column :users, :title + remove_column :users, :office + remove_column :users, :chat_id + remove_column :users, :website + remove_column :users, :affiliation + remove_column :users, :telephone + end +end diff --git a/sufia-models/lib/generators/sufia/models/templates/migrations/add_social_to_users.rb b/sufia-models/lib/generators/sufia/models/templates/migrations/add_social_to_users.rb new file mode 100644 index 0000000000..33d2779490 --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/templates/migrations/add_social_to_users.rb @@ -0,0 +1,13 @@ +class AddSocialToUsers < ActiveRecord::Migration + def self.up + add_column :users, :facebook_handle, :string + add_column :users, :twitter_handle, :string + add_column :users, :googleplus_handle, :string + end + + def self.down + remove_column :users, :facebook_handle, :string + remove_column :users, :twitter_handle, :string + remove_column :users, :googleplus_handle, :string + end +end diff --git a/sufia-models/lib/generators/sufia/models/templates/migrations/create_checksum_audit_logs.rb b/sufia-models/lib/generators/sufia/models/templates/migrations/create_checksum_audit_logs.rb new file mode 100644 index 0000000000..6340be2517 --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/templates/migrations/create_checksum_audit_logs.rb @@ -0,0 +1,20 @@ +class CreateChecksumAuditLogs < ActiveRecord::Migration + def self.up + create_table :checksum_audit_logs do |t| + t.string :pid + t.string :dsid + t.string :version + t.integer :pass + t.string :expected_result + t.string :actual_result + t.timestamps + end + add_index :checksum_audit_logs, [:pid, :dsid], :name=>'by_pid_and_dsid', :order => {:created_at => "DESC" } + + end + + def self.down + remove_index(:checksum_audit_logs, :name => 'by_pid_and_dsid') + drop_table :checksum_audit_logs + end +end diff --git a/sufia-models/lib/generators/sufia/models/templates/migrations/create_local_authorities.rb b/sufia-models/lib/generators/sufia/models/templates/migrations/create_local_authorities.rb new file mode 100644 index 0000000000..b6189694a9 --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/templates/migrations/create_local_authorities.rb @@ -0,0 +1,50 @@ +class CreateLocalAuthorities < ActiveRecord::Migration + def self.up + create_table :local_authority_entries, :force => true do |t| + t.integer :local_authority_id + t.string :label + t.string :uri + end + + create_table :local_authorities, :force => true do |t| + t.string :name, :unique => true + end + + create_table :domain_terms, :force => true do |t| + t.string :model + t.string :term + end + + create_table :domain_terms_local_authorities, :id => false do |t| + t.integer :domain_term_id, :foreign_key => true + t.integer :local_authority_id, :foreign_key => true + end + + create_table :subject_local_authority_entries, :force => true do |t| + t.string :label + t.string :lowerLabel + t.string :url + end + + add_index :local_authority_entries, [:local_authority_id, :label], :name => 'entries_by_term_and_label' + add_index :local_authority_entries, [:local_authority_id, :uri], :name => 'entries_by_term_and_uri' + add_index :domain_terms, [:model, :term], :name => 'terms_by_model_and_term' + add_index :domain_terms_local_authorities, [:local_authority_id, :domain_term_id], :name => 'dtla_by_ids1' + add_index :domain_terms_local_authorities, [:domain_term_id, :local_authority_id], :name => 'dtla_by_ids2' + add_index :subject_local_authority_entries, [:lowerLabel], :name => 'entries_by_lower_label' + end + + def self.down + drop_table :local_authority_entries + drop_table :local_authorities + drop_table :domain_terms + drop_table :domain_terms_local_authorities + drop_table :subject_local_authority_entries + remove_index :local_authority_entries, :name => "entries_by_term_and_label" + remove_index :local_authority_entries, :name => "entries_by_term_and_uri" + remove_index :domain_terms, :name => "terms_by_model_and_term" + remove_index :subject_local_authority_entries, :name => 'entries_by_lower_label' + remove_index :domain_terms_local_authorities, :name => 'dtla_by_ids1' + remove_index :domain_terms_local_authorities, :name => 'dtla_by_ids2' + end +end diff --git a/sufia-models/lib/generators/sufia/models/templates/migrations/create_single_use_links.rb b/sufia-models/lib/generators/sufia/models/templates/migrations/create_single_use_links.rb new file mode 100644 index 0000000000..3c1c3067ae --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/templates/migrations/create_single_use_links.rb @@ -0,0 +1,12 @@ +class CreateSingleUseLinks < ActiveRecord::Migration + def change + create_table :single_use_links do |t| + t.string :downloadKey + t.string :path + t.string :itemId + t.datetime :expires + + t.timestamps + end + end +end diff --git a/sufia-models/lib/generators/sufia/models/templates/migrations/create_trophies.rb b/sufia-models/lib/generators/sufia/models/templates/migrations/create_trophies.rb new file mode 100644 index 0000000000..38d28df045 --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/templates/migrations/create_trophies.rb @@ -0,0 +1,10 @@ +class CreateTrophies < ActiveRecord::Migration + def change + create_table :trophies do |t| + t.integer :user_id + t.string :generic_file_id + + t.timestamps + end + end +end diff --git a/sufia-models/lib/generators/sufia/models/templates/migrations/create_version_committers.rb b/sufia-models/lib/generators/sufia/models/templates/migrations/create_version_committers.rb new file mode 100644 index 0000000000..7c23fb91f9 --- /dev/null +++ b/sufia-models/lib/generators/sufia/models/templates/migrations/create_version_committers.rb @@ -0,0 +1,15 @@ +class CreateVersionCommitters < ActiveRecord::Migration + def self.up + create_table :version_committers do |t| + t.string :obj_id + t.string :datastream_id + t.string :version_id + t.string :committer_login + t.timestamps + end + end + + def self.down + drop_table :version_committers + end +end