-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add documentation about DB migration
- Loading branch information
1 parent
0fc70ef
commit 16c865f
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Database migrations | ||
|
||
We use [peewee_migrate](https://github.com/klen/peewee_migrate) to handle our SQL database migrations. | ||
|
||
## Create a migration | ||
|
||
You should create a migration if you update the SQL database schema. | ||
To create a new migration, use: | ||
|
||
`make robotoff-cli args='create-migration MIGRATION_NAME --auto'` | ||
|
||
You should use an identifiable name (such as "add_bounding_box") to the migration. | ||
|
||
The `--auto` flag is used to ask `peewee_migrate` to scan all table definitions in the source code and create the migration file | ||
automatically. You can skip it if you want `peewee_migrate` to create a blank migration file. | ||
|
||
|
||
## Apply the migration | ||
|
||
To apply all pending migrations, use: | ||
|
||
`make migrate-db` | ||
|
||
|
||
## What if I had a previous installation of Robotoff with an initialized DB? | ||
|
||
You should then create yourself the migration table: | ||
|
||
```sql | ||
CREATE TABLE IF NOT EXISTS "migratehistory" | ||
( | ||
"id" SERIAL NOT NULL PRIMARY KEY, | ||
"name" VARCHAR(255) NOT NULL, | ||
"migrated_at" TIMESTAMP NOT NULL | ||
) | ||
``` | ||
|
||
Then add manually the the initial migration file in database: | ||
|
||
```sql | ||
INSERT INTO "migratehistory" VALUES (1, '001_initial', CURRENT_TIMESTAMP); | ||
``` | ||
|
||
Then you can apply remaining migrations with `make migrate-db`. |