migrate and save new db structure

This commit is contained in:
Jun-te Kim 2025-06-17 11:00:08 +00:00
parent 486de729fb
commit a9a479cf98
4 changed files with 150 additions and 2 deletions

View file

@ -7,6 +7,7 @@ from sqlmodel import SQLModel
from etl.models.topLevel import *
from etl.models.preSiteNoteTypes import *
from etl.models.conditionReport import *
import os

View file

@ -0,0 +1,34 @@
"""condition table from osmosis
Revision ID: 956c4ea39b29
Revises: 427e65da69c1
Create Date: 2025-06-17 10:49:55.213111
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '956c4ea39b29'
down_revision: Union[str, None] = '427e65da69c1'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_foreign_key(None, 'documents', 'assessorinfo', ['assessor_id'], ['id'])
op.create_foreign_key(None, 'presitenote', 'assessorinfo', ['assessor_id'], ['id'])
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'presitenote', type_='foreignkey')
op.drop_constraint(None, 'documents', type_='foreignkey')
# ### end Alembic commands ###

View file

@ -0,0 +1,113 @@
# SQLModel mapping for ConditionReportModel using BaseModel
from sqlmodel import SQLModel, Field, Relationship
from typing import Optional, List
import uuid
from datetime import datetime
class BaseModel(SQLModel):
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
class AssessorDetails(BaseModel, table=True):
assessor_name_and_id: str
elmhurst_id: str
class InspectionAndProject(BaseModel, table=True):
inspection_date: str
class TheProperty(BaseModel, table=True):
house_type: str
on_which_floor_is_the_flat_located: str
is_there_a_corridor: bool
is_it_heated: bool
it_there_a_balcony: bool
classification_type: str
orientation_front_elevation: str
orientation_in_degrees_front_elevation: str
exposure_zone: str
main_wall_construction: str
class ElevationInfo(BaseModel, table=True):
elevation_type: str
cavity_wall_depth: str
is_insulation_present: bool
insulation_type: str
class Elevation(BaseModel, table=True):
protected_conservatory_or_aonb: bool
material_type: str
are_there_any_visible_signs_of_existing_wall_insulation: str
does_the_existing_ground_level_on_any_elevation_bridge_the_dpc: bool
class PropertyAccess(BaseModel, table=True):
are_there_any_road_restriction_in_the_locality: bool
is_on_street_parking_available: bool
are_there_any_overhead_wires_or_cables: bool
is_the_access_gated: bool
is_there_restricted_space_for_contractors_to_access_the_wall_area: bool
is_there_restricted_space_for_contractors_to_access_the_roof_area: bool
is_there_more_than_1_point_5_meters_in_width_to_fence_or_neighbouring_boundary_along_the_full_gable_elevation: bool
is_access_to_the_rear_provided_by_use_of_a_ginnel: bool
is_access_to_the_rear_provided_by_use_of_a_secured_alleyway: bool
class ExternalElevation(BaseModel, table=True):
structural_defects_of_elevation: str
does_any_structural_defect_need_resolving_before_retrofit: bool
are_there_any_signs_of_water_penetration_caused_by_failed_rainwater_goods_or_pipework: bool
are_there_any_visible_signs_of_movement: bool
are_there_any_visible_signs_of_cracking_to_the_existing_external_finish: bool
class ConservatoryOrOutbuilding(BaseModel, table=True):
is_there_a_conservatory: bool
is_there_a_cellar_present: bool
is_there_an_outbuilding: bool
class GeneralConditionHeatingSystem(BaseModel, table=True):
is_the_heating_system_in_working_order: bool
does_the_occupant_have_a_smart_meter: bool
are_there_any_smart_monitoring_devices: bool
are_the_gas_and_electricity_meters_accessible: bool
dual_or_single_electric_meter: str
class SecondaryHeating(BaseModel, table=True):
is_there_a_secondary_heating: bool
fuel: str
electric_heating_type: str
gas_heating_type: str
class MainHeatingOne(BaseModel, table=True):
as_defined_by: str
fuel: str
type: str
class MainHeatingTwo(BaseModel, table=True):
is_there_a_main_heating_two: bool
class Heating(BaseModel, table=True):
room_stat_in_temperature_in_celsius: Optional[str] = None
room_stat_location: Optional[str] = None
is_the_heating_pattern_known: Optional[str] = None
class ConditionReport(BaseModel, table=True):
project_site_name: str
property_reference_code: str
property_address: str
postcode: str
assessor_details_id: Optional[uuid.UUID] = Field(default=None, foreign_key="assessordetails.id")
inspection_id: Optional[uuid.UUID] = Field(default=None, foreign_key="inspectionandproject.id")
property_id: Optional[uuid.UUID] = Field(default=None, foreign_key="theproperty.id")
general_condition_id: Optional[uuid.UUID] = Field(default=None, foreign_key="generalconditionheatingsystem.id")

View file

@ -1,3 +1,3 @@
#poetry run alembic revision --autogenerate -m "Initial table"
poetry run alembic revision --autogenerate -m "condition table from osmosis added as i didn't add"
poetry run alembic upgrade head
#poetry run alembic upgrade head