Skip to content

Commit 40ad2b4

Browse files
committed
raise exception when calling open(created=False) and store doesn't exist - fixes #23
1 parent 2ac5aa5 commit 40ad2b4

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

rdflib_sqlalchemy/store.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -593,26 +593,25 @@ def open(self, configuration, create=True):
593593
self.engine = sqlalchemy.create_engine(configuration)
594594
with self.engine.connect():
595595
if create:
596-
return self.create_all()
596+
# Create all of the database tables (idempotent)
597+
self.metadata.create_all(self.engine)
597598

598-
def create_all(self):
599+
self.verify_store_exists()
600+
601+
def verify_store_exists(self):
599602
"""
600-
Create all of the database tables.
601-
Will not re-create any tables that already exist.
603+
Verify all tables exist.
604+
If an expected table does not exist, raise an exception.
602605
603606
"""
604-
self.metadata.create_all(self.engine)
605607

606608
inspector = reflection.Inspector.from_engine(self.engine)
607609
existing_table_names = inspector.get_table_names()
608610
for table_name in self.table_names:
609611
if table_name not in existing_table_names:
610612
_logger.critical("create_all() - table %s Doesn't exist!", table_name)
611613
# The database exists, but one of the tables doesn't exist
612-
return 0
613-
614-
# Everything is there (the database and all of the tables)
615-
return 1
614+
raise RuntimeError("Missing table: {}".format(table_name))
616615

617616
def close(self, commit_pending_transaction=False):
618617
"""

0 commit comments

Comments
 (0)