Skip to content

Commit

Permalink
Add drop support for SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyMcCormick committed Jul 30, 2024
1 parent 4a221d2 commit 2b5dfba
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion python/felis/db/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ def initialize(self) -> None:
raise ValueError(f"PostgreSQL schema '{schema_name}' already exists.")
logger.debug(f"Creating PG schema: {schema_name}")
self.conn.execute(CreateSchema(schema_name))
elif self.dialect_name == "sqlite":
# Just silently ignore this operation for SQLite. The database
# will still be created if it does not exist and the engine
# URL is valid.
pass
else:
raise ValueError(f"Initialization not supported for: {self.dialect_name}")
except SQLAlchemyError as e:
logger.error(f"Error creating schema: {e}")
raise
Expand All @@ -285,8 +292,12 @@ def drop(self) -> None:
elif self.dialect_name == "postgresql":
logger.debug(f"Dropping PostgreSQL schema if exists: {schema_name}")
self.conn.execute(DropSchema(schema_name, if_exists=True, cascade=True))
elif self.dialect_name == "sqlite":
if isinstance(self.engine, Engine):
logger.debug("Dropping tables in SQLite schema")
self.metadata.drop_all(bind=self.engine)
else:
raise ValueError(f"Unsupported database type: {self.dialect_name}")
raise ValueError(f"Drop operation not supported for: {self.dialect_name}")
except SQLAlchemyError as e:
logger.error(f"Error dropping schema: {e}")
raise
Expand Down

0 comments on commit 2b5dfba

Please sign in to comment.