@@ -18,20 +18,26 @@ def cli(verbose):
1818@click .option ('--schema-only' , is_flag = True , help = "Only export database schema, not data" )
1919@click .option ('--skip-export' , is_flag = True , help = "Skip the export step (use existing dump)" )
2020@click .option ('--skip-clean' , is_flag = True , help = "Skip the cleaning step" )
21- def migrate (cloudsql_password , schema_only , skip_export , skip_clean ):
21+ @click .option ('--source-schema' , help = "Source schema in CloudSQL to export" )
22+ @click .option ('--target-schema' , help = "Target schema in Supabase to import into" )
23+ def migrate (cloudsql_password , schema_only , skip_export , skip_clean , source_schema , target_schema ):
2224 """Run full migration from CloudSQL to Supabase"""
2325 try :
2426 if not skip_export :
25- export .export_cloudsql (password = cloudsql_password , schema_only = schema_only )
27+ export .export_cloudsql (
28+ password = cloudsql_password ,
29+ schema_only = schema_only ,
30+ schema = source_schema
31+ )
2632 else :
2733 logger .info ("Skipping export step" )
2834
2935 if not skip_clean :
30- clean .clean_dump_file ()
36+ clean .clean_dump_file (target_schema = target_schema )
3137 else :
3238 logger .info ("Skipping clean step" )
3339
34- import_ .import_to_supabase ()
40+ import_ .import_to_supabase (schema = target_schema )
3541 click .echo ("Migration completed successfully!" )
3642
3743 except Exception as e :
@@ -42,10 +48,15 @@ def migrate(cloudsql_password, schema_only, skip_export, skip_clean):
4248@cli .command ()
4349@click .option ('--cloudsql-password' , help = "CloudSQL password (if not provided, will prompt)" )
4450@click .option ('--schema-only' , is_flag = True , help = "Only export database schema, not data" )
45- def backup (cloudsql_password , schema_only ):
51+ @click .option ('--schema' , help = "Specific schema to export (default: public)" )
52+ def backup (cloudsql_password , schema_only , schema ):
4653 """Only export CloudSQL to a dump file"""
4754 try :
48- dump_file = export .export_cloudsql (password = cloudsql_password , schema_only = schema_only )
55+ dump_file = export .export_cloudsql (
56+ password = cloudsql_password ,
57+ schema_only = schema_only ,
58+ schema = schema
59+ )
4960 click .echo (f"Backup completed successfully! File saved to: { dump_file } " )
5061 except Exception as e :
5162 logger .error (f"Backup failed: { str (e )} " )
@@ -55,13 +66,14 @@ def backup(cloudsql_password, schema_only):
5566@cli .command ()
5667@click .option ('--input-file' , '-i' , type = click .Path (exists = True ), help = "Input SQL dump file" )
5768@click .option ('--output-file' , '-o' , type = click .Path (), help = "Output cleaned SQL file" )
58- def clean_dump (input_file , output_file ):
69+ @click .option ('--target-schema' , help = "Target schema in Supabase to import into" )
70+ def clean_dump (input_file , output_file , target_schema ):
5971 """Clean a SQL dump file for Supabase compatibility"""
6072 try :
6173 input_path = Path (input_file ) if input_file else None
6274 output_path = Path (output_file ) if output_file else None
6375
64- result_file = clean .clean_dump_file (input_path , output_path )
76+ result_file = clean .clean_dump_file (input_path , output_path , target_schema )
6577 click .echo (f"Cleaning completed successfully! File saved to: { result_file } " )
6678 except Exception as e :
6779 logger .error (f"Cleaning failed: { str (e )} " )
@@ -70,11 +82,12 @@ def clean_dump(input_file, output_file):
7082
7183@cli .command ()
7284@click .option ('--input-file' , '-i' , type = click .Path (exists = True ), help = "Input SQL dump file to import" )
73- def import_db (input_file ):
85+ @click .option ('--schema' , help = "Target schema in Supabase to import into" )
86+ def import_db (input_file , schema ):
7487 """Import a cleaned SQL dump file into Supabase"""
7588 try :
7689 input_path = Path (input_file ) if input_file else None
77- import_ .import_to_supabase (input_path )
90+ import_ .import_to_supabase (input_path , schema = schema )
7891 click .echo ("Import completed successfully!" )
7992 except Exception as e :
8093 logger .error (f"Import failed: { str (e )} " )
@@ -98,4 +111,4 @@ def validate():
98111
99112 except Exception as e :
100113 click .echo (f"Configuration error: { str (e )} " , err = True )
101- exit (1 )
114+ exit (1 )
0 commit comments