Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extremely simple migration system #23

Closed
simonw opened this issue Oct 17, 2019 · 2 comments
Closed

Extremely simple migration system #23

simonw opened this issue Oct 17, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Collaborator

simonw commented Oct 17, 2019

Needed for #12. This is going to be an incredibly simple version of the Django migration system.

  • A migrations table, keeping track of which migrations were applied (and when)
  • A migrate() function which applies any pending migrations
  • A MIGRATIONS constant which is a list of functions to be applied

The function names will be detected and used as the names of the migrations.

Every time you run the CLI tool it will call the migrate() function before doing anything else.

Needs to take into account that there might be no tables at all. As such, migration functions should sanity check that the tables they are going to work on actually exist.

@simonw simonw added the enhancement New feature or request label Oct 17, 2019
@simonw
Copy link
Collaborator Author

simonw commented Oct 17, 2019

Thinking about this further: the concept of migrations may end up being in direct conflict with the sqlite-utils concept of creating tables on demand the first time they are used - and of creating table schemas automatically to fit the shape of the JSON that is being inserted into them.

I'm going to forge ahead anyway and build this because I think it will be an interesting exploration, but it's very likely this turns out to be a bad idea in the long run!

@simonw
Copy link
Collaborator Author

simonw commented Oct 17, 2019

Migrations will run only if you open a database that previously existed (as opposed to opening a brand new empty database).

This means that the first time you run a command against a fresh database, migrations will not run and the migrations table will not be created. The second time you run any command against that database the migrations will execute and populate the migrations table.

This also means that each migration needs to be able to sanity check the database to see if it should run or not. If it should NOT run, it will do nothing but still be marked as having executed by adding to the migrations table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant