def migrate_user(old_username, new_username, password, superuser=False): if postgresql.is_primary(): # We do this on any primary, as the master is # appointed later. It also works if we have # a weird setup with manual_replication and # multiple primaries. con = postgresql.connect() postgresql.ensure_user(con, new_username, password, superuser=superuser) cur = con.cursor() hookenv.log("Granting old role {} to new role {}" "".format(old_username, new_username)) cur.execute( "GRANT %s TO %s", ( postgresql.pgidentifier(old_username), postgresql.pgidentifier(new_username), ), ) con.commit() else: hookenv.log("Primary must map role {!r} to {!r}" "".format(old_username, new_username))
def migrate_user(old_username, new_username, password, superuser=False): if postgresql.is_primary(): # We do this on any primary, as the master is # appointed later. It also works if we have # a weird setup with manual_replication and # multiple primaries. con = postgresql.connect() postgresql.ensure_user(con, new_username, password, superuser=superuser) cur = con.cursor() hookenv.log('Granting old role {} to new role {}' ''.format(old_username, new_username)) cur.execute('GRANT %s TO %s', (postgresql.pgidentifier(old_username), postgresql.pgidentifier(new_username))) con.commit() else: hookenv.log('Primary must map role {!r} to {!r}' ''.format(old_username, new_username))
def test_pgidentifier(self): a = postgresql.pgidentifier("magic") self.assertEqual(a, postgresql.AsIs('"magic"'))
def test_pgidentifier(self): a = postgresql.pgidentifier('magic') self.assertEqual(a, postgresql.AsIs('"magic"'))