schema: do not try to create the table if it already exists
1 files changed, 13 insertions(+), 1 deletions(-)

M dbcache/schema.py
M dbcache/schema.py +13 -1
@@ 15,4 15,16 @@ def init(engine, ns='cache', drop=False)
             )
 
     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.')