Update changes, refactor drop_database

This commit is contained in:
Konsta Vesterinen
2014-10-29 14:21:29 +02:00
parent 7cb1f317d4
commit 8b629be1db
2 changed files with 10 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ Here you can see the full list of changes between each SQLAlchemy-Utils release.
^^^^^^^^^^^^^^^^^^^
- Fixed assert_max_length not working with non nullable columns
- Add PostgreSQL < 9.2 support for drop_database
0.27.5 (2014-10-24)

View File

@@ -399,8 +399,15 @@ def drop_database(url):
engine.raw_connection().set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
# Disconnect all users from the database we are dropping.
version = list(map(int, engine.execute('SHOW server_version;').first()[0].split('.')))
pid_column = 'pid' if (version[0] >= 9 and version[1] >= 2) else 'procpid'
version = list(
map(
int,
engine.execute('SHOW server_version;').first()[0].split('.')
)
)
pid_column = (
'pid' if (version[0] >= 9 and version[1] >= 2) else 'procpid'
)
text = '''
SELECT pg_terminate_backend(pg_stat_activity.%(pid_column)s)
FROM pg_stat_activity