Skip to content

Commit 5f561be

Browse files
authored
Add --cutover flag to schema-sync (#608)
1 parent 46b4869 commit 5f561be

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

integration/schema_sync/dev.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ ${PGDOG_BIN_PATH} \
2424
--publication pgdog \
2525
--data-sync-complete
2626

27+
${PGDOG_BIN_PATH} \
28+
schema-sync \
29+
--from-database source \
30+
--to-database destination \
31+
--publication pgdog \
32+
--cutover
33+
2734
pg_dump \
2835
--schema-only \
2936
--exclude-schema pgdog \

pgdog/src/backend/schema/sync/pg_dump.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl PgDumpOutput {
367367
sequence,
368368
sql: original,
369369
});
370-
} else {
370+
} else if state == SyncState::Cutover {
371371
let sql = sequence
372372
.setval_from_column(&column)
373373
.map_err(|_| Error::MissingEntity)?;
@@ -438,10 +438,12 @@ impl PgDumpOutput {
438438

439439
NodeEnum::AlterOwnerStmt(stmt) => {
440440
if stmt.object_type() != ObjectType::ObjectPublication {
441-
result.push(Statement::Other {
442-
sql: original.to_string(),
443-
idempotent: true,
444-
});
441+
if state == SyncState::PreData {
442+
result.push(Statement::Other {
443+
sql: original.to_string(),
444+
idempotent: true,
445+
});
446+
}
445447
}
446448
}
447449

pgdog/src/cli.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ pub enum Commands {
126126
/// Data sync has been complete.
127127
#[arg(long)]
128128
data_sync_complete: bool,
129+
130+
/// Execute cutover statements.
131+
#[arg(long)]
132+
cutover: bool,
129133
},
130134

131135
/// Perform cluster configuration steps
@@ -271,14 +275,15 @@ pub async fn data_sync(commands: Commands) -> Result<(), Box<dyn std::error::Err
271275

272276
#[allow(clippy::print_stdout)]
273277
pub async fn schema_sync(commands: Commands) -> Result<(), Box<dyn std::error::Error>> {
274-
let (source, destination, publication, dry_run, ignore_errors, data_sync_complete) =
278+
let (source, destination, publication, dry_run, ignore_errors, data_sync_complete, cutover) =
275279
if let Commands::SchemaSync {
276280
from_database,
277281
to_database,
278282
publication,
279283
dry_run,
280284
ignore_errors,
281285
data_sync_complete,
286+
cutover,
282287
} = commands
283288
{
284289
let source = databases().schema_owner(&from_database)?;
@@ -291,6 +296,7 @@ pub async fn schema_sync(commands: Commands) -> Result<(), Box<dyn std::error::E
291296
dry_run,
292297
ignore_errors,
293298
data_sync_complete,
299+
cutover,
294300
)
295301
} else {
296302
return Ok(());
@@ -300,6 +306,8 @@ pub async fn schema_sync(commands: Commands) -> Result<(), Box<dyn std::error::E
300306
let output = dump.dump().await?;
301307
let state = if data_sync_complete {
302308
SyncState::PostData
309+
} else if cutover {
310+
SyncState::Cutover
303311
} else {
304312
SyncState::PreData
305313
};

0 commit comments

Comments
 (0)