simonw / sqlite-migrate Goto Github PK
View Code? Open in Web Editor NEWA simple database migration system for SQLite, based on sqlite-utils
License: Apache License 2.0
A simple database migration system for SQLite, based on sqlite-utils
License: Apache License 2.0
I'm going to test this with a fresh install of
llm
to make sure it doesn't break.Although... here's an interesting callenge with LLM: I frequently run many different copies of it against the same
llm.db
database stashed away in my~/Library/Application Support
folder.It's perfectly possible I'll run an
LLM
upgraded instance which will upgrade the database... but then re-run an older version against the same DB in a way that will break things.
Originally posted by @simonw in #6 (comment)
Lint failure: https://github.com/simonw/sqlite-migrate/actions/runs/8270287510/job/22627467914
4 files would be left unchanged.
warning: `ruff <path>` is deprecated. Use `ruff check <path>` instead.
tests/test_sqlite_migrate.py:78:11: F841 Local variable `db` is assigned to but never used
Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
Error: Process completed with exit code 1.
README currently just talks about the CLI.
See here:
Should be able to do this:
sqlite-utils migrate data.db path/to/migrations.py
As an alternative to the current automatic discovery.
Should provide more examples, and cover things like the --list
command.
In writing a test for a migration for this issue:
I realized I wanted to apply migrations up to a specific point, then run some test code, then apply the rest.
I think .apply()
should take an optional second argument, stop_before="name"
.
Currently:
sqlite-utils migrate data.db --list
Pending migrations for data.db:
For LLM I got into a habit of doing this:
@migration()
def m001_create_table(db):
# db is a sqlite-utils Database instance
db["creatures"].create(
{"id": int, "name": str, "species": str},
pk="id"
)
@migration()
def m002_add_weight(db):
# db is a sqlite-utils Database instance
db["creatures"].add_column("weight", float)
Because I was using the function names as the primary key in the database and I wanted them to naturally be displayed in the correct order in Datasette.
I can do better than that.
I had to add this to mypy.ini
in LLM:
[mypy-sqlite_migrate.*]
ignore_missing_imports = True
Discovered when I had two separate migrations with different migration_set
names but the same step name.
The first migration:
from sqlite_migrate import Migrations
m1 = Migrations("m1")
@m1()
def m001_init(db):
pass
The second:
from sqlite_migrate import Migrations
m2 = Migrations("m2")
@m2()
def m001_init(db):
pass
The m1.m001_init()
step runs successfully, but m2.m001_init()
is skipped. This is because they share the same step name m001_init
, but they should have a different namespace anyway.
Caused by this, I think:
sqlite-migrate/sqlite_migrate/__init__.py
Line 51 in 82f3459
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.