22from typing import Optional
33
44from aws_cdk import aws_ec2 , aws_rds
5- from pydantic import BaseSettings , Field , validator
5+ from pydantic import Field , field_validator
6+ from pydantic_settings import BaseSettings
67
78
89class vedaDBSettings (BaseSettings ):
@@ -42,17 +43,17 @@ class vedaDBSettings(BaseSettings):
4243 max_locks_per_transaction : Optional [str ] = Field (
4344 "1024" ,
4445 description = "Number of database objects that can be locked simultaneously" ,
45- regex = r"^[1-9]\d*$" ,
46+ pattern = r"^[1-9]\d*$" ,
4647 )
4748 work_mem : Optional [str ] = Field (
4849 "64000" ,
4950 description = "Maximum amount of memory to be used by a query operation before writing to temporary disk files" ,
50- regex = r"^[1-9]\d*$" ,
51+ pattern = r"^[1-9]\d*$" ,
5152 )
5253 temp_buffers : Optional [str ] = Field (
5354 "32000" ,
5455 description = "maximum number of temporary buffers used by each session" ,
55- regex = r"^[1-9]\d*$" ,
56+ pattern = r"^[1-9]\d*$" ,
5657 )
5758 use_rds_proxy : Optional [bool ] = Field (
5859 False ,
@@ -64,13 +65,15 @@ class vedaDBSettings(BaseSettings):
6465 "The instance class of the RDS instance "
6566 "https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_ec2/InstanceClass.html"
6667 ),
68+ validate_default = True ,
6769 )
6870 rds_instance_size : Optional [str ] = Field (
6971 aws_ec2 .InstanceSize .SMALL .value ,
7072 description = (
7173 "The size of the RDS instance "
7274 "https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_ec2/InstanceSize.html"
7375 ),
76+ validate_default = True ,
7477 )
7578 rds_engine_full_version : Optional [str ] = Field (
7679 aws_rds .PostgresEngineVersion .VER_14 .postgres_full_version ,
@@ -91,14 +94,14 @@ class vedaDBSettings(BaseSettings):
9194 description = "Boolean if the RDS should be encrypted" ,
9295 )
9396
94- @validator ("rds_instance_class" , pre = True , always = True )
97+ @field_validator ("rds_instance_class" , mode = "before" )
9598 def convert_rds_class_to_uppercase (cls , value ):
9699 """Convert to uppercase."""
97100 if isinstance (value , str ):
98101 return value .upper ()
99102 return value
100103
101- @validator ("rds_instance_size" , pre = True , always = True )
104+ @field_validator ("rds_instance_size" , mode = "before" )
102105 def convert_rds_size_to_uppercase (cls , value ):
103106 """Convert to uppercase."""
104107 if isinstance (value , str ):
@@ -110,6 +113,7 @@ class Config:
110113
111114 env_file = ".env"
112115 env_prefix = "VEDA_DB_"
116+ extra = "ignore"
113117
114118
115119veda_db_settings = vedaDBSettings ()
0 commit comments