Auto-create schema if it does not exist
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -66,6 +66,9 @@ class Importer:
|
|||||||
def _ensure_table(self, conn, df: pd.DataFrame, cfg: SheetConfig):
|
def _ensure_table(self, conn, df: pd.DataFrame, cfg: SheetConfig):
|
||||||
schema, table_name = _split_table(cfg.target_table)
|
schema, table_name = _split_table(cfg.target_table)
|
||||||
insp = inspect(conn)
|
insp = inspect(conn)
|
||||||
|
if schema and schema not in insp.get_schema_names():
|
||||||
|
conn.execute(text(f"CREATE SCHEMA {schema}"))
|
||||||
|
logger.info("Created schema %r", schema)
|
||||||
if not insp.has_table(table_name, schema=schema):
|
if not insp.has_table(table_name, schema=schema):
|
||||||
meta = MetaData()
|
meta = MetaData()
|
||||||
cols = build_columns(df, cfg.columns, self.config.default_varchar_length)
|
cols = build_columns(df, cfg.columns, self.config.default_varchar_length)
|
||||||
|
|||||||
Reference in New Issue
Block a user