Refactors alarms to decouple them from vnf specific data
[osm/MON.git] / osm_mon / migrations / 001_initial.py
1 """Peewee migrations -- 001_initial.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
26 SQL = pw.SQL
27
28
29 def migrate(migrator, database, fake=False, **kwargs):
30 """Write your migrations here."""
31
32 @migrator.create_model
33 class Alarm(pw.Model):
34 id = pw.AutoField()
35 uuid = pw.CharField(max_length=255, unique=True)
36 name = pw.CharField(max_length=255)
37 severity = pw.CharField(max_length=255)
38 threshold = pw.FloatField()
39 operation = pw.CharField(max_length=255)
40 statistic = pw.CharField(max_length=255)
41 monitoring_param = pw.CharField(max_length=255)
42 vdur_name = pw.CharField(max_length=255)
43 vnf_member_index = pw.CharField(max_length=255)
44 nsr_id = pw.CharField(max_length=255)
45
46 class Meta:
47 table_name = "alarm"
48
49 @migrator.create_model
50 class BaseModel(pw.Model):
51 id = pw.AutoField()
52
53 class Meta:
54 table_name = "basemodel"
55
56 @migrator.create_model
57 class VimCredentials(pw.Model):
58 id = pw.AutoField()
59 uuid = pw.CharField(max_length=255, unique=True)
60 name = pw.CharField(max_length=255)
61 type = pw.CharField(max_length=255)
62 url = pw.CharField(max_length=255)
63 user = pw.CharField(max_length=255)
64 password = pw.CharField(max_length=255)
65 tenant_name = pw.CharField(max_length=255)
66 config = pw.TextField()
67
68 class Meta:
69 table_name = "vimcredentials"
70
71
72 def rollback(migrator, database, fake=False, **kwargs):
73 """Write your rollback migrations here."""
74
75 migrator.remove_model('vimcredentials')
76
77 migrator.remove_model('basemodel')
78
79 migrator.remove_model('alarm')