Skip to content

Commit

Permalink
refactor(GODT-2522): More error description to catch migration issues
Browse files Browse the repository at this point in the history
  • Loading branch information
LBeernaertProton committed Jun 28, 2023
1 parent ccfbcb7 commit c7380a7
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions internal/db_impl/sqlite3/v1/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (m Migration) Run(ctx context.Context, tx utils.QueryWrapper, generator ima

// Migrate Mailboxes.
if err := migrateMailboxes(ctx, tx, generator); err != nil {
return fmt.Errorf("failed to migrate mailboxes: %w", err)
return err
}

// Migrate Mailbox Messages.
Expand All @@ -49,7 +49,7 @@ func migrateMailboxes(ctx context.Context, tx utils.QueryWrapper, generator imap
)

if _, err := utils.ExecQuery(ctx, tx, query); err != nil {
return err
return fmt.Errorf("failed to create mailboxes table: %w", err)
}
}

Expand All @@ -67,7 +67,7 @@ func migrateMailboxes(ctx context.Context, tx utils.QueryWrapper, generator imap
)

if _, err := utils.ExecQuery(ctx, tx, query); err != nil {
return err
return fmt.Errorf("failed to create mailboxes flags table: %w", err)
}
}

Expand All @@ -85,7 +85,7 @@ func migrateMailboxes(ctx context.Context, tx utils.QueryWrapper, generator imap
)

if _, err := utils.ExecQuery(ctx, tx, query); err != nil {
return err
return fmt.Errorf("failed to create mailboxes perm flags table: %w", err)
}
}

Expand All @@ -103,7 +103,7 @@ func migrateMailboxes(ctx context.Context, tx utils.QueryWrapper, generator imap
)

if _, err := utils.ExecQuery(ctx, tx, query); err != nil {
return err
return fmt.Errorf("failed to create mailboxes attr table: %w", err)
}
}

Expand All @@ -124,7 +124,7 @@ func migrateMailboxes(ctx context.Context, tx utils.QueryWrapper, generator imap
)

if _, err := utils.ExecQuery(ctx, tx, query); err != nil {
return err
return fmt.Errorf("failed to create messages to mailboxes table: %w", err)
}
}

Expand All @@ -133,7 +133,7 @@ func migrateMailboxes(ctx context.Context, tx utils.QueryWrapper, generator imap

mailboxes, err := utils.MapQueryRowsFn(ctx, tx, loadExistingQuery, scanMailboxV0)
if err != nil {
return err
return fmt.Errorf("failed to read existing mailboxes: %w", err)
}

for _, chunk := range xslices.Chunk(mailboxes, db.ChunkLimit) {
Expand Down Expand Up @@ -167,7 +167,7 @@ func migrateMailboxes(ctx context.Context, tx utils.QueryWrapper, generator imap
query := CreateMailboxMessageTableQuery(mboxID)

if _, err := utils.ExecQuery(ctx, tx, query); err != nil {
return err
return fmt.Errorf("failed to create mailbox messages table (%v): %w", mboxID, err)
}
}
}
Expand Down Expand Up @@ -202,7 +202,7 @@ func migrateMailboxes(ctx context.Context, tx utils.QueryWrapper, generator imap
MailboxFlagsFieldMailboxID,
MailboxFlagsFieldValue,
); err != nil {
return err
return fmt.Errorf("failed to copy mailbox flags: %w", err)
}

// Copy mailbox perm flags.
Expand All @@ -217,7 +217,7 @@ func migrateMailboxes(ctx context.Context, tx utils.QueryWrapper, generator imap
MailboxPermFlagsFieldMailboxID,
MailboxPermFlagsFieldValue,
); err != nil {
return err
return fmt.Errorf("failed to copy mailbox perm flags: %w", err)
}

// Copy mailbox attributes.
Expand All @@ -232,10 +232,14 @@ func migrateMailboxes(ctx context.Context, tx utils.QueryWrapper, generator imap
MailboxAttrsFieldMailboxID,
MailboxAttrsFieldValue,
); err != nil {
return err
return fmt.Errorf("failed to copy mailbox attr: %w", err)
}

return migrateMailboxMessages(ctx, tx, oldToNewIDMap)
if err := migrateMailboxMessages(ctx, tx, oldToNewIDMap); err != nil {
return fmt.Errorf("failed to migrate mailbox messages: %w", err)
}

return nil
}

func migrateMessagesAndFlags(ctx context.Context, tx utils.QueryWrapper) error {
Expand Down

0 comments on commit c7380a7

Please sign in to comment.