CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" (
    migration_id character varying(150) NOT NULL,
    product_version character varying(32) NOT NULL,
    CONSTRAINT pk___ef_migrations_history PRIMARY KEY (migration_id)
);

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE commitees (
        commitee_id uuid NOT NULL,
        residence_id uuid NOT NULL,
        name text NULL,
        unit text NULL,
        position text NULL,
        contact_number text NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_commitees PRIMARY KEY (commitee_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE facilitys (
        facility_id uuid NOT NULL,
        name text NULL,
        description text NULL,
        status integer NOT NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_facilitys PRIMARY KEY (facility_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE guard_checkpoints (
        guard_checkpoint_id uuid NOT NULL,
        checkpoint_id uuid NOT NULL,
        residence_id uuid NOT NULL,
        user_id uuid NOT NULL,
        proof bytea NULL,
        status boolean NOT NULL,
        check_date timestamp without time zone NOT NULL,
        CONSTRAINT pk_guard_checkpoints PRIMARY KEY (guard_checkpoint_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE inquirys (
        inquiry_id uuid NOT NULL,
        residence_id uuid NOT NULL,
        question text NULL,
        answer text NULL,
        status integer NOT NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_inquirys PRIMARY KEY (inquiry_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE panics (
        panic_id uuid NOT NULL,
        residence_id uuid NOT NULL,
        unit_id text NULL,
        "user" uuid NOT NULL,
        message text NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_panics PRIMARY KEY (panic_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE parkings (
        parking_id uuid NOT NULL,
        residence_id uuid NOT NULL,
        parking_number integer NOT NULL,
        parking_name text NULL,
        visitor_id uuid NOT NULL,
        check_in_date_time timestamp without time zone NOT NULL,
        check_out_date_time timestamp without time zone NOT NULL,
        CONSTRAINT pk_parkings PRIMARY KEY (parking_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE residences (
        residence_id uuid NOT NULL,
        residence_type integer NOT NULL,
        residence_name text NULL,
        phone_number text NULL,
        office_number text NULL,
        email_address text NULL,
        address1 text NULL,
        address2 text NULL,
        city text NULL,
        state integer NOT NULL,
        zip_code integer NOT NULL,
        country text NULL,
        description text NULL,
        status integer NOT NULL,
        price double precision NOT NULL,
        subscription_start text NULL,
        subscription_end text NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_residences PRIMARY KEY (residence_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE announcements (
        announcement_id uuid NOT NULL,
        users text NULL,
        residence_id uuid NULL,
        announcement_type integer NOT NULL,
        title text NULL,
        description text NULL,
        created_by_user_id uuid NOT NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_announcements PRIMARY KEY (announcement_id),
        CONSTRAINT fk_announcements_residences_residence_id FOREIGN KEY (residence_id) REFERENCES residences (residence_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE buildings (
        building_id uuid NOT NULL,
        building_name text NULL,
        building_prefix text NULL,
        total_floor integer NOT NULL,
        unit_per_floor integer NOT NULL,
        description text NULL,
        is_unit_created boolean NOT NULL,
        status integer NOT NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        residence_id uuid NULL,
        CONSTRAINT pk_buildings PRIMARY KEY (building_id),
        CONSTRAINT fk_buildings_residences_residence_id FOREIGN KEY (residence_id) REFERENCES residences (residence_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE checkpoints (
        checkpoint_id uuid NOT NULL,
        residence_id uuid NULL,
        title text NULL,
        description text NULL,
        file bytea NULL,
        status integer NOT NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_checkpoints PRIMARY KEY (checkpoint_id),
        CONSTRAINT fk_checkpoints_residences_residence_id FOREIGN KEY (residence_id) REFERENCES residences (residence_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE doc_banners (
        doc_banner_id uuid NOT NULL,
        title text NULL,
        description text NULL,
        doc_banner_type integer NOT NULL,
        residence_id uuid NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_doc_banners PRIMARY KEY (doc_banner_id),
        CONSTRAINT fk_doc_banners_residences_residence_id FOREIGN KEY (residence_id) REFERENCES residences (residence_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE managements (
        management_id uuid NOT NULL,
        name text NULL,
        phone_number text NULL,
        office_number text NULL,
        email_address text NULL,
        address1 text NULL,
        address2 text NULL,
        city text NULL,
        state integer NOT NULL,
        zip_code integer NOT NULL,
        country text NULL,
        description text NULL,
        status integer NOT NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        residence_id uuid NULL,
        CONSTRAINT pk_managements PRIMARY KEY (management_id),
        CONSTRAINT fk_managements_residences_residence_id FOREIGN KEY (residence_id) REFERENCES residences (residence_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE residence_docs (
        residence_doc_id uuid NOT NULL,
        file bytea NULL,
        file_type text NULL,
        file_name text NULL,
        residence_id uuid NULL,
        CONSTRAINT pk_residence_docs PRIMARY KEY (residence_doc_id),
        CONSTRAINT fk_residence_docs_residences_residence_id FOREIGN KEY (residence_id) REFERENCES residences (residence_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE residence_facilities (
        residence_facility_id uuid NOT NULL,
        facility_id uuid NULL,
        residence_id uuid NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_residence_facilities PRIMARY KEY (residence_facility_id),
        CONSTRAINT fk_residence_facilities_facilitys_facility_id FOREIGN KEY (facility_id) REFERENCES facilitys (facility_id),
        CONSTRAINT fk_residence_facilities_residences_residence_id FOREIGN KEY (residence_id) REFERENCES residences (residence_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE ser_providers (
        ser_provider_id uuid NOT NULL,
        residence_id uuid NULL,
        company_name text NULL,
        description text NULL,
        phone_number text NULL,
        price text NULL,
        natureofbusiness text NULL,
        link text NULL,
        logo bytea NULL,
        status integer NOT NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_ser_providers PRIMARY KEY (ser_provider_id),
        CONSTRAINT fk_ser_providers_residences_residence_id FOREIGN KEY (residence_id) REFERENCES residences (residence_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE slots (
        slot_id uuid NOT NULL,
        residence_id uuid NULL,
        slot_name text NULL,
        "from" text NULL,
        "to" text NULL,
        people text NULL,
        status integer NOT NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_slots PRIMARY KEY (slot_id),
        CONSTRAINT fk_slots_residences_residence_id FOREIGN KEY (residence_id) REFERENCES residences (residence_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE users (
        user_id uuid NOT NULL,
        first_name text NULL,
        last_name text NULL,
        dob text NULL,
        email text NULL,
        password_hash text NULL,
        occupation text NULL,
        nationality integer NOT NULL,
        gender integer NOT NULL,
        status integer NOT NULL,
        role integer[] NULL,
        nric text NULL,
        passport text NULL,
        phone_number text NULL,
        profile_picture bytea NULL,
        created_by text NULL,
        bank_name text NULL,
        account_number text NULL,
        account_holder_name text NULL,
        registered_ip text NULL,
        registered_host_name text NULL,
        last_login_ip text NULL,
        last_login timestamp without time zone NOT NULL,
        is_password_format integer NOT NULL,
        last_password_updated timestamp without time zone NOT NULL,
        terms boolean NOT NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        modified_by uuid NOT NULL,
        modified_ip text NULL,
        modified_host_name text NULL,
        modified_count integer NOT NULL,
        parking_lot_no text NULL,
        residence_id uuid NULL,
        CONSTRAINT pk_users PRIMARY KEY (user_id),
        CONSTRAINT fk_users_residences_residence_id FOREIGN KEY (residence_id) REFERENCES residences (residence_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE announcement_docs (
        announcement_doc_id uuid NOT NULL,
        announcement_id uuid NULL,
        file bytea NULL,
        file_type text NULL,
        file_name text NULL,
        CONSTRAINT pk_announcement_docs PRIMARY KEY (announcement_doc_id),
        CONSTRAINT fk_announcement_docs_announcements_announcement_id FOREIGN KEY (announcement_id) REFERENCES announcements (announcement_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE doc_banner_docs (
        doc_banner_docs_id uuid NOT NULL,
        doc_banner_id uuid NULL,
        file bytea NULL,
        file_type text NULL,
        file_name text NULL,
        CONSTRAINT pk_doc_banner_docs PRIMARY KEY (doc_banner_docs_id),
        CONSTRAINT fk_doc_banner_docs_doc_banners_doc_banner_id FOREIGN KEY (doc_banner_id) REFERENCES doc_banners (doc_banner_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE management_docs (
        management_doc_id uuid NOT NULL,
        file bytea NULL,
        file_type text NULL,
        file_name text NULL,
        management_id uuid NULL,
        CONSTRAINT pk_management_docs PRIMARY KEY (management_doc_id),
        CONSTRAINT fk_management_docs_managements_management_id FOREIGN KEY (management_id) REFERENCES managements (management_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE accounts (
        accounts_id uuid NOT NULL,
        created_by_user_id uuid NOT NULL,
        user_id uuid NULL,
        residence_id uuid NULL,
        fee_title text NULL,
        fees double precision NOT NULL,
        description text NULL,
        bill_for integer NOT NULL,
        payment_status integer NOT NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_accounts PRIMARY KEY (accounts_id),
        CONSTRAINT fk_accounts_residences_residence_id FOREIGN KEY (residence_id) REFERENCES residences (residence_id),
        CONSTRAINT fk_accounts_users_user_id FOREIGN KEY (user_id) REFERENCES users (user_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE complaints (
        complaint_id uuid NOT NULL,
        user_id uuid NULL,
        residence_id uuid NULL,
        subject text NULL,
        message text NULL,
        status integer NOT NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_complaints PRIMARY KEY (complaint_id),
        CONSTRAINT fk_complaints_residences_residence_id FOREIGN KEY (residence_id) REFERENCES residences (residence_id),
        CONSTRAINT fk_complaints_users_user_id FOREIGN KEY (user_id) REFERENCES users (user_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE facility_bookings (
        facility_booking_id uuid NOT NULL,
        user_id uuid NULL,
        residence_id uuid NULL,
        facility_id uuid NULL,
        date text NULL,
        remark text NULL,
        status integer NOT NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_facility_bookings PRIMARY KEY (facility_booking_id),
        CONSTRAINT fk_facility_bookings_facilitys_facility_id FOREIGN KEY (facility_id) REFERENCES facilitys (facility_id),
        CONSTRAINT fk_facility_bookings_residences_residence_id FOREIGN KEY (residence_id) REFERENCES residences (residence_id),
        CONSTRAINT fk_facility_bookings_users_user_id FOREIGN KEY (user_id) REFERENCES users (user_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE otp_trackers (
        otp_tracker_id uuid NOT NULL,
        user_id uuid NULL,
        code integer NOT NULL,
        from_email text NULL,
        to_email text NULL,
        purpose integer NOT NULL,
        is_send_by integer NOT NULL,
        cc_list text NULL,
        is_send boolean NOT NULL,
        is_expired boolean NOT NULL,
        date_created timestamp without time zone NOT NULL,
        date_updated timestamp without time zone NOT NULL,
        error text NULL,
        context text NULL,
        CONSTRAINT pk_otp_trackers PRIMARY KEY (otp_tracker_id),
        CONSTRAINT fk_otp_trackers_users_user_id FOREIGN KEY (user_id) REFERENCES users (user_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE technicians (
        technician_id uuid NOT NULL,
        technician_user_user_id uuid NULL,
        management_id uuid NULL,
        job_title text NULL,
        description text NULL,
        priorities integer NOT NULL,
        status integer NOT NULL,
        proof bytea NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        CONSTRAINT pk_technicians PRIMARY KEY (technician_id),
        CONSTRAINT fk_technicians_managements_management_id FOREIGN KEY (management_id) REFERENCES managements (management_id),
        CONSTRAINT fk_technicians_users_technician_user_user_id FOREIGN KEY (technician_user_user_id) REFERENCES users (user_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE units (
        unit_id uuid NOT NULL,
        unit_prefix text NULL,
        unit_floor_number text NULL,
        unit_number text NULL,
        is_primary boolean NOT NULL,
        unit_role integer NOT NULL,
        unit_furnish_type integer NOT NULL,
        unit_type integer NOT NULL,
        lease_from timestamp without time zone NOT NULL,
        lease_to timestamp without time zone NOT NULL,
        unit_price double precision NOT NULL,
        number_of_bed_room integer NOT NULL,
        number_of_bathroom integer NOT NULL,
        description text NULL,
        unit_status integer NOT NULL,
        unit_sold_date timestamp without time zone NOT NULL,
        date_created timestamp without time zone NOT NULL,
        date_modified timestamp without time zone NOT NULL,
        building_id uuid NULL,
        user_id uuid NULL,
        unit_tenant_role integer NOT NULL,
        tenant uuid NULL,
        tenant_active boolean NOT NULL,
        CONSTRAINT pk_units PRIMARY KEY (unit_id),
        CONSTRAINT fk_units_buildings_building_id FOREIGN KEY (building_id) REFERENCES buildings (building_id),
        CONSTRAINT fk_units_users_user_id FOREIGN KEY (user_id) REFERENCES users (user_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE complaint_docs (
        complaint_doc_id uuid NOT NULL,
        complaint_id uuid NULL,
        file bytea NULL,
        file_type text NULL,
        file_name text NULL,
        CONSTRAINT pk_complaint_docs PRIMARY KEY (complaint_doc_id),
        CONSTRAINT fk_complaint_docs_complaints_complaint_id FOREIGN KEY (complaint_id) REFERENCES complaints (complaint_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE add_tenants (
        tenant_id uuid NOT NULL,
        unit_id uuid NULL,
        user_id uuid NULL,
        unit_role integer NOT NULL,
        tenant_start timestamp without time zone NOT NULL,
        tenant_end timestamp without time zone NOT NULL,
        status integer NOT NULL,
        CONSTRAINT pk_add_tenants PRIMARY KEY (tenant_id),
        CONSTRAINT fk_add_tenants_units_unit_id FOREIGN KEY (unit_id) REFERENCES units (unit_id),
        CONSTRAINT fk_add_tenants_users_user_id FOREIGN KEY (user_id) REFERENCES users (user_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE unit_docs (
        unit_doc_id uuid NOT NULL,
        file bytea NULL,
        file_type text NULL,
        file_name text NULL,
        unit_id uuid NULL,
        CONSTRAINT pk_unit_docs PRIMARY KEY (unit_doc_id),
        CONSTRAINT fk_unit_docs_units_unit_id FOREIGN KEY (unit_id) REFERENCES units (unit_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE TABLE visitors (
        visitor_id uuid NOT NULL,
        residence_id uuid NULL,
        unit_id uuid NULL,
        building_id uuid NULL,
        name text NULL,
        ic_number text NULL,
        perpouse_of_visit integer NOT NULL,
        visit_by integer NOT NULL,
        vehicle_number text NULL,
        is_pre_visit boolean NOT NULL,
        user_id uuid NULL,
        parking_id uuid NOT NULL,
        check_in timestamp without time zone NULL,
        check_out timestamp without time zone NULL,
        CONSTRAINT pk_visitors PRIMARY KEY (visitor_id),
        CONSTRAINT fk_visitors_buildings_building_id FOREIGN KEY (building_id) REFERENCES buildings (building_id),
        CONSTRAINT fk_visitors_residences_residence_id FOREIGN KEY (residence_id) REFERENCES residences (residence_id),
        CONSTRAINT fk_visitors_units_unit_id FOREIGN KEY (unit_id) REFERENCES units (unit_id),
        CONSTRAINT fk_visitors_users_user_id FOREIGN KEY (user_id) REFERENCES users (user_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_accounts_residence_id ON accounts (residence_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_accounts_user_id ON accounts (user_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_add_tenants_unit_id ON add_tenants (unit_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_add_tenants_user_id ON add_tenants (user_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_announcement_docs_announcement_id ON announcement_docs (announcement_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_announcements_residence_id ON announcements (residence_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_buildings_residence_id ON buildings (residence_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_checkpoints_residence_id ON checkpoints (residence_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_complaint_docs_complaint_id ON complaint_docs (complaint_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_complaints_residence_id ON complaints (residence_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_complaints_user_id ON complaints (user_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_doc_banner_docs_doc_banner_id ON doc_banner_docs (doc_banner_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_doc_banners_residence_id ON doc_banners (residence_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_facility_bookings_facility_id ON facility_bookings (facility_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_facility_bookings_residence_id ON facility_bookings (residence_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_facility_bookings_user_id ON facility_bookings (user_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_management_docs_management_id ON management_docs (management_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_managements_residence_id ON managements (residence_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_otp_trackers_user_id ON otp_trackers (user_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_residence_docs_residence_id ON residence_docs (residence_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_residence_facilities_facility_id ON residence_facilities (facility_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_residence_facilities_residence_id ON residence_facilities (residence_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_ser_providers_residence_id ON ser_providers (residence_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_slots_residence_id ON slots (residence_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_technicians_management_id ON technicians (management_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_technicians_technician_user_user_id ON technicians (technician_user_user_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_unit_docs_unit_id ON unit_docs (unit_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_units_building_id ON units (building_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_units_user_id ON units (user_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_users_residence_id ON users (residence_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_visitors_building_id ON visitors (building_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_visitors_residence_id ON visitors (residence_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_visitors_unit_id ON visitors (unit_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    CREATE INDEX ix_visitors_user_id ON visitors (user_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830202733_Initial') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20230830202733_Initial', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830224526_visitecheck') THEN
    ALTER TABLE visitors ADD is_check_in boolean NOT NULL DEFAULT FALSE;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830224526_visitecheck') THEN
    ALTER TABLE visitors ADD is_check_out boolean NOT NULL DEFAULT FALSE;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230830224526_visitecheck') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20230830224526_visitecheck', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230901132140_slotupdate') THEN
    ALTER TABLE slots ADD facility_id uuid NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230901132140_slotupdate') THEN
    ALTER TABLE facility_bookings ADD slot_id uuid NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230901132140_slotupdate') THEN
    CREATE INDEX ix_slots_facility_id ON slots (facility_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230901132140_slotupdate') THEN
    CREATE INDEX ix_facility_bookings_slot_id ON facility_bookings (slot_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230901132140_slotupdate') THEN
    ALTER TABLE facility_bookings ADD CONSTRAINT fk_facility_bookings_slots_slot_id FOREIGN KEY (slot_id) REFERENCES slots (slot_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230901132140_slotupdate') THEN
    ALTER TABLE slots ADD CONSTRAINT fk_slots_facilitys_facility_id FOREIGN KEY (facility_id) REFERENCES facilitys (facility_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20230901132140_slotupdate') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20230901132140_slotupdate', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231008154700_devicetoken added') THEN
    ALTER TABLE users ADD device_token text NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231008154700_devicetoken added') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231008154700_devicetoken added', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231018150111_Technicial Document Added') THEN
    CREATE TABLE technician_docs (
        technician_doc_id uuid NOT NULL,
        technician_id uuid NULL,
        file bytea NULL,
        file_type text NULL,
        file_name text NULL,
        CONSTRAINT pk_technician_docs PRIMARY KEY (technician_doc_id),
        CONSTRAINT fk_technician_docs_technicians_technician_id FOREIGN KEY (technician_id) REFERENCES technicians (technician_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231018150111_Technicial Document Added') THEN
    CREATE INDEX ix_technician_docs_technician_id ON technician_docs (technician_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231018150111_Technicial Document Added') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231018150111_Technicial Document Added', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231018153258_Tech update') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231018153258_Tech update', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231018153411_some update') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231018153411_some update', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231019131801_tech some update') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231019131801_tech some update', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231020021129_tech remark added') THEN
    ALTER TABLE technicians ADD remark text NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231020021129_tech remark added') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231020021129_tech remark added', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231020132717_added isview option') THEN
    ALTER TABLE technicians ADD is_viewed boolean NOT NULL DEFAULT FALSE;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231020132717_added isview option') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231020132717_added isview option', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231029164037_visitor proof added') THEN
    ALTER TABLE visitors ADD file bytea NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231029164037_visitor proof added') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231029164037_visitor proof added', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231120161808_initialAccount') THEN
    ALTER TABLE accounts ADD unit_id uuid NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231120161808_initialAccount') THEN
    CREATE INDEX ix_accounts_unit_id ON accounts (unit_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231120161808_initialAccount') THEN
    ALTER TABLE accounts ADD CONSTRAINT fk_accounts_units_unit_id FOREIGN KEY (unit_id) REFERENCES units (unit_id);
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231120161808_initialAccount') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231120161808_initialAccount', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231121152737_account some update') THEN
    ALTER TABLE accounts ADD is_close boolean NOT NULL DEFAULT FALSE;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231121152737_account some update') THEN
    ALTER TABLE accounts ADD repeat text NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231121152737_account some update') THEN
    ALTER TABLE accounts ADD send_date text NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231121152737_account some update') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231121152737_account some update', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231123044409_someaccountupdate') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231123044409_someaccountupdate', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231123045043_accupdate') THEN
    ALTER TABLE accounts RENAME COLUMN verified TO verified_by_admin;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231123045043_accupdate') THEN
    ALTER TABLE accounts RENAME COLUMN proof TO payment_proof;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231123045043_accupdate') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231123045043_accupdate', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231123045612_paymantupdate') THEN
    ALTER TABLE accounts RENAME COLUMN payments_by TO payment_by;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231123045612_paymantupdate') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231123045612_paymantupdate', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231123104203_accountpaystatus') THEN
    ALTER TABLE accounts ADD verified_admin_status integer NOT NULL DEFAULT 0;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231123104203_accountpaystatus') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231123104203_accountpaystatus', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231126081350_LocationAdded') THEN
    ALTER TABLE guard_checkpoints ADD location text NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231126081350_LocationAdded') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231126081350_LocationAdded', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231127040353_unitparking ') THEN
    CREATE TABLE unit_parkings (
        unit_parking_id uuid NOT NULL,
        residence_id uuid NOT NULL,
        parking_number integer NOT NULL,
        parking_name text NULL,
        unit_id uuid NOT NULL,
        check_in_date_time timestamp without time zone NOT NULL,
        check_out_date_time timestamp without time zone NOT NULL,
        CONSTRAINT pk_unit_parkings PRIMARY KEY (unit_parking_id)
    );
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231127040353_unitparking ') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231127040353_unitparking ', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231228122337_checkpoint update') THEN
    ALTER TABLE checkpoints ADD file1 bytea NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231228122337_checkpoint update') THEN
    ALTER TABLE checkpoints ADD file2 bytea NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231228122337_checkpoint update') THEN
    ALTER TABLE checkpoints ADD file3 bytea NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231228122337_checkpoint update') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231228122337_checkpoint update', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231228124103_gurd checkpoint') THEN
    ALTER TABLE guard_checkpoints ADD proof2 bytea NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231228124103_gurd checkpoint') THEN
    ALTER TABLE guard_checkpoints ADD proof3 bytea NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231228124103_gurd checkpoint') THEN
    ALTER TABLE guard_checkpoints ADD proof4 bytea NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20231228124103_gurd checkpoint') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20231228124103_gurd checkpoint', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20240404013713_checkpoint') THEN
    ALTER TABLE checkpoints DROP COLUMN file1;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20240404013713_checkpoint') THEN
    ALTER TABLE checkpoints DROP COLUMN file2;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20240404013713_checkpoint') THEN
    ALTER TABLE checkpoints DROP COLUMN file3;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20240404013713_checkpoint') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20240404013713_checkpoint', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20240404014045_checkpointstuff') THEN
    ALTER TABLE checkpoints ADD file1 bytea NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20240404014045_checkpointstuff') THEN
    ALTER TABLE checkpoints ADD file2 bytea NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20240404014045_checkpointstuff') THEN
    ALTER TABLE checkpoints ADD file3 bytea NULL;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20240404014045_checkpointstuff') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20240404014045_checkpointstuff', '6.0.4');
    END IF;
END $EF$;
COMMIT;

START TRANSACTION;


DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20240404014337_checkpointstuff1') THEN
    ALTER TABLE checkpoints DROP COLUMN file1;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20240404014337_checkpointstuff1') THEN
    ALTER TABLE checkpoints DROP COLUMN file2;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20240404014337_checkpointstuff1') THEN
    ALTER TABLE checkpoints DROP COLUMN file3;
    END IF;
END $EF$;

DO $EF$
BEGIN
    IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "migration_id" = '20240404014337_checkpointstuff1') THEN
    INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
    VALUES ('20240404014337_checkpointstuff1', '6.0.4');
    END IF;
END $EF$;
COMMIT;

