Skip to content

Commit a2e09ee

Browse files
committed
migration to fix production's DB
1 parent 8d7a450 commit a2e09ee

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

migrations/001_wizards_schedule.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# https://docs.peewee-orm.com/en/latest/peewee/playhouse.html#schema-migrations
2+
3+
from datetime import datetime, timedelta
4+
from playhouse.migrate import *
5+
import peewee as pw
6+
7+
from pycamp_bot.models import Pycampista, Slot, Pycamp
8+
9+
10+
my_db = pw.SqliteDatabase('pycamp_projects.db')
11+
migrator = SqliteMigrator(my_db)
12+
13+
from pycamp_bot.models import Pycamp
14+
15+
16+
migrate(
17+
migrator.add_column( # wizard_slot_duration = pw.IntegerField(default=60, null=False)
18+
Pycamp._meta.table_name,
19+
'wizard_slot_duration',
20+
Pycamp.wizard_slot_duration
21+
),
22+
migrator.add_column( # current_wizard = pw.ForeignKeyField(Pycampista)
23+
Slot._meta.table_name,
24+
'current_wizard_id',
25+
Slot.current_wizard
26+
),
27+
)
28+
29+
p = Pycamp.get()
30+
p.end = datetime(2024,6,23,23,59,59,99)
31+
p.end = datetime(2024,6,23,23,59,59,999999)
32+
p.save()
33+

0 commit comments

Comments
 (0)