diff --git a/alembic/things_alembic_doesn't_automate_for.txt b/alembic/things_alembic_doesn't_automate_for.txt new file mode 100644 index 0000000..b4f20e7 --- /dev/null +++ b/alembic/things_alembic_doesn't_automate_for.txt @@ -0,0 +1,19 @@ +Source: https://alembic.sqlalchemy.org/en/latest/autogenerate.html + +Autogenerate can not detect: + + Changes of table name. These will come out as an add/drop of two different tables, and should be hand-edited into a name change instead. + + Changes of column name. Like table name changes, these are detected as a column add/drop pair, which is not at all the same as a name change. + + Anonymously named constraints. Give your constraints a name, e.g. UniqueConstraint('col1', 'col2', name="my_name"). See the section The Importance of Naming Constraints for background on how to configure automatic naming schemes for constraints. + + Special SQLAlchemy types such as Enum when generated on a backend which doesn’t support ENUM directly - this because the representation of such a type in the non-supporting database, i.e. a CHAR+ CHECK constraint, could be any kind of CHAR+CHECK. For SQLAlchemy to determine that this is actually an ENUM would only be a guess, something that’s generally a bad idea. To implement your own “guessing” function here, use the sqlalchemy.events.DDLEvents.column_reflect() event to detect when a CHAR (or whatever the target type is) is reflected, and change it to an ENUM (or whatever type is desired) if it is known that that’s the intent of the type. The sqlalchemy.events.DDLEvents.after_parent_attach() can be used within the autogenerate process to intercept and un-attach unwanted CHECK constraints. + + + +Autogenerate can’t currently, but will eventually detect: + + Some free-standing constraint additions and removals may not be supported, including PRIMARY KEY, EXCLUDE, CHECK; these are not necessarily implemented within the autogenerate detection system and also may not be supported by the supporting SQLAlchemy dialect. + + Sequence additions, removals - not yet implemented. diff --git a/alembic/versions/42a19efef660_condition_table_from_osmosis_added_as_i_.py b/alembic/versions/42a19efef660_condition_table_from_osmosis_added_as_i_.py new file mode 100644 index 0000000..d3fc585 --- /dev/null +++ b/alembic/versions/42a19efef660_condition_table_from_osmosis_added_as_i_.py @@ -0,0 +1,166 @@ +"""condition table from osmosis added as i didn't add + +Revision ID: 42a19efef660 +Revises: 956c4ea39b29 +Create Date: 2025-06-17 12:45:14.976944 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +import sqlmodel + +# revision identifiers, used by Alembic. +revision: str = '42a19efef660' +down_revision: Union[str, None] = '956c4ea39b29' +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_table('assessordetails', + sa.Column('id', sa.Uuid(), nullable=False), + sa.Column('assessor_name_and_id', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('elmhurst_id', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('conservatoryoroutbuilding', + sa.Column('id', sa.Uuid(), nullable=False), + sa.Column('is_there_a_conservatory', sa.Boolean(), nullable=False), + sa.Column('is_there_a_cellar_present', sa.Boolean(), nullable=False), + sa.Column('is_there_an_outbuilding', sa.Boolean(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('elevation', + sa.Column('id', sa.Uuid(), nullable=False), + sa.Column('protected_conservatory_or_aonb', sa.Boolean(), nullable=False), + sa.Column('material_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('are_there_any_visible_signs_of_existing_wall_insulation', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('does_the_existing_ground_level_on_any_elevation_bridge_the_dpc', sa.Boolean(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('elevationinfo', + sa.Column('id', sa.Uuid(), nullable=False), + sa.Column('elevation_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('cavity_wall_depth', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('is_insulation_present', sa.Boolean(), nullable=False), + sa.Column('insulation_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('externalelevation', + sa.Column('id', sa.Uuid(), nullable=False), + sa.Column('structural_defects_of_elevation', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('does_any_structural_defect_need_resolving_before_retrofit', sa.Boolean(), nullable=False), + sa.Column('are_there_any_signs_of_water_penetration_caused_by_failed_rainwater_goods_or_pipework', sa.Boolean(), nullable=False), + sa.Column('are_there_any_visible_signs_of_movement', sa.Boolean(), nullable=False), + sa.Column('are_there_any_visible_signs_of_cracking_to_the_existing_external_finish', sa.Boolean(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('generalconditionheatingsystem', + sa.Column('id', sa.Uuid(), nullable=False), + sa.Column('is_the_heating_system_in_working_order', sa.Boolean(), nullable=False), + sa.Column('does_the_occupant_have_a_smart_meter', sa.Boolean(), nullable=False), + sa.Column('are_there_any_smart_monitoring_devices', sa.Boolean(), nullable=False), + sa.Column('are_the_gas_and_electricity_meters_accessible', sa.Boolean(), nullable=False), + sa.Column('dual_or_single_electric_meter', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('heating_from_condition_report', + sa.Column('id', sa.Uuid(), nullable=False), + sa.Column('room_stat_in_temperature_in_celsius', sqlmodel.sql.sqltypes.AutoString(), nullable=True), + sa.Column('room_stat_location', sqlmodel.sql.sqltypes.AutoString(), nullable=True), + sa.Column('is_the_heating_pattern_known', sqlmodel.sql.sqltypes.AutoString(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('inspectionandproject', + sa.Column('id', sa.Uuid(), nullable=False), + sa.Column('inspection_date', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('mainheatingone', + sa.Column('id', sa.Uuid(), nullable=False), + sa.Column('as_defined_by', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('fuel', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('type', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('mainheatingtwo', + sa.Column('id', sa.Uuid(), nullable=False), + sa.Column('is_there_a_main_heating_two', sa.Boolean(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('propertyaccess', + sa.Column('id', sa.Uuid(), nullable=False), + sa.Column('are_there_any_road_restriction_in_the_locality', sa.Boolean(), nullable=False), + sa.Column('is_on_street_parking_available', sa.Boolean(), nullable=False), + sa.Column('are_there_any_overhead_wires_or_cables', sa.Boolean(), nullable=False), + sa.Column('is_the_access_gated', sa.Boolean(), nullable=False), + sa.Column('is_there_restricted_space_for_contractors_to_access_the_wall_area', sa.Boolean(), nullable=False), + sa.Column('is_there_restricted_space_for_contractors_to_access_the_roof_area', sa.Boolean(), nullable=False), + sa.Column('is_there_more_than_1_point_5_meters_in_width_to_fence_or_neighbouring_boundary_along_the_full_gable_elevation', sa.Boolean(), nullable=False), + sa.Column('is_access_to_the_rear_provided_by_use_of_a_ginnel', sa.Boolean(), nullable=False), + sa.Column('is_access_to_the_rear_provided_by_use_of_a_secured_alleyway', sa.Boolean(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('secondaryheating', + sa.Column('id', sa.Uuid(), nullable=False), + sa.Column('is_there_a_secondary_heating', sa.Boolean(), nullable=False), + sa.Column('fuel', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('electric_heating_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('gas_heating_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('theproperty', + sa.Column('id', sa.Uuid(), nullable=False), + sa.Column('house_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('on_which_floor_is_the_flat_located', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('is_there_a_corridor', sa.Boolean(), nullable=False), + sa.Column('is_it_heated', sa.Boolean(), nullable=False), + sa.Column('it_there_a_balcony', sa.Boolean(), nullable=False), + sa.Column('classification_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('orientation_front_elevation', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('orientation_in_degrees_front_elevation', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('exposure_zone', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('main_wall_construction', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('conditionreport', + sa.Column('id', sa.Uuid(), nullable=False), + sa.Column('project_site_name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('property_reference_code', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('property_address', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('postcode', sqlmodel.sql.sqltypes.AutoString(), nullable=False), + sa.Column('assessor_details_id', sa.Uuid(), nullable=True), + sa.Column('inspection_id', sa.Uuid(), nullable=True), + sa.Column('property_id', sa.Uuid(), nullable=True), + sa.Column('general_condition_id', sa.Uuid(), nullable=True), + sa.ForeignKeyConstraint(['assessor_details_id'], ['assessordetails.id'], ), + sa.ForeignKeyConstraint(['general_condition_id'], ['generalconditionheatingsystem.id'], ), + sa.ForeignKeyConstraint(['inspection_id'], ['inspectionandproject.id'], ), + sa.ForeignKeyConstraint(['property_id'], ['theproperty.id'], ), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + """Downgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('conditionreport') + op.drop_table('theproperty') + op.drop_table('secondaryheating') + op.drop_table('propertyaccess') + op.drop_table('mainheatingtwo') + op.drop_table('mainheatingone') + op.drop_table('inspectionandproject') + op.drop_table('heating_from_condition_report') + op.drop_table('generalconditionheatingsystem') + op.drop_table('externalelevation') + op.drop_table('elevationinfo') + op.drop_table('elevation') + op.drop_table('conservatoryoroutbuilding') + op.drop_table('assessordetails') + # ### end Alembic commands ### diff --git a/etl/models/conditionReport.py b/etl/models/conditionReport.py index 777a065..5ea84b6 100644 --- a/etl/models/conditionReport.py +++ b/etl/models/conditionReport.py @@ -96,6 +96,7 @@ class MainHeatingTwo(BaseModel, table=True): class Heating(BaseModel, table=True): + __tablename__ = 'heating_from_condition_report' room_stat_in_temperature_in_celsius: Optional[str] = None room_stat_location: Optional[str] = None is_the_heating_pattern_known: Optional[str] = None diff --git a/migration_db.sh b/migration_db.sh index e8cadeb..6e6a750 100644 --- a/migration_db.sh +++ b/migration_db.sh @@ -1,3 +1,3 @@ -poetry run alembic revision --autogenerate -m "condition table from osmosis added as i didn't add" +#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