Skip to content

Conversation

@Manan007224
Copy link
Contributor

@Manan007224 Manan007224 commented Jun 15, 2021

This is an experimental feature in ghostferry to migrate tables with foreign key constraints.

Most of the features are explained in this doc - https://github.com/Shopify/ghostferry/blob/4ea968d2aa702593a4c1ee0f71260333ed88982d/docs/source/copydbforeignkey.rst

@Manan007224 Manan007224 marked this pull request as draft June 15, 2021 08:33
@Manan007224 Manan007224 changed the title [Experimental] Migrating data with foreign key constraints [POC] Migrating data with foreign key constraints Jun 16, 2021
refer to an issue in ghostferry instead of an internal one
@Manan007224 Manan007224 force-pushed the table-creation-priority-order branch from a408db1 to 988e6b2 Compare June 16, 2021 21:45
@Manan007224 Manan007224 requested a review from shuhaowu June 16, 2021 21:46
logrus.Info("creating databases and tables on target")
for _, tableName := range this.Ferry.Tables.GetTableListWithPriority(this.config.TablesToBeCreatedFirst) {
logger.Info("creating databases and tables on target")
var prioritzedTableNames []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var prioritzedTableNames []string
var prioritizedTableNames []string

return
}

func (c TableSchemaCache) GetTableCreationOrder(db *sql.DB) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change the name so it doesn't seem like a generic order that people should follow?

Suggested change
func (c TableSchemaCache) GetTableCreationOrder(db *sql.DB) ([]string, error) {
func (c TableSchemaCache) GetTableCreationOrderForFKConstraints(db *sql.DB) ([]string, error) {


for table := range c {
if _, found := visitedTables[table]; !found {
visitedTables, tableOrder = getTableCreationOrderUtil(visitedTables, tableOrder, tableMap, table)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document how this algorithm is supposed to work (in either comments attached to a function here, or via a separate document)? It looks feasible to trace through myself, but it's better for a non-trivial algorithm to have its intent documented, so reviewers can focus on if the implementation is right or wrong, not reverse engineering what you're trying to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants