mirror of
https://github.com/borgbase/vorta
synced 2025-01-03 13:45:49 +00:00
Add support for database migrations.
This commit is contained in:
parent
dc2a156855
commit
8bf2c54c38
5 changed files with 46 additions and 0 deletions
|
@ -55,6 +55,8 @@ $ brew cask install qt-creator
|
|||
$ brew install qt
|
||||
```
|
||||
|
||||
[Peewee Migrate](https://github.com/klen/peewee_migrate) is used to manage database migrations. Add them to the `vorta.migrations` package.
|
||||
|
||||
To build a binary package:
|
||||
```
|
||||
$ pyinstaller --clean --noconfirm vorta.spec
|
||||
|
|
|
@ -41,6 +41,7 @@ install_requires =
|
|||
python-dateutil
|
||||
keyring
|
||||
borgbackup
|
||||
peewee_migrate
|
||||
|
||||
[options.extras_require]
|
||||
tests =
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import peewee
|
||||
|
||||
import vorta.models
|
||||
import vorta.migrations
|
||||
from vorta.application import VortaApp
|
||||
from vorta.config import SETTINGS_DIR
|
||||
|
||||
|
@ -15,6 +16,10 @@
|
|||
sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db'))
|
||||
vorta.models.init_db(sqlite_db)
|
||||
|
||||
# Run migrations
|
||||
from peewee_migrate.cli import get_router
|
||||
router = get_router(os.path.dirname(vorta.migrations.__file__), sqlite_db, True)
|
||||
router.run()
|
||||
|
||||
app = VortaApp(sys.argv)
|
||||
sys.exit(app.exec_())
|
||||
|
|
38
src/vorta/migrations/001_add-snapshot-size.py
Normal file
38
src/vorta/migrations/001_add-snapshot-size.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
"""Peewee migrations -- 001_add-snapshot-size.py.
|
||||
|
||||
Some examples (model - class or model name)::
|
||||
|
||||
> Model = migrator.orm['model_name'] # Return model in current state by name
|
||||
|
||||
> migrator.sql(sql) # Run custom SQL
|
||||
> migrator.python(func, *args, **kwargs) # Run python code
|
||||
> migrator.create_model(Model) # Create a model (could be used as decorator)
|
||||
> migrator.remove_model(model, cascade=True) # Remove a model
|
||||
> migrator.add_fields(model, **fields) # Add fields to a model
|
||||
> migrator.change_fields(model, **fields) # Change fields
|
||||
> migrator.remove_fields(model, *field_names, cascade=True)
|
||||
> migrator.rename_field(model, old_field_name, new_field_name)
|
||||
> migrator.rename_table(model, new_table_name)
|
||||
> migrator.add_index(model, *col_names, unique=False)
|
||||
> migrator.drop_index(model, *col_names)
|
||||
> migrator.add_not_null(model, *field_names)
|
||||
> migrator.drop_not_null(model, *field_names)
|
||||
> migrator.add_default(model, field_name, default)
|
||||
|
||||
"""
|
||||
|
||||
import peewee as pw
|
||||
from vorta.models import *
|
||||
|
||||
SQL = pw.SQL
|
||||
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
migrator.add_fields(SnapshotModel, duration=pw.FloatField(null=True))
|
||||
migrator.add_fields(SnapshotModel, size=pw.IntegerField(null=True))
|
||||
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
"""Write your rollback migrations here."""
|
||||
|
0
src/vorta/migrations/__init__.py
Normal file
0
src/vorta/migrations/__init__.py
Normal file
Loading…
Reference in a new issue