Skip to content

Migrate external table to enum column #3196

Answered by simolus3
Andres-Parra2610 asked this question in Q&A
Discussion options

You must be logged in to vote

I assume MeasureUnits currently has an id column as well, right? Assuming that Products also has an id column, a migration could look like this:

final innerProducts = products.createAlias('i');
// For each product we're about to select from in the TableMigration step, resolve the measurement name based on the current measurement id:
final unitNameFromId = subqueryExpression(selectOnly(measureUnits)
  ..addColumns([measureUnits.name])
  ..join([
    innerJoin(innerProducts,
        innerProducts.measureUnitId.equalsExp(measureUnits.id))
  ])
  ..where(innerProducts.id.equalsExp(products.id)));

await m.alterTable(TableMigration(
  products,
  newColumns: {products.unitName},
  columnTransf…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Andres-Parra2610
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants