diff --git a/Makefile b/Makefile index 77f7c12..0cf9a5d 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/subsetter/sync.go b/subsetter/sync.go index e834372..356d798 100644 --- a/subsetter/sync.go +++ b/subsetter/sync.go @@ -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") + } } } }