diff --git a/cloudkitty/rating/hash/db/sqlalchemy/alembic/versions/4e0232ce_increase_precision_for_cost_fields.py b/cloudkitty/rating/hash/db/sqlalchemy/alembic/versions/4e0232ce_increase_precision_for_cost_fields.py new file mode 100644 index 00000000..5b439a53 --- /dev/null +++ b/cloudkitty/rating/hash/db/sqlalchemy/alembic/versions/4e0232ce_increase_precision_for_cost_fields.py @@ -0,0 +1,45 @@ +# Copyright 2018 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +"""Increase cost fields to 30 digits + +Revision ID: 4e0232ce +Revises: Ifbf5b2515c7 +Create Date: 2022-04-06 08:00:00.000000 + +""" + +from alembic import op +import importlib + +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = '4e0232ce' +down_revision = 'Ifbf5b2515c7' + + +def upgrade(): + down_version_module = importlib.import_module( + "cloudkitty.rating.hash.db.sqlalchemy.alembic.versions." + "644faa4491fd_update_tenant_id_type_from_uuid_to_text") + + for table_name in ('hashmap_mappings', 'hashmap_thresholds'): + with op.batch_alter_table( + table_name, reflect_args=down_version_module.get_reflect( + table_name)) as batch_op: + + batch_op.alter_column('cost', + type_=sa.Numeric(precision=40, scale=28)) diff --git a/cloudkitty/rating/hash/db/sqlalchemy/models.py b/cloudkitty/rating/hash/db/sqlalchemy/models.py index 3695a540..e16d5b27 100644 --- a/cloudkitty/rating/hash/db/sqlalchemy/models.py +++ b/cloudkitty/rating/hash/db/sqlalchemy/models.py @@ -230,7 +230,7 @@ class HashMapMapping(Base, HashMapBase): sqlalchemy.String(255), nullable=True) cost = sqlalchemy.Column( - sqlalchemy.Numeric(30, 28), + sqlalchemy.Numeric(40, 28), nullable=False) map_type = sqlalchemy.Column( sqlalchemy.Enum( @@ -309,7 +309,7 @@ class HashMapThreshold(Base, HashMapBase): sqlalchemy.Numeric(20, 8), nullable=True) cost = sqlalchemy.Column( - sqlalchemy.Numeric(30, 28), + sqlalchemy.Numeric(40, 28), nullable=False) map_type = sqlalchemy.Column( sqlalchemy.Enum( diff --git a/doc/source/user/rating/hashmap.rst b/doc/source/user/rating/hashmap.rst index efc28ba1..80f8f822 100644 --- a/doc/source/user/rating/hashmap.rst +++ b/doc/source/user/rating/hashmap.rst @@ -160,8 +160,8 @@ As for mappings, a threshold can be tied to a specific scope/project. Cost ---- The cost option is the actual cost for the rating period. It has a precision of -28 decimal digits (on the right side of the number), and 30 digits on the left -side of the number. +28 decimal digits (on the right side of the decimal point), and 12 digits on +the left side of the decimal point (the integer part of the number). Examples ======== diff --git a/releasenotes/notes/fix-rating-rules-value-precision-40d1054f8ab494c3.yaml b/releasenotes/notes/fix-rating-rules-value-precision-40d1054f8ab494c3.yaml new file mode 100644 index 00000000..2eef9bf8 --- /dev/null +++ b/releasenotes/notes/fix-rating-rules-value-precision-40d1054f8ab494c3.yaml @@ -0,0 +1,10 @@ +--- +fixes: + - | + Allow rating rules that have more than 2 digits in integer part. + + Currently, CloudKitty only allows creating rating rules as + ``99.999999999999999999999999``. Therefore, for prices equal to or higher + than 100, we would not be able to use them. This patch will enable + operators to use any value between ``0`` and ``999999999999`` (in the + integer part of the number), which will provide more flexibility.