Open amb-jarek opened 1 year ago
@amb-jarek Thank you for reporting this. As documented in README, currently the data order of foreign key is not respected.
So to dump the data with expected order, please run spanner-dump
multiple times with --tables
option so that the data order can be manually specified.
For example, the first run with --tables=consumer,account
and the second run with --tables=account_owner
.
Thank you for fast response.
Yep this is exactly what I'm doing right now. But it is rather workaround.
Would be great if I could execute spanner-dump once with preferred order of tabled to dump set in --tables
parameter like:
spanner-dump ... --tables=consumer,account,account_owner
Unfortunately it doesn't work like that and data is dumped alphabetically
Technically it's not an alphabetical order. Currently the parent table is dumped first before child tables are dumped: https://github.com/cloudspannerecosystem/spanner-dump/blob/master/table.go#L55-L65
So interleaved table order is preserved when dumping the data.
It looks data are dumped from tables in alphabetic orders therefore sometimes created dump cannot be imported.
As you see tables itself are created correctly
consumer
,account
,account_owner
But data of those tables are exported in alphabetic order of tables:account
,account_owner
,consumer
This leads to SQL problems during import because data fromaccount_owner
is trying to set foreign key toconsumer
table record, but this record doesn't exists yet