I am trying to use bulk_insert
to insert data into an existing table (services
) in my Postgres database. How do I instantiate this table object so I can do a bulk_insert with it?
I saw answers like this: Alembic bulk_insert to table with schema but I want to avoid redefining the schema again in the migration.
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
"""Up migration."""
services = sa.MetaData().Services()
op.bulk_insert(services,
[
{
'id': 88,
'name':'Test 1',
'is_active': 'true',
'include_in_broker_fee': 'true',
'is_domestic': 'true',
'is_international': 'true'
},
{
'id': 89,
'name':'Test 2',
'is_active': 'true',
'include_in_broker_fee': 'true',
'is_domestic': 'true',
'is_international': 'true'
}
])