kapsikkum-unmanic – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 """Peewee migrations -- 001_rename_ffmpeg_log_to_log.py.
2  
3 Some examples (model - class or model name)::
4  
5 > Model = migrator.orm['model_name'] # Return model in current state by name
6  
7 > migrator.sql(sql) # Run custom SQL
8 > migrator.python(func, *args, **kwargs) # Run python code
9 > migrator.create_model(Model) # Create a model (could be used as decorator)
10 > migrator.remove_model(model, cascade=True) # Remove a model
11 > migrator.add_fields(model, **fields) # Add fields to a model
12 > migrator.change_fields(model, **fields) # Change fields
13 > migrator.remove_fields(model, *field_names, cascade=True)
14 > migrator.rename_field(model, old_field_name, new_field_name)
15 > migrator.rename_table(model, new_table_name)
16 > migrator.add_index(model, *col_names, unique=False)
17 > migrator.drop_index(model, *col_names)
18 > migrator.add_not_null(model, *field_names)
19 > migrator.drop_not_null(model, *field_names)
20 > migrator.add_default(model, field_name, default)
21  
22 """
23  
24 import peewee as pw
25 from decimal import ROUND_HALF_EVEN
26  
27 try:
28 import playhouse.postgres_ext as pw_pext
29 except ImportError:
30 pass
31  
32 SQL = pw.SQL
33  
34 """NOTES:
35 The migrator function 'rename_field' has a bug: https://github.com/klen/peewee_migrate/issues/99
36 The simple work-around to this was to skip this method and just directly append a migration to the migrator's ops list.
37 Eg. `migrator.ops.append(migrator.migrator.rename_column('tasks', 'ffmpeg_log', 'log'))`
38 """
39  
40  
41 """Note:
42 This migration is required for legacy installations.
43 The old Unmanic had a ffmpeg_log column which had a NOT NULL contraint on it.
44 If this column is left as is, no items will be able to be added to the task queue.
45 """
46 def migrate(migrator, database, fake=False, **kwargs):
47 """Write your migrations here."""
48 # Rename 'ffmpeg_log' field to 'log'' in Tasks model
49 if any(cm for cm in database.get_columns('tasks') if cm.name == 'ffmpeg_log'):
50 migrator.ops.append(migrator.migrator.rename_column('tasks', 'ffmpeg_log', 'log'))
51  
52  
53 def rollback(migrator, database, fake=False, **kwargs):
54 """Write your rollback migrations here."""
55 # Reverse rename 'ffmpeg_log' field to 'log'' in Tasks model
56 if any(cm for cm in database.get_columns('tasks') if cm.name == 'log'):
57 migrator.ops.append(migrator.migrator.rename_column('tasks', 'log', 'ffmpeg_log'))