Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] Migrating data with foreign key constraints #288

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

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
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

@@ -342,6 +342,75 @@ func (c TableSchemaCache) GetTableListWithPriority(priorityList []string) (prior
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