From a01b512b6855106f211f513ba40087cb51f94c51 Mon Sep 17 00:00:00 2001 From: secwall Date: Sat, 10 Jul 2021 00:30:14 +0300 Subject: [PATCH] Skip unnecessary schema creation on init --- pgmigrate.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pgmigrate.py b/pgmigrate.py index ae1b632..c8986a9 100644 --- a/pgmigrate.py +++ b/pgmigrate.py @@ -385,10 +385,16 @@ def _init_schema(schema, cursor): """ Create schema_version table """ - LOG.info('creating schema') cursor.execute( - SQL('CREATE SCHEMA IF NOT EXISTS {schema}').format( - schema=Identifier(schema))) + 'SELECT EXISTS(SELECT 1 FROM ' + 'information_schema.schemata ' + 'WHERE schema_name = %s)', (schema, )) + schema_exists = cursor.fetchone()[0] + if not schema_exists: + LOG.info('creating schema') + cursor.execute( + SQL('CREATE SCHEMA IF NOT EXISTS {schema}').format( + schema=Identifier(schema))) LOG.info('creating type schema_version_type') cursor.execute( SQL('CREATE TYPE {schema}.schema_version_type '