@@ -7,6 +7,7 @@ use thiserror::Error;
77use tokio:: { select, signal:: ctrl_c} ;
88use tracing:: error;
99
10+ use crate :: backend:: schema:: sync:: config:: ShardConfig ;
1011use crate :: backend:: schema:: sync:: pg_dump:: { PgDump , SyncState } ;
1112use crate :: backend:: { databases:: databases, replication:: logical:: Publisher } ;
1213use crate :: config:: { Config , Users } ;
@@ -94,19 +95,13 @@ pub enum Commands {
9495 /// Source database name.
9596 #[ arg( long) ]
9697 from_database : String ,
97- /// Source user name.
98- #[ arg( long) ]
99- from_user : String ,
10098 /// Publication name.
10199 #[ arg( long) ]
102100 publication : String ,
103101
104102 /// Destination database.
105103 #[ arg( long) ]
106104 to_database : String ,
107- /// Destination user name.
108- #[ arg( long) ]
109- to_user : String ,
110105
111106 /// Dry run. Print schema commands, don't actually execute them.
112107 #[ arg( long) ]
@@ -120,6 +115,14 @@ pub enum Commands {
120115 #[ arg( long) ]
121116 data_sync_complete : bool ,
122117 } ,
118+
119+ /// Perform cluster configuration steps
120+ /// required for sharded operations.
121+ Setup {
122+ /// Database name.
123+ #[ arg( long) ]
124+ database : String ,
125+ } ,
123126}
124127
125128/// Fingerprint some queries.
@@ -251,17 +254,15 @@ pub async fn schema_sync(commands: Commands) -> Result<(), Box<dyn std::error::E
251254 let ( source, destination, publication, dry_run, ignore_errors, data_sync_complete) =
252255 if let Commands :: SchemaSync {
253256 from_database,
254- from_user,
255257 to_database,
256- to_user,
257258 publication,
258259 dry_run,
259260 ignore_errors,
260261 data_sync_complete,
261262 } = commands
262263 {
263- let source = databases ( ) . cluster ( ( from_user . as_str ( ) , from_database. as_str ( ) ) ) ?;
264- let dest = databases ( ) . cluster ( ( to_user . as_str ( ) , to_database. as_str ( ) ) ) ?;
264+ let source = databases ( ) . schema_owner ( & from_database) ?;
265+ let dest = databases ( ) . schema_owner ( & to_database) ?;
265266
266267 (
267268 source,
@@ -283,6 +284,10 @@ pub async fn schema_sync(commands: Commands) -> Result<(), Box<dyn std::error::E
283284 SyncState :: PreData
284285 } ;
285286
287+ if state == SyncState :: PreData {
288+ ShardConfig :: sync_all ( & destination) . await ?;
289+ }
290+
286291 for output in output {
287292 if dry_run {
288293 let queries = output. statements ( state) ?;
@@ -296,3 +301,12 @@ pub async fn schema_sync(commands: Commands) -> Result<(), Box<dyn std::error::E
296301
297302 Ok ( ( ) )
298303}
304+
305+ pub async fn setup ( database : & str ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
306+ let databases = databases ( ) ;
307+ let schema_owner = databases. schema_owner ( database) ?;
308+
309+ ShardConfig :: sync_all ( & schema_owner) . await ?;
310+
311+ Ok ( ( ) )
312+ }
0 commit comments