1 |
|
# -*- coding: utf-8 -*- |
2 |
|
|
3 |
|
# Copyright 2018 Whitestack, LLC |
4 |
|
# ************************************************************* |
5 |
|
|
6 |
|
# This file is part of OSM Monitoring module |
7 |
|
# All Rights Reserved to Whitestack, LLC |
8 |
|
|
9 |
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
10 |
|
# not use this file except in compliance with the License. You may obtain |
11 |
|
# a copy of the License at |
12 |
|
|
13 |
|
# http://www.apache.org/licenses/LICENSE-2.0 |
14 |
|
|
15 |
|
# Unless required by applicable law or agreed to in writing, software |
16 |
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
17 |
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
18 |
|
# License for the specific language governing permissions and limitations |
19 |
|
# under the License. |
20 |
|
|
21 |
|
# For those usages not covered by the Apache License, Version 2.0 please |
22 |
|
# contact: bdiaz@whitestack.com or glavado@whitestack.com |
23 |
|
## |
24 |
0 |
"""Peewee migrations -- 001_initial.py. |
25 |
|
|
26 |
|
Some examples (model - class or model name):: |
27 |
|
|
28 |
|
> Model = migrator.orm['model_name'] # Return model in current state by name |
29 |
|
|
30 |
|
> migrator.sql(sql) # Run custom SQL |
31 |
|
> migrator.python(func, *args, **kwargs) # Run python code |
32 |
|
> migrator.create_model(Model) # Create a model (could be used as decorator) |
33 |
|
> migrator.remove_model(model, cascade=True) # Remove a model |
34 |
|
> migrator.add_fields(model, **fields) # Add fields to a model |
35 |
|
> migrator.change_fields(model, **fields) # Change fields |
36 |
|
> migrator.remove_fields(model, *field_names, cascade=True) |
37 |
|
> migrator.rename_field(model, old_field_name, new_field_name) |
38 |
|
> migrator.rename_table(model, new_table_name) |
39 |
|
> migrator.add_index(model, *col_names, unique=False) |
40 |
|
> migrator.drop_index(model, *col_names) |
41 |
|
> migrator.add_not_null(model, *field_names) |
42 |
|
> migrator.drop_not_null(model, *field_names) |
43 |
|
> migrator.add_default(model, field_name, default) |
44 |
|
|
45 |
|
""" |
46 |
|
|
47 |
0 |
import peewee as pw |
48 |
|
|
49 |
0 |
SQL = pw.SQL |
50 |
|
|
51 |
|
|
52 |
0 |
def migrate(migrator, database, fake=False, **kwargs): |
53 |
|
"""Write your migrations here.""" |
54 |
|
|
55 |
0 |
@migrator.create_model |
56 |
0 |
class BaseModel(pw.Model): |
57 |
0 |
id = pw.AutoField() |
58 |
|
|
59 |
0 |
class Meta: |
60 |
0 |
table_name = "basemodel" |
61 |
|
|
62 |
0 |
@migrator.create_model |
63 |
0 |
class ScalingGroup(pw.Model): |
64 |
0 |
id = pw.AutoField() |
65 |
0 |
nsr_id = pw.CharField(max_length=255) |
66 |
0 |
vnf_member_index = pw.IntegerField() |
67 |
0 |
name = pw.CharField(max_length=255) |
68 |
0 |
content = pw.TextField() |
69 |
|
|
70 |
0 |
class Meta: |
71 |
0 |
table_name = "scalinggroup" |
72 |
|
|
73 |
0 |
@migrator.create_model |
74 |
0 |
class ScalingPolicy(pw.Model): |
75 |
0 |
id = pw.AutoField() |
76 |
0 |
name = pw.CharField(max_length=255) |
77 |
0 |
cooldown_time = pw.IntegerField() |
78 |
0 |
last_scale = pw.DateTimeField() |
79 |
0 |
scaling_group = pw.ForeignKeyField(backref='scaling_policies', column_name='scaling_group_id', field='id', |
80 |
|
model=migrator.orm['scalinggroup'], on_delete='CASCADE') |
81 |
|
|
82 |
0 |
class Meta: |
83 |
0 |
table_name = "scalingpolicy" |
84 |
|
|
85 |
0 |
@migrator.create_model |
86 |
0 |
class ScalingCriteria(pw.Model): |
87 |
0 |
id = pw.AutoField() |
88 |
0 |
name = pw.CharField(max_length=255) |
89 |
0 |
scaling_policy = pw.ForeignKeyField(backref='scaling_criterias', column_name='scaling_policy_id', field='id', |
90 |
|
model=migrator.orm['scalingpolicy'], on_delete='CASCADE') |
91 |
|
|
92 |
0 |
class Meta: |
93 |
0 |
table_name = "scalingcriteria" |
94 |
|
|
95 |
0 |
@migrator.create_model |
96 |
0 |
class ScalingAlarm(pw.Model): |
97 |
0 |
id = pw.AutoField() |
98 |
0 |
alarm_uuid = pw.CharField(max_length=255, unique=True) |
99 |
0 |
action = pw.CharField(max_length=255) |
100 |
0 |
vnf_member_index = pw.IntegerField() |
101 |
0 |
vdu_name = pw.CharField(max_length=255) |
102 |
0 |
scaling_criteria = pw.ForeignKeyField(backref='scaling_alarms', column_name='scaling_criteria_id', field='id', |
103 |
|
model=migrator.orm['scalingcriteria'], on_delete='CASCADE') |
104 |
|
|
105 |
0 |
class Meta: |
106 |
0 |
table_name = "scalingalarm" |
107 |
|
|
108 |
|
|
109 |
0 |
def rollback(migrator, database, fake=False, **kwargs): |
110 |
|
"""Write your rollback migrations here.""" |
111 |
|
|
112 |
0 |
migrator.remove_model('scalingalarm') |
113 |
|
|
114 |
0 |
migrator.remove_model('scalingcriteria') |
115 |
|
|
116 |
0 |
migrator.remove_model('scalingpolicy') |
117 |
|
|
118 |
0 |
migrator.remove_model('scalinggroup') |
119 |
|
|
120 |
0 |
migrator.remove_model('basemodel') |