Skip to content

Commit

Permalink
Add support for bare tables in the bootstrap tool
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffxy committed Oct 23, 2024
1 parent 3b5d5d7 commit db7048d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/brad/admin/bootstrap_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def register_admin_action(subparser) -> None:
help="Set this flag to avoid persisting the blueprint. "
"Only meant to be used if you know what you are doing!",
)
parser.add_argument(
"--bare-aurora-tables",
action="store_true",
help="If set, do not create the shadow tables and triggers "
"for Aurora. Only meant to be used if you know what you are doing!",
)
parser.set_defaults(admin_action=bootstrap_schema)


Expand Down Expand Up @@ -100,15 +106,17 @@ def bootstrap_schema(args):
table.name,
location,
)
queries, db_type = sql_gen.generate_create_table_sql(table, location)
queries, db_type = sql_gen.generate_create_table_sql(
table, location, args.bare_aurora_tables
)
conn = cxns.get_connection(db_type)
cursor = conn.cursor_sync()
for q in queries:
logger.debug("Running on %s: %s", str(db_type), q)
cursor.execute_sync(q)

# 7. Create and set up the extraction progress table.
if Engine.Aurora in engines_filter:
if Engine.Aurora in engines_filter and not args.bare_aurora_tables:
queries, db_type = sql_gen.generate_extraction_progress_set_up_table_sql()
conn = cxns.get_connection(db_type)
cursor = conn.cursor_sync()
Expand Down
7 changes: 5 additions & 2 deletions src/brad/blueprint/sql_gen/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ def __init__(self, config: ConfigFile, blueprint: Blueprint):
self._blueprint = blueprint

def generate_create_table_sql(
self, table: Table, location: Engine
self, table: Table, location: Engine, bare_aurora_tables: bool = False
) -> Tuple[List[str], Engine]:
"""
Returns SQL queries that should be used to create `table` on `location`,
along with the engine on which to execute the queries.
"""

if location == Engine.Aurora:
if table.name in self._blueprint.base_table_names():
if (
not bare_aurora_tables
and table.name in self._blueprint.base_table_names()
):
# This table needs to support incremental extraction. We need to
# create several additional structures to support this extraction.
columns_with_types = comma_separated_column_names_and_types(
Expand Down

0 comments on commit db7048d

Please sign in to comment.