Utility script to create schema

July 22, 2024

def create_schemas(session, schemas: List[SchemaName]):
    schema_names = {s.value for s in schemas}
    current_schema_names = set(session.bind.dialect.get_schema_names(session))
 
    required_schema_names = schema_names - current_schema_names
 
    for schema_name in required_schema_names:
        session.execute(sa.schema.CreateSchema(schema_name))
        session.commit()
 
    created = len(required_schema_names) > 0
    return created