# HG changeset patch # User Aurélien Campéas # Date 1676300204 -3600 # Mon Feb 13 15:56:44 2023 +0100 # Node ID c96827c97629004bc555d129521eed8dd557d0ad # Parent 9c998b46463743f9e24342e059107f8084d73a89 schema: do not try to create the table if it already exists diff --git a/dbcache/schema.py b/dbcache/schema.py --- a/dbcache/schema.py +++ b/dbcache/schema.py @@ -15,4 +15,16 @@ ) with engine.begin() as cn: - cn.execute(sqlfile(SQLFILE, ns=ns)) + exists = cn.execute( + 'select exists (' + ' select from information_schema.tables ' + ' where table_schema = %(schema_name)s and' + ' table_name = %(table_name)s' + ')', + schema_name=ns, + table_name='things' + ).scalar() + if not exists: + cn.execute(sqlfile(SQLFILE, ns=ns)) + else: + print(f'dbcache: "{ns}"."things" already exists.')