sqlalchemy / sqlalchemy/alembic

support sqlite date casts in batch mode under sqlite.cast_for_batch_migrate, or at least a hook

Open
#1,033 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

batch migrations sqlite use case
Dominant language
Python
Stars
4.4k
Forks
375
PR merge metrics
No merged PRs in 30d

Description

I am trying to migrate a column from type Date to type Datetime. Here the migration script:

from alembic import op
import sqlalchemy as sa

def upgrade():
with op.batch_alter_table('col_1', schema=None) as batch_op:
batch_op.alter_column('date',
existing_type=sa.DATE,
type_=sa.DateTime,
existing_nullable=False)

I would expect the new column to contain text of the ISO8601 format ( I am operating on an SQLite database).

Running the upgrade command the migration does not throw any exception. Here the stdout:
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> 0a2d90c1423d, empty message

The modified column after contains only the year instead, i.e. 4 characters.

I am running:

  • OS: Ubuntu 20.04.4 LTS
  • Python: 3.9.12
  • Alembic: 1.7.7
  • SQLAlchemy: 1.4.36

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Date-to-DateTime migration with SQLite and inspect the batch_alter_table path around sqlite.cast_for_batch_migrate. Determine whether the conversion can preserve ISO8601 date text or needs an exposed hook, then add coverage for the migration behavior and document what is supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlalchemy, sqlite
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.