I'm using alembic to create a new column in a mysql table. The table has a column source_list
that is json
{"sources": ["source1" "source2"]}
I want to create a new column, sources
, that is a pipe-delimited concatenation of the list items.
"source1|source2"
There is a variable number of sources in the sources list.
The alembic upgrade call would be something like this.
def upgrade():
op.add_column(
"table_name",
sa.Column(
"sources",
sa.String(32, collation="utf8mb4_unicode_ci"),
server_default=sa.Computed("source_list->>'$.sources[0]'"),
),
)
This would create a sources
column with the 0th element of the source_list
json.
How do I get this computed column of a pipe-delimited concatenation of all the elements in that list?