Skip to content

Conversation

@ilongin
Copy link
Contributor

@ilongin ilongin commented Jan 5, 2026

Simple DB automatic migration for SQLite to add new columns to existing DB.
Note that this code doesn't cover:

  1. Altering existing columns
  2. Removing columns

Migration runs on every SQLite DB initialization but it is fast enough not to create overhead (there is a test added that measures performance)

@ilongin ilongin linked an issue Jan 5, 2026 that may be closed by this pull request
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 5, 2026

Deploying datachain with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5a8a102
Status: ✅  Deploy successful!
Preview URL: https://a1409504.datachain-2g6.pages.dev
Branch Preview URL: https://ilongin-1536-local-db-migrat.datachain-2g6.pages.dev

View logs

@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/datachain/data_storage/sqlite.py 83.33% 6 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@ilongin ilongin changed the title Added simple local db automatic migration Added simple local db migration Jan 5, 2026
pyproject.toml Outdated
"ignore::DeprecationWarning:datasets.utils._dill",
"ignore::DeprecationWarning:librosa.core.intervals",
"ignore::FutureWarning:google.api_core._python_version_support", # Python 3.10 EOL warning
"ignore:The default formatters.*will be replaced by ruff:FutureWarning:datamodel_code_generator.*", # Formatter migration warning
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not do this please, properly fix this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in another PR

pyproject.toml Outdated
"pydantic",
"jmespath>=1.0",
"datamodel-code-generator>=0.25",
"datamodel-code-generator>=0.27",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do these changes and Pillow as a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed and merged

@ilongin ilongin requested a review from shcheklein January 7, 2026 14:07
parts.append(f"DEFAULT {default_val}")

column_def = " ".join(parts)
alter_query = f"ALTER TABLE {table_name} ADD COLUMN {column_def}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use sqlalchemy here and not build raw SQL, which is fragile/not safe.

Brief example:

from sqlalchemy.schema import AddColumn

table.append_column(col)
self.execute(AddColumn(table, col))

Haven't checked it but it looks more robust to me, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no AddColumn any more, SQLAlchemy stopped supporting it a while ago since it wasn't stable / portable I guess. Only thing left is to create raw query.

@ilongin ilongin merged commit 35b1b05 into main Jan 8, 2026
35 of 36 checks passed
@ilongin ilongin deleted the ilongin/1536-local-db-migrations branch January 8, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local automatic DB migrations

4 participants