Ticket #844 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

Conversion failed

Reported by: anonymous Assigned to: pacopablo
Priority: normal Component: SqliteToPgScript
Severity: major Keywords:
Cc: nick.stone@snowvalley.com Trac Release: 0.10

Description

Basically I'm experiencing a number of problems with the conversion. Firstly the burndown plug-in causes an error but that seems to be a problem with the plugin. Secondly the following lines:

if not opts.noclean:

self.cleanTable(table)

in migrateTable throw an error. Thirdly once these are removed the copy only seems to copy over some of the rows. I get back an error to the effect that the data already exists in the postgres table even though it doesn't.

I'm happy to help out here so if you need more info - please let me know

Attachments

Change History

(in reply to: ↑ description ) 10/24/06 19:01:45 changed by pacopablo

  • status changed from new to assigned.

Replying to anonymous:

Firstly the burndown plug-in causes an error but that seems to be a problem with the plugin.

Since I'm lazy, I'll blame those on the burndown plugin also.

if not opts.noclean:
    self.cleanTable(table)

in migrateTable throw an error. Thirdly once these are removed the copy only seems to copy over some of the rows. I get back an error to the effect that the data already exists in the postgres table even though it doesn't.

The way the plugin works, is it populates the PostgreSQL tables using the same method that Trac uses when one runs initenv. Beacuse of this, all the default pages are copied into the PostgreSQL database. So, if we want an exact copy of the SQLite data, it then wipes all info from the table before copying the data from SQLite.

The only reason that I can think of that this would fail is due to permissions on the PostgreSQL database. However, I find that unlikely.

I'm happy to help out here so if you need more info - please let me know

More info would be helpful. If you have any tracebacks, that would be the best. Also, can you tell me what versions you are using of the following:

  • PostgreSQL
  • psycopg or pyPgSQL
  • Trac

10/25/06 06:53:57 changed by nickstone

Here's the information you wanted:

System: python 2.4.3-8 postgres 8.1.4-6 python-psycopg 2.0.4-1 trac 0.10

Traceback

Traceback (most recent call last):
  File "/root/trac_scripts/sqlitetopgscript/0.10/sqlite2pg", line 332, in ?
    Main(opts)
  File "/root/trac_scripts/sqlitetopgscript/0.10/sqlite2pg", line 245, in Main
    pgenv = getPostgreSQLEnvironment(opts)
  File "/root/trac_scripts/sqlitetopgscript/0.10/sqlite2pg", line 224, in getPostgreSQLEnvironment
    env.upgrade()
  File "/usr/lib/python2.4/site-packages/trac/env.py", line 334, in upgrade
    if participant.environment_needs_upgrade(db):
  File "build/bdist.linux-i686/egg/burndown/burndown.py", line 42, in environment_needs_upgrade
  File "/usr/lib/python2.4/site-packages/trac/db/util.py", line 48, in execute
    return self.cursor.execute(sql)
  File "/usr/lib/python2.4/site-packages/trac/db/util.py", line 48, in execute
    return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "sqlite_master" does not exist

Trac plugins

graphviz.graphviz.graphvizmacro = enabled
iniadmin.* = enabled
navadd.* = enabled
pagetopdf.* = enabled
trac.wiki.web_ui.wikimodule = disabled
tracgantt.* = enabled
tractags.* = enabled
webadmin.* = enabled
tracnav.* = enabled

Notes:

I did try editing the script to see if I could see what is going on. Firstly it appears that the schema is correctly created which rules out permissions. Secondly the script appears to drop out in the try / catch within the for loop in Main. I have tried changing the catch statement and have managed to get some data accross but I suspect the problem lies with why that's failing.

10/25/06 08:14:47 changed by nickstone

Just for information I'm using the command as follows:

sqlite2pg -e /<sqlite-project> -s sqlite:db/trac.db -p 'postgres://<user>:<password>@localhost/trac?schema=<schema>'

10/25/06 08:16:51 changed by nickstone

My appologies - I just realised I pasted the wrong traceback... Correct Traceback below:

Traceback (most recent call last):
  File "/root/trac_scripts/sqlitetopgscript/0.10/sqlite2pg", line 331, in ?
    Main(opts)
  File "/root/trac_scripts/sqlitetopgscript/0.10/sqlite2pg", line 250, in Main
    rc = tmigration.migrateTable(tname) or rc
  File "/root/trac_scripts/sqlitetopgscript/0.10/sqlite2pg", line 70, in migrateTable
    self.cleanTable(table)
  File "/root/trac_scripts/sqlitetopgscript/0.10/sqlite2pg", line 65, in cleanTable
    cur.execute(delete_from)
  File "/usr/lib/python2.4/site-packages/trac/db/util.py", line 48, in execute
    return self.cursor.execute(sql)
  File "/usr/lib/python2.4/site-packages/trac/db/util.py", line 48, in execute
    return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "system" does not exist

11/07/06 08:01:28 changed by nickstone

Sorry to hastle but is there anything else you need for this and if as I suspect there's something really simple I've done wrong is there any chance you could post something up so that I know what to change - thanks.

11/07/06 17:25:37 changed by pacopablo

Sorry to be so unresponsive.

The good news: I can now duplicate the bug. Not on my own server, but on a different server

The bad news: This bug makes absolutely no sense and shouldn't be happening in the first place.

For some unknown reason, the script manages to create the tables fine in the new schema, however, when it goes to clean the table, it loses the schema. This isn't really a bug in the script as much as it is a bug in either the schema handling code in trac proper (for which I'm to blame again :) ) or some weird combination of postgres + psycopg2 + ???

Just to rule out everything, what are your locale settings? Also, would it be possible to try using pyPgSQL?

So, unfortunately, there isn't a whole lot more you can do, unless you really want to start profiling the trac code. I am working on the issue, but I don't know how long it's going to take me.

11/08/06 08:41:29 changed by nickstone

No worries - I've put the locale stuff in below - hope that's what you wanted - if not just let me know. I've tried installing pyPgSQL through Debain (can't get it to work at all - agggrrrr!). Will keep trying and post some more information up if successful.

LANG=en_GB
LANGUAGE=en_GB:en_US:en_GB:en
LC_CTYPE="en_GB"
LC_NUMERIC="en_GB"
LC_TIME="en_GB"
LC_COLLATE="en_GB"
LC_MONETARY="en_GB"
LC_MESSAGES="en_GB"
LC_PAPER="en_GB"
LC_NAME="en_GB"
LC_ADDRESS="en_GB"
LC_TELEPHONE="en_GB"
LC_MEASUREMENT="en_GB"
LC_IDENTIFICATION="en_GB"
LC_ALL=

11/08/06 08:51:04 changed by nickstone

OK pyPgSQL works fine - well at least as far as I can tell. I have a postgres based site I'm using as a test and that still all functions without psycopg although of course this may be unrelated! The Traceback I now get seems to suggest the script requires psycopg to work...

Traceback (most recent call last):
  File "sqlitetopgscript/0.10/sqlite2pg", line 30, in ?
    from psycopg2 import ProgrammingError, IntegrityError
ImportError: No module named psycopg2

(follow-up: ↓ 10 ) 11/08/06 11:45:33 changed by nickstone

I'm interested in getting up to speed on Python so if you can point me in the right direction I can happily do some profiling if it will help.

(in reply to: ↑ 9 ) 11/08/06 20:19:47 changed by coderanger

Replying to nickstone:

I'm interested in getting up to speed on Python so if you can point me in the right direction I can happily do some profiling if it will help.

http://www.diveintopython.org is a great reference, though in general the mailing list or IRC are probably better places to ask.

11/09/06 12:29:52 changed by nickstone

OK - I think I have a handle on the problem - I'm using schema's within the Postgres DB. If I fudge the code a bit to put the schema name into the SQL in a few places they work fine! e.g. currently the code will produce "DELETE FROM <table>" for the clean table routine but it needs to be "DELETE FROM <schema>.<table>" etc.

Hope this helps

11/09/06 13:52:25 changed by pacopablo

The trick here is the trac code. When you set ?schema=foo in the database option in trac.ini, you are telling trac to use the schema foo for all it's operations. Trac then issues a SET search_path TO foo query. This makes it such that subsequent DELETE FROM <table> queries are equivalent to DELETE FROM foo.<table>

The weird part is that for some reason, when you run the sqlite2pg script, it isn't getting set. This should be next to impossible due to how trac sets the search path. For some reason it is failing to set the search path, or something is happening to nullify the setting of the search path. This is where the problem lies.

11/10/06 05:21:03 changed by nickstone

I've tried a small fudge in the code which seems to do the job - I'm sure you'll want to find a better way of doing this but in the mean time...

I've added the following code to Main just after the "if not opts.tlist: etc..." clause (so just before the for loop).

    cnx = pgenv.get_db_cnx()
    schema = cnx.schema or u'public'
    cur = cnx.cursor()
    cur.execute('SET search_path TO %s', (schema,))

the migration now works which is good but I suspect that there are better ways to do this.

11/21/06 06:16:02 changed by nickstone

OK I was premature - the conversion nearly works for some reason every table apart from milestone gets copied accross - I will keep looking into it and try and put some more information up if I have any luck

11/21/06 06:23:54 changed by nickstone

Looks like the problem is that the table definition for postgres version of milestone is different to the SQLite version - if somebody could point me to the appropriate place to log this as a trac bug I will. FYI:

SQLite definition:

CREATE TABLE milestone (
    name            text PRIMARY KEY,
    due             integer, -- Due date/time
    completed       integer, -- Completed date/time
    started        integer, -- Started date/time
    description     text
)

postgresql def:

CREATE TABLE milestone
(
  name text NOT NULL,
  due int4,
  completed int4,
  description text,
  CONSTRAINT milestone_pkey PRIMARY KEY (name)
) 
WITHOUT OIDS;

11/28/06 15:22:45 changed by pacopablo

IamLordV1ldemort has given me great insight into this problem as he seems to be able to break everything I do ;)

Anyway, when we were mucking around with postgres database leaks in tracd, we found that when we turned off connection pooling, we ran into this bug.

For us that is what triggered it. I verified that this bug exists even when connection pooling is turned on, which is probably your case.

I hope to have a work around soon.

11/28/06 16:08:59 changed by pacopablo

(In [1608])

  • Refs #844 hopefull fix for missing "system" table. Turns out that the ISOLATION_LEVEL_AUTOCOMMIT line was the culprit. I think that I originally had that in there because when I first started the script I was taking a different approach for creating the environments. It's not needed now, and fixes the issue for me. Need testing before I can close the bug.

11/28/06 16:35:58 changed by pacopablo

OK, fix applied. Need testing. Works for me now.

03/27/07 08:56:53 changed by anonymous

  • status changed from assigned to closed.
  • resolution set to fixed.

(follow-up: ↓ 21 ) 03/27/07 22:46:25 changed by tauk2mi@gmail.com

  • status changed from closed to reopened.
  • resolution deleted.

Getting the following error while converting from sqlite to postgresql:

System: python 2.4.3-8 postgres 8.1.4-6 python-psycopg 2.0.4-1 trac 0.10

Traceback (most recent call last):

File "./sqlite2pg", line 331, in ?

Main(opts)

File "./sqlite2pg", line 250, in Main

rc = tmigration.migrateTable(tname) or rc

File "./sqlite2pg", line 72, in migrateTable

rc = self.default_copy(table)

File "./sqlite2pg", line 82, in default_copy

scur.execute(select_all)

File "/var/lib/python-support/python2.4/trac/db/util.py", line 51, in execute

return self.cursor.execute(sql)

File "/var/lib/python-support/python2.4/trac/db/sqlite_backend.py", line 56, in execute

args or [])

File "/var/lib/python-support/python2.4/trac/db/sqlite_backend.py", line 48, in _rollback_on_error

return function(self, *args, **kwargs)

pysqlite2.dbapi2.DatabaseError?: file is encrypted or is not a database

(in reply to: ↑ 20 ) 03/27/07 23:10:51 changed by pacopablo

  • status changed from reopened to closed.
  • resolution set to fixed.

Replying to tauk2mi@gmail.com:

Getting the following error while converting from sqlite to postgresql:

<snip>

pysqlite2.dbapi2.DatabaseError?: file is encrypted or is not a database

This is not a bug in the conversion script. This is due to the fact that your sqlite database is either a sqlite2 db and your bindings are sqlite3 or the bindings are sqlite2 and the bindings are sqlite3. Because you're using pysqlite2, I'd say the former. Convert your sqlite database and then re-run the script.

Take a look at t.e.o for info on how to upgrade your sqlite database.

03/27/07 23:47:56 changed by anonymous

It worked. Thank you for the quick response and a fix!


Add/Change #844 (Conversion failed)




Change Properties
Action