(cfg, eng, ident)
| 26 | |
| 27 | @create_db.for_db("postgresql") |
| 28 | def _pg_create_db(cfg, eng, ident): |
| 29 | template_db = cfg.options.postgresql_templatedb |
| 30 | |
| 31 | with eng.execution_options(isolation_level="AUTOCOMMIT").begin() as conn: |
| 32 | if not template_db: |
| 33 | template_db = conn.exec_driver_sql( |
| 34 | "select current_database()" |
| 35 | ).scalar() |
| 36 | |
| 37 | attempt = 0 |
| 38 | while True: |
| 39 | try: |
| 40 | conn.exec_driver_sql( |
| 41 | "CREATE DATABASE %s TEMPLATE %s" % (ident, template_db) |
| 42 | ) |
| 43 | except exc.OperationalError as err: |
| 44 | attempt += 1 |
| 45 | if attempt >= 3: |
| 46 | raise |
| 47 | if "accessed by other users" in str(err): |
| 48 | log.info( |
| 49 | "Waiting to create %s, URI %r, " |
| 50 | "template DB %s is in use sleeping for .5", |
| 51 | ident, |
| 52 | eng.url, |
| 53 | template_db, |
| 54 | ) |
| 55 | time.sleep(0.5) |
| 56 | except: |
| 57 | raise |
| 58 | else: |
| 59 | break |
| 60 | |
| 61 | |
| 62 | @drop_db.for_db("postgresql") |
nothing calls this directly
no test coverage detected