README.pentabarf.md 2.39 KB
Newer Older
1 2
# frab - pentabarf import

3 4 5 6 7
These notes may help to import data from a pentabarf postgresql database.

Using postgresql as a database for frab is still somewhat untested. The pentabarf 
import is however likely to fail, as pentabarf uses text fields instead of char(255)

Mario Manno's avatar
Mario Manno committed
8 9
Imagemagick needs to be installed as we will convert pjpeg and tiff to png.

10 11
## postgresql installation

Mario Manno's avatar
Mario Manno committed
12
Install postgresql
13 14 15

## postgresql setup

Mario Manno's avatar
Mario Manno committed
16
* make it listen on localhost
17 18
* create a psql user and grant some access on relations
* add a pentabarf entry for the postgresql database to your rails db environment
19 20

## postgresql copy
21

22 23 24 25 26 27 28 29
Make a copy of your postgresql database, as we need to do some changes

    pg_dump -Fc DBNAME > backup.dump
    createdb NEWNAME
    pg_restore -O -d NEWNAME backup.dump > /dev/null

## postgresql permissions

30 31
Grant all permissions on the database copy to the import user account:

Mario Manno's avatar
Mario Manno committed
32 33 34
    psql NEWNAME
    -- generate the grant statements
    select 'grant all on '||schemaname||'.'||tablename||' to frab;' from pg_tables  
35
      order by schemaname, tablename;
Mario Manno's avatar
Mario Manno committed
36 37 38 39 40 41 42
    -- copy&paste the generated statements into psql

    -- in case you re-created the NEWNAME copy, re-grant permissions to the user
    REVOKE ALL ON SCHEMA public FROM frab;
    GRANT ALL ON SCHEMA public TO frab;
    REVOKE ALL ON SCHEMA auth FROM frab;
    GRANT ALL ON SCHEMA auth TO frab;
43 44 45

## data migration

Mario Manno's avatar
Mario Manno committed
46 47
Conference acronyms need to be within /^[a-zA-Z0-9_-]*$/
Whitespaces are removed automatically, but you need to replace unicode characters manually.
48

49 50 51
    -- conference acronyms appear in URLs, they may not contain whitespace in frab:
    UPDATE conference SET acronym = replace(acronym, ' ', '');
    UPDATE conference SET acronym = 'mrmcdX' where conference_id=86; -- mrmcdⅩ
52 53 54 55 56 57 58 59 60 61

## import 

Delete any old mappings from previous imports. Maybe delete the old filess, too.

    rm tmp/*mappings.yml
    rm -fr public/system
    RAILS_ENV=production rake db:reset
    RAILS_ENV=production rake pentabarf:import:all

Mario Manno's avatar
Mario Manno committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
## testing

You can check on the barf data like this:

    RAILS_ENV="development" rails console
    @p = PentabarfImportHelper.new
    @barf = @p.instance_variable_get('@barf')
    @barf.select_all("SELECT * FROM conference")

## privileges

You maybe want to drop all users to the coordinator role, to start fresh.

User.all.select { |u| u.role == "admin" or u.role == "orga" }.each { |u| puts "dropping ${u.email}"; u.role = "coordinator"; u.save }

77