Coverage for osm_policy_module/migrations/001_initial.py: 0%
50 statements
« prev ^ index » next coverage.py v6.4.1, created at 2024-06-30 08:29 +0000
« prev ^ index » next coverage.py v6.4.1, created at 2024-06-30 08:29 +0000
1# -*- coding: utf-8 -*-
3# Copyright 2018 Whitestack, LLC
4# *************************************************************
6# This file is part of OSM Monitoring module
7# All Rights Reserved to Whitestack, LLC
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
13# http://www.apache.org/licenses/LICENSE-2.0
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.
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"""Peewee migrations -- 001_initial.py.
26Some examples (model - class or model name)::
28 > Model = migrator.orm['model_name'] # Return model in current state by name
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)
45"""
47import peewee as pw
49SQL = pw.SQL
52def migrate(migrator, database, fake=False, **kwargs):
53 """Write your migrations here."""
55 @migrator.create_model
56 class BaseModel(pw.Model):
57 id = pw.AutoField()
59 class Meta:
60 table_name = "basemodel"
62 @migrator.create_model
63 class ScalingGroup(pw.Model):
64 id = pw.AutoField()
65 nsr_id = pw.CharField(max_length=255)
66 vnf_member_index = pw.IntegerField()
67 name = pw.CharField(max_length=255)
68 content = pw.TextField()
70 class Meta:
71 table_name = "scalinggroup"
73 @migrator.create_model
74 class ScalingPolicy(pw.Model):
75 id = pw.AutoField()
76 name = pw.CharField(max_length=255)
77 cooldown_time = pw.IntegerField()
78 last_scale = pw.DateTimeField()
79 scaling_group = pw.ForeignKeyField(
80 backref="scaling_policies",
81 column_name="scaling_group_id",
82 field="id",
83 model=migrator.orm["scalinggroup"],
84 on_delete="CASCADE",
85 )
87 class Meta:
88 table_name = "scalingpolicy"
90 @migrator.create_model
91 class ScalingCriteria(pw.Model):
92 id = pw.AutoField()
93 name = pw.CharField(max_length=255)
94 scaling_policy = pw.ForeignKeyField(
95 backref="scaling_criterias",
96 column_name="scaling_policy_id",
97 field="id",
98 model=migrator.orm["scalingpolicy"],
99 on_delete="CASCADE",
100 )
102 class Meta:
103 table_name = "scalingcriteria"
105 @migrator.create_model
106 class ScalingAlarm(pw.Model):
107 id = pw.AutoField()
108 alarm_uuid = pw.CharField(max_length=255, unique=True)
109 action = pw.CharField(max_length=255)
110 vnf_member_index = pw.IntegerField()
111 vdu_name = pw.CharField(max_length=255)
112 scaling_criteria = pw.ForeignKeyField(
113 backref="scaling_alarms",
114 column_name="scaling_criteria_id",
115 field="id",
116 model=migrator.orm["scalingcriteria"],
117 on_delete="CASCADE",
118 )
120 class Meta:
121 table_name = "scalingalarm"
124def rollback(migrator, database, fake=False, **kwargs):
125 """Write your rollback migrations here."""
127 migrator.remove_model("scalingalarm")
129 migrator.remove_model("scalingcriteria")
131 migrator.remove_model("scalingpolicy")
133 migrator.remove_model("scalinggroup")
135 migrator.remove_model("basemodel")