Skip to content

Commit

Permalink
Enable relation copy for complex tables
Browse files Browse the repository at this point in the history
  • Loading branch information
dz0ny committed Nov 11, 2024
1 parent 5e76c96 commit 34969cc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ PACKAGE=niteo.co/subsetter

.PHONY: run
run:
go run "${PACKAGE}/$(filter-out $@,$(MAKECMDGOALS))"
go run ./cli -src "postgres://test_source@localhost:5432/test_source?sslmode=disable" -dst "postgres://test_target@localhost:5432/test_target?sslmode=disable" \
-f 0.5 \
--include "users:id='fd7e087d-67cf-4f05-902e-29ec6212f412'" \
--exclude domains \
--exclude domains_godaddy \
--exclude domains_whoisfreaks \
--exclude domains_dropcatch \
--exclude domains_namesilo \
--exclude domains_sedo \
--exclude domains_namecheap \
--exclude domains_snapnames

.PHONY: up
up:
process-compose up -t=false -p=0

.PHONY: is-postgres-running
is-postgres-running:
Expand Down
17 changes: 16 additions & 1 deletion subsetter/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,22 @@ func (s *Sync) CopyTables(tables []Table) (err error) {

for _, include := range s.include {
if include.Table == complexTable.Name {
log.Warn().Str("table", complexTable.Name).Msgf("Transferring forced rows for relational table is not supported.")
// Copy only primary row by first setting ignore relational checks
_, err := s.destination.Exec(context.Background(), fmt.Sprintf("ALTER TABLE %s DISABLE TRIGGER USER;", complexTable.Name))
if err != nil {
return errors.Wrap(err, "Error setting session_replication_role to replica")
}

err = include.Copy(s)
if err != nil {
return errors.Wrapf(err, "Error copying forced rows for table %s", complexTable.Name)
}

// Set relational checks back
_, err = s.destination.Exec(context.Background(), fmt.Sprintf("ALTER TABLE %s ENABLE TRIGGER USER;", complexTable.Name))
if err != nil {
return errors.Wrap(err, "Error setting session_replication_role to origin")
}
}
}
}
Expand Down

0 comments on commit 34969cc

Please sign in to comment.