Commit 92856c6c authored by phast's avatar phast

- improved sql_import section

parent 37634484
# ----------------------------------------------------
# Legacy Data Import
# ----------------------------------------------------
This folder contains several examples on how to import legacy
data into ]project-open[.
These scripts have been created during specific customer rollout
projects. Please do NOT expect that these scripts will work for
you out of the box. Instead, you will have to adapt these structure
to your data structures and fix any errors ocurring during the
conversion.
You will need reasonable knowledge of SQL and the PostgreSQL
database to perform this task.
- Flat-Table-Import
Preferred import method, developed during the import of data
at ISSA. Please note that project were not imported finally,
so there may still be errors in that section.
- LTC-Import:
Import of data from LTC-Organizer into ]project-open[
- Lexcelera:
Import of data from a proprietary Access application into
]project-open[
If you encounter issues during the import:
- Please be patient.
It usually takes one day of work to import one object type
(5 days for importing users, companies, projects, price list
and skills), even for persons with proven ]po[ database
skills.
- Please learn about the ]po[ data model:
Please search Google for "PO-Data-Model".
- Please learn PL/SQL:
It will pay off if you dedicate half a day to learn the
basics of PL/SQL.
Bests,
Frank
-- In this file we try to delete a user that is
-- referenced in many parts of the system.
delete from persons where person_id in (8892,13958,8898,11180,18025);
delete from users where user_id in (8892,13958,8898,11180,18025);
update acs_objects set modifying_user = 24332 where modifying_user in (8892,13958,8898,11180,18025);
update im_forum_topics set asignee_id = 24332 where asignee_id in (8892,13958,8898,11180,18025);
update im_projects set project_lead_id = 24332 where project_lead_id in (8892,13958,8898,11180,18025);
NOTICE: im_project_project_cache_up_tr: 11682
update im_user_absences SET owner_id = 24332 where owner_id in (8892,13958,8898,11180,18025);
update lang_messages_audit set overwrite_user = 24332 where overwrite_user in (8892,13958,8898,11180,18025);
update lang_messages set creation_user = 24332 where creation_user in (8892,13958,8898,11180,18025);
delete from im_fs_folder_status ;
delete from users where user_id in (8892,13958,8898,11180,18025);
delete from persons where person_id in (8892,13958,8898,11180,18025);
This diff is collapsed.
# ----------------------------------------------------
# Flat Table Import
# ----------------------------------------------------
The scripts in this folder have been used to import data from
a customer organization into ]project-open[ during a project
rollout.
- In a first step, we have exported all customer data into CSV
format (MS-Excel).
- In a second step, we paste the contents of the CSV files
right into the "COPY" sections of the import.sql file.
This way, the script automatically populates the import_*
tables with this data.
- In a third step the SQL script converts the data from the
import_* tables into ]po[ objects.
Please do NOT expect that these scripts will work for you
out of the box. Instead, the scripts are provided here as
a code sample. You will have to adapt these structure of
the import_* tables to your data structures and fix any
errors ocurring during the conversion.
Still, this is currently the most efficient method to import
legacy data into ]project-open[, apart from the CSV import
provided under "Companies" and "Users" tabs.
Bests,
Frank
# /packages/intranet-freelance/www/import-skills-tool.tcl
#
# Copyright (c) 2007 ]project-open[
#
# All rights reserved. Please check
# http://www.project-open.com/license/ for details.
ad_page_contract {
Checks for the "IdiomaX_Origen", "IdiomaX-Destino" and "IdiomaX-Tarifa"
fields of persons and convert them into freelance skills.
@author frank.bergmann@project-open.com
} {
}
# ---------------------------------------------------------------
# Security
# ---------------------------------------------------------------
set user_id [ad_maybe_redirect_for_registration]
set admin_p [im_is_user_site_wide_or_intranet_admin $user_id]
if {!$admin_p} {
ad_return_complaint 1 "<li>[_ intranet-freelance.lt_You_have_insufficient_3]"
return
}
set source_lang_skill_type [db_string source_lang "select category_id from im_categories where category = 'Source Language' and category_type = 'Intranet Skill Type'" -default 0]
set target_lang_skill_type [db_string target_lang "select category_id from im_categories where category = 'Target Language' and category_type = 'Intranet Skill Type'" -default 0]
set subject_area_skill_type [db_string target_lang "select category_id from im_categories where category = 'Subject Type' and category_type = 'Intranet Skill Type'" -default 0]
set skill_medium 2202
# ------------------------------------------------------------
# Render Report Header
ad_return_top_of_page "[im_header][im_navbar]"
for { set i 1} { $i < 13 } { incr i} {
set sql "
select person_id,
idiomas${i}_origen as source,
idiomas${i}_destino as target,
idiomas${i}_tarifa as tarif
from
persons
"
set cnt 0
db_foreach sql $sql {
if {$source == "" && $target == "" && $tarif == "" } { continue }
set src [im_transform_language2iso639 $source]
set tgt [im_transform_language2iso639 $target]
ns_write "<li>$i: User=$person_id, $src -> $tgt: $tarif\n"
if {"origen" == $src} { set src "" }
if {"otros" == $src} { set src "" }
if {[string length $src] > 5} {
ns_write "<li>$i: User=$person_id, src=$src: skipping\n"
set src ""
}
if {"destino" == $tgt} { set tgt "" }
if {"otros" == $tgt} { set tgt "" }
if {[string length $tgt] > 5} {
ns_write "<li>$i: User=$person_id, tgt=$tgt: skipping\n"
set tgt ""
}
set src_cat [db_string src "select category_id from im_categories where category = :src" -default 0]
if {0 == $src_cat && $src != ""} {
ns_write "<li><font=red>Didn't find '$src'</font>\n"
}
set tgt_cat [db_string src "select category_id from im_categories where category = :tgt" -default 0]
if {0 == $tgt_cat && $tgt != ""} {
ns_write "<li><font=red>Didn't find '$tgt'</font>\n"
}
set count [db_string cnt "
select count(*)
from im_freelance_skills
where
user_id = :person_id
and skill_type_id = $source_lang_skill_type
and skill_id = :src_cat
"]
if {0 != $src_cat && 0 == $count} {
db_dml source "
insert into im_freelance_skills (
user_id,
skill_id,
skill_type_id,
confirmed_experience_id
) values (
:person_id,
:src_cat,
$source_lang_skill_type,
:skill_medium
)
"
}
set count [db_string cnt "
select count(*)
from im_freelance_skills
where
user_id = :person_id
and skill_type_id = $target_lang_skill_type
and skill_id = :tgt_cat
"]
if {0 != $tgt_cat && 0 == $count} {
db_dml source "
insert into im_freelance_skills (
user_id,
skill_id,
skill_type_id,
confirmed_experience_id
) values (
:person_id,
:tgt_cat,
$target_lang_skill_type,
:skill_medium
)
"
}
if {0 != $src_cat && 0 != $tgt_cat && $tarif != "" && $tarif > 0} {
set companies [db_list cid "
select c.company_id
from im_companies c,
acs_rels r
where
c.company_id = r.object_id_one
and r.object_id_two = :person_id
"]
db_dml price_insert "
insert into im_trans_prices (
price_id,
uom_id,
company_id,
task_type_id,
target_language_id,
source_language_id,
subject_area_id,
currency,
price,
note
) values (
nextval('im_trans_prices_seq'),
[im_uom_s_word],
[lindex $companies 0],
null,
:tgt_cat,
:src_cat,
null,
'EUR',
:tarif,
null
)"
}
incr cnt
}
}
# ------------------------------------------------------------
# Render Report Footer
ns_write [im_footer]
This diff is collapsed.
This diff is collapsed.
drop table tmp_projects;
create table tmp_projects (
project_name varchar(1000),
project_nr varchar(1000),
company_nr varchar(1000),
project_status_id integer,
project_type_id integer
);
insert into tmp_projects values ('First Project', 'first', 'internal', 76, 86);
insert into tmp_projects values ('Second Project', 'second', 'internal', 76, 86);
create or replace function tmp_import_projects ()
returns integer as '
DECLARE
row RECORD;
v_project_id integer;
v_company_id integer;
v_duplicate_p integer;
BEGIN
for row in
select *
from tmp_projects
loop
RAISE NOTICE ''Project: %: %'', row.project_nr, row.project_name;
-- Get the customer for the project
-- The customers must be set up _before_ importing the projects.
-- You can use "internal" for specifying internal projects.
select company_id
into v_company_id
from im_companies
where company_path = row.company_nr;
-- Check for duplicate project_nr.
-- In this case we dont have to create a new project.
-- We still can update the existing project.
select count(*)
into v_duplicate_p
from im_projects p
where trim(p.project_nr) = trim(row.project_nr);
IF v_duplicate_p = 0 THEN
-- First create a new Main project
select im_project__new (
null, ''im_project'',
now()::date, 0, ''0.0.0.0'', null,
row.project_name, row.project_nr, row.project_nr,
null, v_company_id,
row.project_type_id, row.project_status_id
) into v_project_id;
END IF;
-- Now the project should exist.
select project_id
into v_project_id
from im_projects
where project_nr = row.project_nr;
-- Now we can add more stuff to the project.
-- This is just an example
update im_projects set
note = ''batch import''
where project_id = v_project_id;
end loop;
return 0;
END;' language 'plpgsql';
select tmp_import_projects ();
drop function tmp_import_projects ();
-- Check if the projects are there...
select * from im_projects order by project_id;
# ----------------------------------------------------
# Import scripts from Lexcelera
# ----------------------------------------------------
The scripts in this folder have been used to import data from
a legacy Access application at Lexcelera into ]project-open[.
As a first step we have imported the Access database into
PostgreSQL using a commercial database converter.
In a second step we ran the scripts in this folder to insert
]po[ objects for each of the Access objects.
Please do NOT expect that these scripts will work for you
out of the box. Instead, the scripts are provided here as
a code sample. You will have to adapt these scripts to the
data structure of your own application.
Please note that this method of importing data is considerably
less efficient than the "flat-table-import" in a neighbouring
folder.
Bests,
Frank
-------------------------------------------------------
-- Run this SQL script in order to change a Windows
-- "Preconf" for a Linux server.
-------------------------------------------------------
update apm_parameter_values
set attr_value = '/web/projop/' || substring(attr_value, 16)
where
attr_value like 'C:/ProjectOpen/%';
# ----------------------------------------------------
# Import scripts for LTC-Organizer
# ----------------------------------------------------
The scripts in this folder have been used to import data from
an LTC-Organizer 2.0 application into ]project-open[.
As a first step we have imported the Access database into
PostgreSQL using a commercial database converter.
In a second step we ran the scripts in this folder to insert
]po[ objects for each of the Access objects.
Please note that these scripts will probably not work out of
the box for you. You will have to adapt these scripts to the
data structure of your own application.
Please note that this method of importing data is considerably
less efficient than the "flat-table-import" in a neighbouring
folder.
Bests,
Frank
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment