Skip to content

Commit

Permalink
Fixed for legacy import
Browse files Browse the repository at this point in the history
  • Loading branch information
multiscan committed Jul 2, 2013
1 parent 6c90ce6 commit 8a5a70c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 111 deletions.
18 changes: 9 additions & 9 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
# }

# ------------------------------------------------------------ DEPLOYMENT PARAMS
set :application, "slideshot"
set :application, "thot"

role :web, "thot.epfl.ch"
role :app, "thot.epfl.ch"
role :db, "thot.epfl.ch", :primary => true # where migration are executed
# role :db, "your slave db-server here"

set :deploy_to, "/var/www/thot/prod"
set :deploy_to, "/var/www/thot2/prod"
set :user, "root"
set :use_sudo, false
set :keep_releases, 3
Expand Down Expand Up @@ -52,15 +52,15 @@
end

# ----------------------------------------------------------------- DEPLOY TASKS
namespace :deploy do
# namespace :deploy do

desc "Create symlinks to upload/download folders in public"
task :make_symlinks do
run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
run "ln -nfs #{shared_path}/downloads #{release_path}/public/downloads"
end
# desc "Create symlinks to upload/download folders in public"
# task :make_symlinks do
# run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
# run "ln -nfs #{shared_path}/downloads #{release_path}/public/downloads"
# end

end
# end

# -------------------------------------------------------------------- APP TASKS
namespace :app do
Expand Down
6 changes: 3 additions & 3 deletions db/migrate/20130116111900_create_books.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ def change
t.string :subtitle
t.string :author
t.string :editor
t.string :call1, :limit=>8
t.string :call1, :limit=>16
t.string :call2, :limit=>16
t.string :call3, :limit=>8
t.string :call4, :limit=>8
t.string :call3, :limit=>16
t.string :call4, :limit=>16
t.string :collation
t.string :isbn, :limit=>24
t.string :isbn13, :limit=>13
Expand Down
132 changes: 66 additions & 66 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,86 +9,86 @@
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(:version => 20130612161702) do
ActiveRecord::Schema.define(version: 20130612161702) do

create_table "admins", :force => true do |t|
t.string "name", :null => false
t.string "role", :default => "operator", :null => false
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
create_table "admins", force: true do |t|
t.string "name", null: false
t.string "role", default: "operator", null: false
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.integer "sign_in_count", default: 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "admins", ["email"], :name => "index_admins_on_email", :unique => true
add_index "admins", ["reset_password_token"], :name => "index_admins_on_reset_password_token", :unique => true
add_index "admins", ["email"], name: "index_admins_on_email", unique: true, using: :btree
add_index "admins", ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true, using: :btree

create_table "books", :force => true do |t|
create_table "books", force: true do |t|
t.string "title"
t.string "subtitle"
t.string "author"
t.string "editor"
t.string "call1", :limit => 8
t.string "call2", :limit => 16
t.string "call3", :limit => 8
t.string "call4", :limit => 8
t.string "call1", limit: 16
t.string "call2", limit: 16
t.string "call3", limit: 16
t.string "call4", limit: 16
t.string "collation"
t.string "isbn", :limit => 24
t.string "isbn13", :limit => 13
t.string "isbn", limit: 24
t.string "isbn13", limit: 13
t.string "locn"
t.integer "volume"
t.string "edition"
t.integer "publisher_id"
t.string "collection"
t.string "language", :limit => 16
t.string "language", limit: 16
t.string "categories"
t.text "abstract"
t.text "toc"
t.text "idx"
t.text "notes"
t.integer "pubyear"
t.float "price"
t.string "currency", :limit => 8
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "currency", limit: 8
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "deg_isbns", :force => true do |t|
create_table "deg_isbns", force: true do |t|
t.string "isbn"
t.integer "count"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "goods", :force => true do |t|
create_table "goods", force: true do |t|
t.integer "inventory_session_id"
t.integer "item_id"
t.integer "current_shelf_id"
t.integer "previous_shelf_id"
t.integer "commit", :default => 0
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "commit", default: 0
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "inventory_sessions", :force => true do |t|
create_table "inventory_sessions", force: true do |t|
t.string "name"
t.text "notes"
t.integer "admin_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "items", :force => true do |t|
create_table "items", force: true do |t|
t.integer "lab_id"
t.integer "location_id"
t.integer "shelf_id"
Expand All @@ -99,46 +99,46 @@
t.string "currency"
t.integer "inventoriable_id"
t.string "inventoriable_type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "labs", :force => true do |t|
create_table "labs", force: true do |t|
t.string "name"
t.string "nick"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "loans", :force => true do |t|
create_table "loans", force: true do |t|
t.integer "user_id"
t.integer "item_id"
t.datetime "return_date"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "locations", :force => true do |t|
create_table "locations", force: true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "operatorships", :force => true do |t|
create_table "operatorships", force: true do |t|
t.integer "lab_id"
t.integer "admin_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "publishers", :force => true do |t|
create_table "publishers", force: true do |t|
t.string "name"
t.text "notes"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "searches", :force => true do |t|
create_table "searches", force: true do |t|
t.string "query"
t.string "isbn"
t.string "publisher_name"
Expand All @@ -149,32 +149,32 @@
t.integer "lab_id"
t.integer "location_id"
t.string "status"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "shelves", :force => true do |t|
create_table "shelves", force: true do |t|
t.integer "location_id"
t.integer "seqno"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "users", :force => true do |t|
t.string "name", :null => false
create_table "users", force: true do |t|
t.string "name", null: false
t.string "location"
t.string "nebis", :default => "NA"
t.string "nebis", default: "NA"
t.integer "legacy_id"
t.integer "admin_id"
t.integer "lab_id"
t.datetime "expire_at"
t.text "notes"
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.integer "sign_in_count", default: 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
Expand All @@ -183,10 +183,10 @@
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree

end
40 changes: 7 additions & 33 deletions lib/tasks/legacy_import.rake
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
desc "Import legacy thot library database (should be done only at EPFL/IPG"
task :legacy_import => [:environment] do
# ------------------------------------------------------------------- Base Users
admin = Admin.find_or_create_by_email(
:name => ENV['ADMIN_NAME'].dup,
:email => ENV['ADMIN_EMAIL'].dup,
:password => ENV['ADMIN_PASSWORD'].dup,
:password_confirmation => ENV['ADMIN_PASSWORD'].dup
)
admin.role='admin'
# admin.confirmed_at = DateTime.now
admin.save

# if Rails.env == "development"
# user = User.find_or_create_by_email(
# :name => "Test User", :email => "[email protected]",
# :password => ENV['ADMIN_PASSWORD'].dup,
# :password_confirmation => ENV['ADMIN_PASSWORD'].dup
# )
# user.confirmed_at = DateTime.now
# user.save
# end

puts "Seed done. Remember to run the following maintenance rake tasks:"
puts "rake legacy_import"
puts "rake cleanup_books "
puts "rake isbnmerge"


# ------------------------------------------------------- Old database migration

Expand Down Expand Up @@ -78,12 +52,12 @@ end
# end

# ----------------------------------------- Import library users
default_lab = Lab.find_by_nick("UNKNOWN")
default_lab = Lab.where(nick: "UNKNOWN").first
duplicate_users={}
special_users={}
# empty_nebis_count=0
empty_email_count=0
Legacy::Person.find(:all).each do |lp|
Legacy::Person.all.each do |lp|
# # skip users without nebis
# nebis=lp.nebis
# if nebis.nil?
Expand All @@ -102,7 +76,7 @@ Legacy::Person.find(:all).each do |lp|
next
end
p=nil
if p = User.find_by_email(lp.email)
if p = User.where(email: lp.email).first
if ( p.nebis == "invalid" || p.nebis == "empty" ) && lp.nebis != "invalid" && lp.nebis != "empty"
"Duplicate email: #{lp.userEmail} but usefull NEBIS"
p.nebis=lp.nebis
Expand All @@ -123,7 +97,7 @@ Legacy::Person.find(:all).each do |lp|
# :password_confirmation => ENV['DEFAULT_USER_PASSWORD'].dup
)
# p.confirmed_at = DateTime.now
lab=Lab.find_by_nick(lp.userLab)
lab=Lab.where(nick: lp.userLab).first
if lab
p.lab=lab
else
Expand All @@ -142,7 +116,7 @@ end
pn=nil
p=nil
nb=0
Legacy::Book.find(:all, :order => "publisher").each do |lb|
Legacy::Book.order("publisher").each do |lb|
if lb.publisher && lb.publisher != pn
pn=lb.publisher
p=Publisher.create(:name => pn)
Expand Down Expand Up @@ -176,8 +150,8 @@ Legacy::Book.find(:all, :order => "publisher").each do |lb|
puts " errs: #{b.errors}"
end

lab = Lab.find_by_nick(lb.lab)
u = lb.userId ? ( User.find_by_legacy_id(lb.userId) || duplicate_users[lb.userId] ) : nil
lab = Lab.where(nick: lb.lab).first
u = lb.userId ? ( User.where(legacy_id: lb.userId).first || duplicate_users[lb.userId] ) : nil

i = b.items.new(
:status => lb.status,
Expand Down

0 comments on commit 8a5a70c

Please sign in to comment.