This ticket is for creating a generic configuration table to provide a mechanism where configuration can be perisisted and updateable. The table is essentially a key/value store.
There will only be one entry(NUM_DISSOLUTIONS_ALLOWED) in this table but it can be used for other configuration in the future.
TODOs
[x] Create an alembic script to create a new configurations table. Reference screenshot for details on required columns and field types.
[x] The alembic script should also load on entry for NUM_DISSOLUTIONS_ALLOWED with a value of 5. Note: the default value is 100 maybe but let’s start off with a smaller value to make sure we don’t accidentally dissolve a lot of companies in non-prod environements before we are ready
[x] The alembic script should also load on entry for NEW_DISSOLUTIONS_SCHEDULE with a value of 0 0 * * *. Note that we will use this value for now but we need the business to confirm what value they want.
[x] The alembic script should also load on entry for MAX_DISSOLUTIONS_ALLOWED with a value of 2000.
[x] The alembic script should also load on entry for DISSOLUTIONS_ON_HOLD with a value of False.
[x] Add minimal code model to legal api
[x] Able to save new entry
[x] Add function retrieve exiting entry using id
[x] Add function retrieve exiting entry using name
[x] Add a before insert/update listener to validate the value being inserted. Needs to be a mechanism where certain names are numbers. A ValueError exception should be thrown if a non-number value is being saved via the model for relevant configuration entries. Reference potential sample code below.
[x] Add unit tests to verify
[x] new entry can be added
[x] existing entry can be retrieved using id
[x] existing entry can be retrieved using name
[x] MAX_DISSOLUTIONS_ALLOWED entry can only be updated with int values
[x] NUM_DISSOLUTIONS_ALLOWED entry can only be updated with int values
[x] NEW_DISSOLUTIONS_SCHEDULE entry can only be updated with valid cron string. Take a look at croniter
[x] DISSOLUTIONS_ON_HOLD entry can only be updated with boolean values
Example validation code that might work
class Configuration(Base):
id = Column(Integer, primary_key=True)
name = Column(String, unique=True, nullable=False)
val = Column(String, nullable=False)
def validate_value(self):
# Define keys that should have integer values
int_names = {'NUM_DISSOLUTIONS_ALLOWED'}
if self.name in int_names:
try:
# Attempt to convert the value to an integer
int(self.val)
except ValueError:
raise ValueError(f"Value for key {self.name} must be an integer")
# Listen to 'before_insert' and 'before_update' events
@event.listens_for(Config, 'before_insert')
@event.listens_for(Config, 'before_update')
def receive_before_insert(mapper, connection, target):
# Validate the value before it gets inserted/updated
target.validate_value()
This ticket is for creating a generic configuration table to provide a mechanism where configuration can be perisisted and updateable. The table is essentially a key/value store.
There will only be one entry(NUM_DISSOLUTIONS_ALLOWED) in this table but it can be used for other configuration in the future.
TODOs
0 0 * * *
. Note that we will use this value for now but we need the business to confirm what value they want.ValueError
exception should be thrown if a non-number value is being saved via the model for relevant configuration entries. Reference potential sample code below.Example validation code that might work