← Back to team overview

credativ team mailing list archive

[Merge] lp:~therp-nl/openupgrade-server/7.0-migrate_script_with_template into lp:openupgrade-server

 

Stefan Rijnhart (Therp) has proposed merging lp:~therp-nl/openupgrade-server/7.0-migrate_script_with_template into lp:openupgrade-server.

Commit message:
[RFR] Copy database within the database server

Requested reviews:
  OpenUpgrade Committers (openupgrade-committers)

For more details, see:
https://code.launchpad.net/~therp-nl/openupgrade-server/7.0-migrate_script_with_template/+merge/210619

This change copies the database within the database server instead of performing the pg_dump/restore round trip. Apart from a code simplification, this change also allows the script to continue in this environment that I am currently working in, in which the pg utils mysteriously ignore the PGUSER/PASSWORD environment variables.

-- 
https://code.launchpad.net/~therp-nl/openupgrade-server/7.0-migrate_script_with_template/+merge/210619
Your team OpenUpgrade Committers is requested to review the proposed merge of lp:~therp-nl/openupgrade-server/7.0-migrate_script_with_template into lp:openupgrade-server.
=== modified file 'scripts/migrate.py'
--- scripts/migrate.py	2014-01-20 21:56:01 +0000
+++ scripts/migrate.py	2014-03-12 14:31:15 +0000
@@ -201,33 +201,10 @@
     conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
     cur=conn.cursor()
     cur.execute('drop database if exists "%(db)s"' % {'db': db})
-    cur.execute('create database "%(db)s"' % {'db': db})
+    cur.execute('create database "%(db)s" with template "%(db_name)s"' % {
+        'db': db, 'db_name': db_name})
     cur.close()
 
-    os.environ['PGUSER'] = db_user             
-    if ('host' in conn_parms and conn_parms['host']
-    and not os.environ.get('PGHOST')):
-        os.environ['PGHOST'] = conn_parms['host']             
-
-    if ('port' in conn_parms and conn_parms['port']
-    and not os.environ.get('PGPORT')):
-        os.environ['PGPORT'] = conn_parms['port']             
-
-    password_set = False
-    if ('password' in conn_parms and conn_parms['password']
-    and not os.environ.get('PGPASSWORD')):
-        os.environ['PGPASSWORD'] = conn_parms['password']             
-        password_set = True
-
-    os.system(
-        ('pg_dump --format=custom --no-password %(db_name)s ' +
-         '| pg_restore --no-password --dbname=%(db)s') %
-        {'db_name': db_name, 'db': db}
-    )
-
-    if password_set:
-        del os.environ['PGPASSWORD'] 
-
 for version in options.migrations.split(','):
   print 'running migration for '+version
   config.set('options', 'without_demo', 'True')


Follow ups