|
| 1 | +"""Peewee migrations -- 001_wizards_schedule.py. |
| 2 | +
|
| 3 | +Some examples (model - class or model name):: |
| 4 | +
|
| 5 | + > Model = migrator.orm['table_name'] # Return model in current state by name |
| 6 | + > Model = migrator.ModelClass # Return model in current state by name |
| 7 | +
|
| 8 | + > migrator.sql(sql) # Run custom SQL |
| 9 | + > migrator.run(func, *args, **kwargs) # Run python function with the given args |
| 10 | + > migrator.create_model(Model) # Create a model (could be used as decorator) |
| 11 | + > migrator.remove_model(model, cascade=True) # Remove a model |
| 12 | + > migrator.add_fields(model, **fields) # Add fields to a model |
| 13 | + > migrator.change_fields(model, **fields) # Change fields |
| 14 | + > migrator.remove_fields(model, *field_names, cascade=True) |
| 15 | + > migrator.rename_field(model, old_field_name, new_field_name) |
| 16 | + > migrator.rename_table(model, new_table_name) |
| 17 | + > migrator.add_index(model, *col_names, unique=False) |
| 18 | + > migrator.add_not_null(model, *field_names) |
| 19 | + > migrator.add_default(model, field_name, default) |
| 20 | + > migrator.add_constraint(model, name, sql) |
| 21 | + > migrator.drop_index(model, *col_names) |
| 22 | + > migrator.drop_not_null(model, *field_names) |
| 23 | + > migrator.drop_constraints(model, *constraints) |
| 24 | +
|
| 25 | +""" |
| 26 | + |
| 27 | +from contextlib import suppress |
| 28 | + |
| 29 | +import peewee as pw |
| 30 | +from peewee_migrate import Migrator |
| 31 | + |
| 32 | +from pycamp_bot.models import Pycamp |
| 33 | + |
| 34 | + |
| 35 | +with suppress(ImportError): |
| 36 | + import playhouse.postgres_ext as pw_pext |
| 37 | + |
| 38 | + |
| 39 | +def migrate(migrator: Migrator, database: pw.Database, *, fake=False): |
| 40 | + """Write your migrations here.""" |
| 41 | + migrator.add_fields(Pycamp, Pycamp.wizard_slot_duration) |
| 42 | + |
| 43 | + |
| 44 | +def rollback(migrator: Migrator, database: pw.Database, *, fake=False): |
| 45 | + """Write your rollback migrations here.""" |
| 46 | + migrator.remove_fields(Pycamp, ["wizard_slot_duration"]) |
| 47 | + |
0 commit comments