mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-05 22:18:26 -04:00
remove provider_rates table
this was added five years ago but never used. if we want to bring back variable rates per client we might as well get a fresh start since a lot has changed since then.
This commit is contained in:
@@ -4,7 +4,6 @@ import itertools
|
|||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import flask
|
import flask
|
||||||
@@ -42,9 +41,6 @@ from app.dao.organisation_dao import (
|
|||||||
dao_get_organisation_by_id,
|
dao_get_organisation_by_id,
|
||||||
)
|
)
|
||||||
from app.dao.permissions_dao import permission_dao
|
from app.dao.permissions_dao import permission_dao
|
||||||
from app.dao.provider_rates_dao import (
|
|
||||||
create_provider_rates as dao_create_provider_rates,
|
|
||||||
)
|
|
||||||
from app.dao.services_dao import (
|
from app.dao.services_dao import (
|
||||||
dao_fetch_all_services_by_user,
|
dao_fetch_all_services_by_user,
|
||||||
dao_fetch_all_services_created_by_user,
|
dao_fetch_all_services_created_by_user,
|
||||||
@@ -61,7 +57,6 @@ from app.dao.users_dao import (
|
|||||||
from app.models import (
|
from app.models import (
|
||||||
KEY_TYPE_TEST,
|
KEY_TYPE_TEST,
|
||||||
NOTIFICATION_CREATED,
|
NOTIFICATION_CREATED,
|
||||||
PROVIDERS,
|
|
||||||
SMS_TYPE,
|
SMS_TYPE,
|
||||||
AnnualBilling,
|
AnnualBilling,
|
||||||
Domain,
|
Domain,
|
||||||
@@ -108,18 +103,6 @@ class notify_command:
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
@notify_command()
|
|
||||||
@click.option('-p', '--provider_name', required=True, type=click.Choice(PROVIDERS))
|
|
||||||
@click.option('-c', '--cost', required=True, help='Cost (pence) per message including decimals', type=float)
|
|
||||||
@click.option('-d', '--valid_from', required=True, type=click_dt(format='%Y-%m-%dT%H:%M:%S'))
|
|
||||||
def create_provider_rates(provider_name, cost, valid_from):
|
|
||||||
"""
|
|
||||||
Backfill rates for a given provider
|
|
||||||
"""
|
|
||||||
cost = Decimal(cost)
|
|
||||||
dao_create_provider_rates(provider_name, valid_from, cost)
|
|
||||||
|
|
||||||
|
|
||||||
@notify_command()
|
@notify_command()
|
||||||
@click.option('-u', '--user_email_prefix', required=True, help="""
|
@click.option('-u', '--user_email_prefix', required=True, help="""
|
||||||
Functional test user email prefix. eg "notify-test-preview"
|
Functional test user email prefix. eg "notify-test-preview"
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
from app import db
|
|
||||||
from app.dao.dao_utils import autocommit
|
|
||||||
from app.models import ProviderDetails, ProviderRates
|
|
||||||
|
|
||||||
|
|
||||||
@autocommit
|
|
||||||
def create_provider_rates(provider_identifier, valid_from, rate):
|
|
||||||
provider = ProviderDetails.query.filter_by(identifier=provider_identifier).one()
|
|
||||||
|
|
||||||
provider_rates = ProviderRates(provider_id=provider.id, valid_from=valid_from, rate=rate)
|
|
||||||
db.session.add(provider_rates)
|
|
||||||
@@ -1146,16 +1146,6 @@ NOTIFICATION_TYPE = [EMAIL_TYPE, SMS_TYPE, LETTER_TYPE]
|
|||||||
notification_types = db.Enum(*NOTIFICATION_TYPE, name='notification_type')
|
notification_types = db.Enum(*NOTIFICATION_TYPE, name='notification_type')
|
||||||
|
|
||||||
|
|
||||||
class ProviderRates(db.Model):
|
|
||||||
__tablename__ = 'provider_rates'
|
|
||||||
|
|
||||||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
||||||
valid_from = db.Column(db.DateTime, nullable=False)
|
|
||||||
rate = db.Column(db.Numeric(), nullable=False)
|
|
||||||
provider_id = db.Column(UUID(as_uuid=True), db.ForeignKey('provider_details.id'), index=True, nullable=False)
|
|
||||||
provider = db.relationship('ProviderDetails', backref=db.backref('provider_rates', lazy='dynamic'))
|
|
||||||
|
|
||||||
|
|
||||||
class ProviderDetails(db.Model):
|
class ProviderDetails(db.Model):
|
||||||
__tablename__ = 'provider_details'
|
__tablename__ = 'provider_details'
|
||||||
|
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ class ProviderDetailsSchema(BaseSchema):
|
|||||||
|
|
||||||
class Meta(BaseSchema.Meta):
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.ProviderDetails
|
model = models.ProviderDetails
|
||||||
exclude = ("provider_rates", "provider_stats")
|
exclude = ("provider_stats",)
|
||||||
strict = True
|
strict = True
|
||||||
|
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ class ProviderDetailsHistorySchema(BaseSchema):
|
|||||||
|
|
||||||
class Meta(BaseSchema.Meta):
|
class Meta(BaseSchema.Meta):
|
||||||
model = models.ProviderDetailsHistory
|
model = models.ProviderDetailsHistory
|
||||||
exclude = ("provider_rates", "provider_stats")
|
exclude = ("provider_stats",)
|
||||||
strict = True
|
strict = True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
30
migrations/versions/0372_remove_provider_rates.py
Normal file
30
migrations/versions/0372_remove_provider_rates.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
Revision ID: 0372_remove_provider_rates
|
||||||
|
Revises: 0371_fix_apr_2022_sms_rate
|
||||||
|
Create Date: 2022-04-26 09:39:45.260951
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
revision = '0372_remove_provider_rates'
|
||||||
|
down_revision = '0371_fix_apr_2022_sms_rate'
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.drop_table('provider_rates')
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.create_table(
|
||||||
|
'provider_rates',
|
||||||
|
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
|
sa.Column('valid_from', sa.DateTime(), nullable=False),
|
||||||
|
sa.Column('provider_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||||
|
sa.Column('rate', sa.Numeric(), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.ForeignKeyConstraint(['provider_id'], ['provider_details.id'], ),
|
||||||
|
)
|
||||||
@@ -43,7 +43,6 @@ from app.models import (
|
|||||||
Permission,
|
Permission,
|
||||||
ProviderDetails,
|
ProviderDetails,
|
||||||
ProviderDetailsHistory,
|
ProviderDetailsHistory,
|
||||||
ProviderRates,
|
|
||||||
Service,
|
Service,
|
||||||
ServiceEmailReplyTo,
|
ServiceEmailReplyTo,
|
||||||
ServiceGuestList,
|
ServiceGuestList,
|
||||||
@@ -954,7 +953,6 @@ def restore_provider_details(notify_db, notify_db_session):
|
|||||||
yield
|
yield
|
||||||
|
|
||||||
# also delete these as they depend on provider_details
|
# also delete these as they depend on provider_details
|
||||||
ProviderRates.query.delete()
|
|
||||||
ProviderDetails.query.delete()
|
ProviderDetails.query.delete()
|
||||||
ProviderDetailsHistory.query.delete()
|
ProviderDetailsHistory.query.delete()
|
||||||
notify_db.session.commit()
|
notify_db.session.commit()
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
from datetime import datetime
|
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from app.dao.provider_rates_dao import create_provider_rates
|
|
||||||
from app.models import ProviderDetails, ProviderRates
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_provider_rates(notify_db, notify_db_session, mmg_provider):
|
|
||||||
now = datetime.now()
|
|
||||||
rate = Decimal("1.00000")
|
|
||||||
|
|
||||||
provider = ProviderDetails.query.filter_by(identifier=mmg_provider.identifier).one()
|
|
||||||
|
|
||||||
create_provider_rates(mmg_provider.identifier, now, rate)
|
|
||||||
assert ProviderRates.query.count() == 1
|
|
||||||
assert ProviderRates.query.first().rate == rate
|
|
||||||
assert ProviderRates.query.first().valid_from == now
|
|
||||||
assert ProviderRates.query.first().provider_id == provider.id
|
|
||||||
Reference in New Issue
Block a user