sqlalchemy.DATE

Here are the examples of the python api sqlalchemy.DATE taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

3 Source : 2020_04_09_f1c0140a53d4_add_last_updated_to_user.py
with MIT License
from Nukesor

def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("user", "last_update")
    op.add_column(
        "poll",
        sa.Column(
            "current_date",
            sa.DATE(),
            server_default=sa.text("now()"),
            autoincrement=False,
            nullable=False,
        ),
    )
    # ### end Alembic commands ###

0 Source : 2021_05_03_1400_bea81e3e03ef_entity_documentation_part_5.py
with GNU General Public License v3.0
from Recidiviz

def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "state_program_assignment",
        "discharge_date",
        existing_type=sa.DATE(),
        comment="The date the person was discharged from the program, if applicable.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment",
        "discharge_reason",
        existing_type=postgresql.ENUM(
            "EXTERNAL_UNKNOWN",
            "ABSCONDED",
            "ADVERSE_TERMINATION",
            "COMPLETED",
            "MOVED",
            "OPTED_OUT",
            "PROGRAM_TRANSFER",
            "REINCARCERATED",
            name="state_program_assignment_discharge_reason",
        ),
        comment="The reason the person was discharged from the program, if applicable.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment",
        "discharge_reason_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value for the discharge reason.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment",
        "external_id",
        existing_type=sa.VARCHAR(length=255),
        comment="The unique identifier for the StateProgramAssignment, unique within the scope of the source data system.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment",
        "participation_status",
        existing_type=postgresql.ENUM(
            "DENIED",
            "DISCHARGED",
            "EXTERNAL_UNKNOWN",
            "IN_PROGRESS",
            "PENDING",
            "PRESENT_WITHOUT_INFO",
            "REFUSED",
            name="state_program_assignment_participation_status",
        ),
        comment="The status of the person's participation in the program.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_program_assignment",
        "participation_status_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the participation status.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment",
        "program_assignment_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) program assignment, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to others.",
        existing_nullable=False,
        autoincrement=True,
        existing_server_default=sa.text(
            "nextval('state_program_assignment_program_assignment_id_seq'::regclass)"
        ),
    )
    op.alter_column(
        "state_program_assignment",
        "program_id",
        existing_type=sa.VARCHAR(length=255),
        comment="Unique identifier for a program being assigned to.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment",
        "program_location_id",
        existing_type=sa.VARCHAR(length=255),
        comment="The id of where the program takes place.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment",
        "referral_date",
        existing_type=sa.DATE(),
        comment="The date the person was referred to the program, if applicable.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment",
        "referral_metadata",
        existing_type=sa.TEXT(),
        comment="This includes whichever fields and values are relevant to a fine understanding of a particular referral. It can be provided in any format, but will be transformed into JSON prior to persistence.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment",
        "referring_agent_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) state agent, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to relevant state agent information.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment",
        "start_date",
        existing_type=sa.DATE(),
        comment="The date the person started the program, if applicable.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment",
        "state_code",
        existing_type=sa.VARCHAR(length=255),
        comment="The U.S. state or region that provided the source data.",
        existing_nullable=False,
    )
    op.create_table_comment(
        "state_program_assignment",
        "The StateProgramAssignment object represents information about the assignment of a person to some form of rehabilitative programming -- and their participation in the program -- intended to address specific needs of the person. People can be assigned to programs while under various forms of custody, principally while incarcerated or under supervision. These programs can be administered by the agency/government, by a quasi-governmental organization, by a private third party, or any other number of service providers. A StateProgramAssignment is always for a particular person, but it may also be optionally linked to a particular StateIncarcerationPeriod or StateSupervisionPeriod if the program is explicitly within the bounds of that period of custody. The programming-related portion of our schema is still being constructed and will be added to in the near future.",
        existing_comment=None,
        schema=None,
    )
    op.alter_column(
        "state_program_assignment_history",
        "discharge_date",
        existing_type=sa.DATE(),
        comment="The date the person was discharged from the program, if applicable.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment_history",
        "discharge_reason",
        existing_type=postgresql.ENUM(
            "EXTERNAL_UNKNOWN",
            "ABSCONDED",
            "ADVERSE_TERMINATION",
            "COMPLETED",
            "MOVED",
            "OPTED_OUT",
            "PROGRAM_TRANSFER",
            "REINCARCERATED",
            name="state_program_assignment_discharge_reason",
        ),
        comment="The reason the person was discharged from the program, if applicable.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment_history",
        "discharge_reason_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value for the discharge reason.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment_history",
        "external_id",
        existing_type=sa.VARCHAR(length=255),
        comment="The unique identifier for the StateProgramAssignment, unique within the scope of the source data system.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment_history",
        "participation_status",
        existing_type=postgresql.ENUM(
            "DENIED",
            "DISCHARGED",
            "EXTERNAL_UNKNOWN",
            "IN_PROGRESS",
            "PENDING",
            "PRESENT_WITHOUT_INFO",
            "REFUSED",
            name="state_program_assignment_participation_status",
        ),
        comment="The status of the person's participation in the program.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_program_assignment_history",
        "participation_status_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the participation status.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment_history",
        "program_assignment_history_id",
        existing_type=sa.INTEGER(),
        comment="This primary key should not be used. It only exists because SQLAlchemy requires every table to have a unique primary key.",
        existing_nullable=False,
        autoincrement=True,
    )
    op.alter_column(
        "state_program_assignment_history",
        "program_assignment_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) program assignment, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to relevant program assignment information.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_program_assignment_history",
        "program_id",
        existing_type=sa.VARCHAR(length=255),
        comment="Unique identifier for a program being assigned to.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment_history",
        "program_location_id",
        existing_type=sa.VARCHAR(length=255),
        comment="The id of where the program takes place.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment_history",
        "referral_date",
        existing_type=sa.DATE(),
        comment="The date the person was referred to the program, if applicable.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment_history",
        "referral_metadata",
        existing_type=sa.TEXT(),
        comment="This includes whichever fields and values are relevant to a fine understanding of a particular referral. It can be provided in any format, but will be transformed into JSON prior to persistence.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment_history",
        "referring_agent_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) state agent, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to relevant state agent information.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment_history",
        "start_date",
        existing_type=sa.DATE(),
        comment="The date the person started the program, if applicable.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_program_assignment_history",
        "state_code",
        existing_type=sa.VARCHAR(length=255),
        comment="The U.S. state or region that provided the source data.",
        existing_nullable=False,
    )
    op.create_table_comment(
        "state_program_assignment_history",
        "Represents all updates that have made to a(n) StateProgramAssignment object over time.",
        existing_comment=None,
        schema=None,
    )
    op.alter_column(
        "state_sentence_group",
        "county_code",
        existing_type=sa.VARCHAR(length=255),
        comment="DEPRECATED. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_sentence_group",
        "date_imposed",
        existing_type=sa.DATE(),
        comment="DEPRECATED. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_sentence_group",
        "external_id",
        existing_type=sa.VARCHAR(length=255),
        comment="DEPRECATED. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_sentence_group",
        "is_life",
        existing_type=sa.BOOLEAN(),
        comment="DEPRECATED. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_sentence_group",
        "max_length_days",
        existing_type=sa.INTEGER(),
        comment="DEPRECATED. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_sentence_group",
        "min_length_days",
        existing_type=sa.INTEGER(),
        comment="DEPRECATED. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_sentence_group",
        "sentence_group_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) sentence group, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to others.",
        existing_nullable=False,
        autoincrement=True,
        existing_server_default=sa.text(
            "nextval('state_sentence_group_sentence_group_id_seq'::regclass)"
        ),
    )
    op.alter_column(
        "state_sentence_group",
        "state_code",
        existing_type=sa.VARCHAR(length=255),
        comment="DEPRECATED. See #2891.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_sentence_group",
        "status",
        existing_type=postgresql.ENUM(
            "COMMUTED",
            "COMPLETED",
            "EXTERNAL_UNKNOWN",
            "PARDONED",
            "PRESENT_WITHOUT_INFO",
            "REVOKED",
            "SERVING",
            "SUSPENDED",
            "VACATED",
            name="state_sentence_status",
        ),
        comment="DEPRECATED. See #2891.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_sentence_group",
        "status_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="DEPRECATED. See #2891.",
        existing_nullable=True,
    )
    op.create_table_comment(
        "state_sentence_group",
        "DEPRECATED. See #2891.",
        existing_comment=None,
        schema=None,
    )
    op.alter_column(
        "state_sentence_group_history",
        "county_code",
        existing_type=sa.VARCHAR(length=255),
        comment="DEPRECATED. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_sentence_group_history",
        "date_imposed",
        existing_type=sa.DATE(),
        comment="DEPRECATED. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_sentence_group_history",
        "external_id",
        existing_type=sa.VARCHAR(length=255),
        comment="DEPRECATED. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_sentence_group_history",
        "is_life",
        existing_type=sa.BOOLEAN(),
        comment="DEPRECATED. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_sentence_group_history",
        "max_length_days",
        existing_type=sa.INTEGER(),
        comment="DEPRECATED. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_sentence_group_history",
        "min_length_days",
        existing_type=sa.INTEGER(),
        comment="DEPRECATED. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_sentence_group_history",
        "sentence_group_history_id",
        existing_type=sa.INTEGER(),
        comment="DEPRECATED. See #2891.",
        existing_nullable=False,
        autoincrement=True,
    )
    op.alter_column(
        "state_sentence_group_history",
        "sentence_group_id",
        existing_type=sa.INTEGER(),
        comment="DEPRECATED. See #2891.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_sentence_group_history",
        "state_code",
        existing_type=sa.VARCHAR(length=255),
        comment="DEPRECATED. See #2891.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_sentence_group_history",
        "status",
        existing_type=postgresql.ENUM(
            "COMMUTED",
            "COMPLETED",
            "EXTERNAL_UNKNOWN",
            "PARDONED",
            "PRESENT_WITHOUT_INFO",
            "REVOKED",
            "SERVING",
            "SUSPENDED",
            "VACATED",
            name="state_sentence_status",
        ),
        comment="DEPRECATED. See #2891.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_sentence_group_history",
        "status_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="DEPRECATED. See #2891.",
        existing_nullable=True,
    )
    op.create_table_comment(
        "state_sentence_group_history",
        "DEPRECATED. See #2891.",
        existing_comment=None,
        schema=None,
    )
    op.alter_column(
        "state_supervision_case_type_entry",
        "case_type",
        existing_type=postgresql.ENUM(
            "ALCOHOL_DRUG",
            "DOMESTIC_VIOLENCE",
            "DRUG_COURT",
            "FAMILY_COURT",
            "GENERAL",
            "MENTAL_HEALTH_COURT",
            "SERIOUS_MENTAL_ILLNESS",
            "SEX_OFFENSE",
            "VETERANS_COURT",
            name="state_supervision_case_type",
        ),
        comment="The type of case that describes the associated period of supervision.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_case_type_entry",
        "case_type_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the case type.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_case_type_entry",
        "external_id",
        existing_type=sa.VARCHAR(length=255),
        comment="The unique identifier for the StateSupervisionCaseTypeEntry, unique within the scope of the source data system.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_case_type_entry",
        "state_code",
        existing_type=sa.VARCHAR(length=255),
        comment="The U.S. state or region that provided the source data.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_supervision_case_type_entry",
        "supervision_case_type_entry_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) case type entry, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to others.",
        existing_nullable=False,
        autoincrement=True,
        existing_server_default=sa.text(
            "nextval('state_supervision_case_type_e_supervision_case_type_entry_i_seq'::regclass)"
        ),
    )
    op.alter_column(
        "state_supervision_case_type_entry",
        "supervision_period_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) state supervision period, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to relevant state supervision period information.",
        existing_nullable=True,
    )
    op.create_table_comment(
        "state_supervision_case_type_entry",
        "The StateSupervisionCaseTypeEntry object represents a particular case type that applies to this period of supervision. A case type implies certain conditions of supervision that may apply, or certain levels or intensity of supervision, or certain kinds of specialized courts that generated the sentence to supervision, or even that the person being supervised may be supervised by particular kinds of officers with particular types of caseloads they are responsible for. A StateSupervisionPeriod may have zero to many distinct case types.",
        existing_comment=None,
        schema=None,
    )
    op.alter_column(
        "state_supervision_case_type_entry_history",
        "case_type",
        existing_type=postgresql.ENUM(
            "ALCOHOL_DRUG",
            "DOMESTIC_VIOLENCE",
            "DRUG_COURT",
            "FAMILY_COURT",
            "GENERAL",
            "MENTAL_HEALTH_COURT",
            "SERIOUS_MENTAL_ILLNESS",
            "SEX_OFFENSE",
            "VETERANS_COURT",
            name="state_supervision_case_type",
        ),
        comment="The type of case that describes the associated period of supervision.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_case_type_entry_history",
        "case_type_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the case type.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_case_type_entry_history",
        "state_code",
        existing_type=sa.VARCHAR(length=255),
        comment="The U.S. state or region that provided the source data.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_supervision_case_type_entry_history",
        "supervision_case_type_entry_history_id",
        existing_type=sa.INTEGER(),
        comment="This primary key should not be used. It only exists because SQLAlchemy requires every table to have a unique primary key.",
        existing_nullable=False,
        autoincrement=True,
    )
    op.alter_column(
        "state_supervision_case_type_entry_history",
        "supervision_case_type_entry_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) state case type entry, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to relevant state case type entry information.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_supervision_case_type_entry_history",
        "supervision_period_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) state supervision period, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to relevant state supervision period information.",
        existing_nullable=True,
    )
    op.create_table_comment(
        "state_supervision_case_type_entry_history",
        "Represents all updates that have made to a(n) StateSupervisionCaseTypeEntry object over time.",
        existing_comment=None,
        schema=None,
    )
    op.alter_column(
        "state_supervision_contact",
        "contact_date",
        existing_type=sa.DATE(),
        comment="The date when this contact happened.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact",
        "contact_reason",
        existing_type=postgresql.ENUM(
            "INTERNAL_UNKNOWN",
            "EXTERNAL_UNKNOWN",
            "EMERGENCY_CONTACT",
            "GENERAL_CONTACT",
            "INITIAL_CONTACT",
            name="state_supervision_contact_reason",
        ),
        comment="The reason why this contact took place.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact",
        "contact_reason_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the contact reason.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact",
        "contact_type",
        existing_type=postgresql.ENUM(
            "INTERNAL_UNKNOWN",
            "EXTERNAL_UNKNOWN",
            "FACE_TO_FACE",
            "TELEPHONE",
            "WRITTEN_MESSAGE",
            "VIRTUAL",
            name="state_supervision_contact_type",
        ),
        comment="The type of contact which took place.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact",
        "contact_type_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the contact type.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact",
        "contacted_agent_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) state agent, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to relevant state agent information.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact",
        "external_id",
        existing_type=sa.VARCHAR(length=255),
        comment="The unique identifier for the StateSupervisionContact, unique within the scope of the source data system.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact",
        "location",
        existing_type=postgresql.ENUM(
            "INTERNAL_UNKNOWN",
            "EXTERNAL_UNKNOWN",
            "COURT",
            "FIELD",
            "JAIL",
            "PLACE_OF_EMPLOYMENT",
            "RESIDENCE",
            "SUPERVISION_OFFICE",
            "TREATMENT_PROVIDER",
            name="state_supervision_contact_location",
        ),
        comment="Where this contact took place.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact",
        "location_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the contact location.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact",
        "resulted_in_arrest",
        existing_type=sa.BOOLEAN(),
        comment="Whether or not this contact resulted in the person's arrest.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact",
        "state_code",
        existing_type=sa.VARCHAR(length=255),
        comment="The U.S. state or region that provided the source data.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_supervision_contact",
        "status",
        existing_type=postgresql.ENUM(
            "INTERNAL_UNKNOWN",
            "EXTERNAL_UNKNOWN",
            "ATTEMPTED",
            "COMPLETED",
            name="state_supervision_contact_status",
        ),
        comment="The current status of this contact.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact",
        "status_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the contact status.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact",
        "supervision_contact_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) supervision contact, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to others.",
        existing_nullable=False,
        autoincrement=True,
        existing_server_default=sa.text(
            "nextval('state_supervision_contact_supervision_contact_id_seq'::regclass)"
        ),
    )
    op.alter_column(
        "state_supervision_contact",
        "verified_employment",
        existing_type=sa.BOOLEAN(),
        comment="Whether or not the person's current employment status was verified at this contact.",
        existing_nullable=True,
    )
    op.create_table_comment(
        "state_supervision_contact",
        "The StateSupervisionContact object represents information about a point of contact between a person under supervision and some agent representing the department, typically a supervising officer. These may include face-to-face meetings, phone calls, emails, or other such media. At these contacts, specific things may occur, such as referral to programming or written warnings or even arrest, but any and all events that happen as part of a single contact are modeled as one supervision contact. StateSupervisionPeriods have zero to many StateSupervisionContacts as children, and each StateSupervisionContact has one to many StateSupervisionPeriods as parents. This is because a given person may be serving multiple periods of supervision simultaneously in rare cases, and a given point of contact may apply to both.",
        existing_comment=None,
        schema=None,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "contact_date",
        existing_type=sa.DATE(),
        comment="The date when this contact happened.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "contact_reason",
        existing_type=postgresql.ENUM(
            "INTERNAL_UNKNOWN",
            "EXTERNAL_UNKNOWN",
            "EMERGENCY_CONTACT",
            "GENERAL_CONTACT",
            "INITIAL_CONTACT",
            name="state_supervision_contact_reason",
        ),
        comment="The reason why this contact took place.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "contact_reason_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the contact reason.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "contact_type",
        existing_type=postgresql.ENUM(
            "INTERNAL_UNKNOWN",
            "EXTERNAL_UNKNOWN",
            "FACE_TO_FACE",
            "TELEPHONE",
            "WRITTEN_MESSAGE",
            "VIRTUAL",
            name="state_supervision_contact_type",
        ),
        comment="The type of contact which took place.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "contact_type_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the contact type.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "contacted_agent_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) state agent, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to relevant state agent information.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "external_id",
        existing_type=sa.VARCHAR(length=255),
        comment="The unique identifier for the StateSupervisionContact, unique within the scope of the source data system.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "location",
        existing_type=postgresql.ENUM(
            "INTERNAL_UNKNOWN",
            "EXTERNAL_UNKNOWN",
            "COURT",
            "FIELD",
            "JAIL",
            "PLACE_OF_EMPLOYMENT",
            "RESIDENCE",
            "SUPERVISION_OFFICE",
            "TREATMENT_PROVIDER",
            name="state_supervision_contact_location",
        ),
        comment="Where this contact took place.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "location_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the contact location.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "resulted_in_arrest",
        existing_type=sa.BOOLEAN(),
        comment="Whether or not this contact resulted in the person's arrest.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "state_code",
        existing_type=sa.VARCHAR(length=255),
        comment="The U.S. state or region that provided the source data.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "status",
        existing_type=postgresql.ENUM(
            "INTERNAL_UNKNOWN",
            "EXTERNAL_UNKNOWN",
            "ATTEMPTED",
            "COMPLETED",
            name="state_supervision_contact_status",
        ),
        comment="The current status of this contact.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "status_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the contact status.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "supervision_contact_history_id",
        existing_type=sa.INTEGER(),
        comment="This primary key should not be used. It only exists because SQLAlchemy requires every table to have a unique primary key.",
        existing_nullable=False,
        autoincrement=True,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "supervision_contact_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) state supervision contact, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to relevant state supervision contact information.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_supervision_contact_history",
        "verified_employment",
        existing_type=sa.BOOLEAN(),
        comment="Whether or not the person's current employment status was verified at this contact.",
        existing_nullable=True,
    )
    op.create_table_comment(
        "state_supervision_contact_history",
        "Represents all updates that have made to a(n) StateSupervisionContact object over time.",
        existing_comment=None,
        schema=None,
    )
    op.alter_column(
        "state_supervision_period",
        "admission_reason",
        existing_type=postgresql.ENUM(
            "ABSCONSION",
            "CONDITIONAL_RELEASE",
            "COURT_SENTENCE",
            "EXTERNAL_UNKNOWN",
            "INVESTIGATION",
            "RETURN_FROM_ABSCONSION",
            "RETURN_FROM_SUSPENSION",
            "INTERNAL_UNKNOWN",
            "TRANSFER_OUT_OF_STATE",
            "TRANSFER_WITHIN_STATE",
            name="state_supervision_period_admission_reason",
        ),
        comment="The reason the person was admitted to this particular period of supervision.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "admission_reason_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the supervision period's admission reason.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "conditions",
        existing_type=sa.TEXT(),
        comment="The conditions of this period of supervision which the person must follow to avoid a disciplinary response.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "county_code",
        existing_type=sa.VARCHAR(length=255),
        comment="The code of the county where the person is currently supervised.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "custodial_authority",
        existing_type=postgresql.ENUM(
            "FEDERAL",
            "OTHER_COUNTRY",
            "OTHER_STATE",
            "SUPERVISION_AUTHORITY",
            "STATE_PRISON",
            name="state_custodial_authority",
        ),
        comment="The type of government entity directly responsible for the person in this period of incarceration. Not necessarily the decision making authority. For example, the supervision authority in a state might be the custodial authority for someone on probation, even though the courts are the body with the power to make decisions about that person's path through the system.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "custodial_authority_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the supervision period's custodial authority.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "external_id",
        existing_type=sa.VARCHAR(length=255),
        comment="The unique identifier for the StateSupervisionPeriod, unique within the scope of the source data system.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "start_date",
        existing_type=sa.DATE(),
        comment="The date the person began this period of supervision.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "state_code",
        existing_type=sa.VARCHAR(length=255),
        comment="The U.S. state or region that provided the source data.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_supervision_period",
        "status",
        existing_type=postgresql.ENUM(
            "EXTERNAL_UNKNOWN",
            "TERMINATED",
            "UNDER_SUPERVISION",
            "PRESENT_WITHOUT_INFO",
            name="state_supervision_period_status",
        ),
        comment="The current status of this period.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_supervision_period",
        "status_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the current status.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "supervising_officer_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) state agent, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to relevant state agent information.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "supervision_level",
        existing_type=postgresql.ENUM(
            "EXTERNAL_UNKNOWN",
            "INTERNAL_UNKNOWN",
            "PRESENT_WITHOUT_INFO",
            "DIVERSION",
            "INCARCERATED",
            "INTERSTATE_COMPACT",
            "IN_CUSTODY",
            "ELECTRONIC_MONITORING_ONLY",
            "LIMITED",
            "MINIMUM",
            "MEDIUM",
            "HIGH",
            "MAXIMUM",
            "UNSUPERVISED",
            name="state_supervision_level",
        ),
        comment="The level of supervision the person is receiving, i.e. an analog to the security level of incarceration, indicating frequency of contact, strictness of constraints, etc.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "supervision_level_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the supervision period's supervision level.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "supervision_period_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) supervision period, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to others.",
        existing_nullable=False,
        autoincrement=True,
        existing_server_default=sa.text(
            "nextval('state_supervision_period_supervision_period_id_seq'::regclass)"
        ),
    )
    op.alter_column(
        "state_supervision_period",
        "supervision_period_supervision_type",
        existing_type=postgresql.ENUM(
            "EXTERNAL_UNKNOWN",
            "INFORMAL_PROBATION",
            "INTERNAL_UNKNOWN",
            "INVESTIGATION",
            "PAROLE",
            "PROBATION",
            "DUAL",
            name="state_supervision_period_supervision_type",
        ),
        comment="The type of supervision the person is serving during this time period.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "supervision_period_supervision_type_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the supervision period supervision type.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "supervision_site",
        existing_type=sa.VARCHAR(length=255),
        comment="A single string encoding the location (i.e. office/region/district) this person is being supervised out of. This field may eventually be split into multiple to better encode supervision org structure. See #3829.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "supervision_type",
        existing_type=postgresql.ENUM(
            "CIVIL_COMMITMENT",
            "EXTERNAL_UNKNOWN",
            "INTERNAL_UNKNOWN",
            "HALFWAY_HOUSE",
            "PAROLE",
            "POST_CONFINEMENT",
            "PRE_CONFINEMENT",
            "PROBATION",
            name="state_supervision_type",
        ),
        comment="DEPRECATED - use supervision_period_supervision_type instead. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "supervision_type_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="DEPRECATED - use supervision_period_supervision_type instead. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "termination_date",
        existing_type=sa.DATE(),
        comment="The date the period of supervision was terminated, either positively or negatively.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "termination_reason",
        existing_type=postgresql.ENUM(
            "EXTERNAL_UNKNOWN",
            "ABSCONSION",
            "COMMUTED",
            "DEATH",
            "DISCHARGE",
            "DISMISSED",
            "EXPIRATION",
            "INVESTIGATION",
            "PARDONED",
            "RETURN_FROM_ABSCONSION",
            "RETURN_TO_INCARCERATION",
            "REVOCATION",
            "SUSPENSION",
            "INTERNAL_UNKNOWN",
            "TRANSFER_OUT_OF_STATE",
            "TRANSFER_WITHIN_STATE",
            name="state_supervision_period_termination_reason",
        ),
        comment="The reason the period of supervision was terminated.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period",
        "termination_reason_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the supervision period's termination reason.",
        existing_nullable=True,
    )
    op.create_table_comment(
        "state_supervision_period",
        "The StateSupervisionPeriod object represents information about a single period of supervision, defined as a contiguous period of custody for a particular person under a particular jurisdiction. As a person transfers from jurisdiction to jurisdiction, these are modeled as multiple abutting supervision periods. Multiple periods of supervision for a particular person may be overlapping, due to extended periods of supervision that are temporarily interrupted by, say, periods of incarceration, or periods of supervision stemming from charges in different jurisdictions.  <  br /> < br />StateSupervisionPeriods can be children of either StateIncarcerationSentences or StateSupervisionSentences, for reasons established in the descriptions of those objects. < br /> < br />StateSupervisionPeriods have zero to many StateSupervisionViolations as children. They also may have StateAssessments or StateProgramAssignments as children, if any of those objects are explicitly related to this particular period of supervision.",
        existing_comment=None,
        schema=None,
    )
    op.alter_column(
        "state_supervision_period_history",
        "admission_reason",
        existing_type=postgresql.ENUM(
            "ABSCONSION",
            "CONDITIONAL_RELEASE",
            "COURT_SENTENCE",
            "EXTERNAL_UNKNOWN",
            "INVESTIGATION",
            "RETURN_FROM_ABSCONSION",
            "RETURN_FROM_SUSPENSION",
            "INTERNAL_UNKNOWN",
            "TRANSFER_OUT_OF_STATE",
            "TRANSFER_WITHIN_STATE",
            name="state_supervision_period_admission_reason",
        ),
        comment="The reason the person was admitted to this particular period of supervision.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "admission_reason_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the supervision period's admission reason.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "conditions",
        existing_type=sa.TEXT(),
        comment="The conditions of this period of supervision which the person must follow to avoid a disciplinary response.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "county_code",
        existing_type=sa.VARCHAR(length=255),
        comment="The code of the county where the person is currently supervised.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "custodial_authority",
        existing_type=postgresql.ENUM(
            "FEDERAL",
            "OTHER_COUNTRY",
            "OTHER_STATE",
            "SUPERVISION_AUTHORITY",
            "STATE_PRISON",
            name="state_custodial_authority",
        ),
        comment="The type of government entity directly responsible for the person in this period of incarceration. Not necessarily the decision making authority. For example, the supervision authority in a state might be the custodial authority for someone on probation, even though the courts are the body with the power to make decisions about that person's path through the system.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "custodial_authority_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the supervision period's custodial authority.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "external_id",
        existing_type=sa.VARCHAR(length=255),
        comment="The unique identifier for the StateSupervisionPeriod, unique within the scope of the source data system.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "start_date",
        existing_type=sa.DATE(),
        comment="The date the person began this period of supervision.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "state_code",
        existing_type=sa.VARCHAR(length=255),
        comment="The U.S. state or region that provided the source data.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_supervision_period_history",
        "status",
        existing_type=postgresql.ENUM(
            "EXTERNAL_UNKNOWN",
            "TERMINATED",
            "UNDER_SUPERVISION",
            "PRESENT_WITHOUT_INFO",
            name="state_supervision_period_status",
        ),
        comment="The current status of this period.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_supervision_period_history",
        "status_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the current status.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "supervising_officer_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) state agent, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to relevant state agent information.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "supervision_level",
        existing_type=postgresql.ENUM(
            "EXTERNAL_UNKNOWN",
            "INTERNAL_UNKNOWN",
            "PRESENT_WITHOUT_INFO",
            "DIVERSION",
            "INCARCERATED",
            "INTERSTATE_COMPACT",
            "IN_CUSTODY",
            "ELECTRONIC_MONITORING_ONLY",
            "LIMITED",
            "MINIMUM",
            "MEDIUM",
            "HIGH",
            "MAXIMUM",
            "UNSUPERVISED",
            name="state_supervision_level",
        ),
        comment="The level of supervision the person is receiving, i.e. an analog to the security level of incarceration, indicating frequency of contact, strictness of constraints, etc.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "supervision_level_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the supervision period's supervision level.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "supervision_period_history_id",
        existing_type=sa.INTEGER(),
        comment="This primary key should not be used. It only exists because SQLAlchemy requires every table to have a unique primary key.",
        existing_nullable=False,
        autoincrement=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "supervision_period_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) state supervision period, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to relevant state supervision period information.",
        existing_nullable=False,
    )
    op.alter_column(
        "state_supervision_period_history",
        "supervision_period_supervision_type",
        existing_type=postgresql.ENUM(
            "EXTERNAL_UNKNOWN",
            "INFORMAL_PROBATION",
            "INTERNAL_UNKNOWN",
            "INVESTIGATION",
            "PAROLE",
            "PROBATION",
            "DUAL",
            name="state_supervision_period_supervision_type",
        ),
        comment="The type of supervision the person is serving during this time period.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "supervision_period_supervision_type_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the supervision period supervision type.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "supervision_site",
        existing_type=sa.VARCHAR(length=255),
        comment="A single string encoding the location (i.e. office/region/district) this person is being supervised out of. This field may eventually be split into multiple to better encode supervision org structure. See #3829.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "supervision_type",
        existing_type=postgresql.ENUM(
            "CIVIL_COMMITMENT",
            "EXTERNAL_UNKNOWN",
            "INTERNAL_UNKNOWN",
            "HALFWAY_HOUSE",
            "PAROLE",
            "POST_CONFINEMENT",
            "PRE_CONFINEMENT",
            "PROBATION",
            name="state_supervision_type",
        ),
        comment="DEPRECATED - use supervision_period_supervision_type instead. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "supervision_type_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="DEPRECATED - use supervision_period_supervision_type instead. See #2891.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "termination_date",
        existing_type=sa.DATE(),
        comment="The date the period of supervision was terminated, either positively or negatively.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "termination_reason",
        existing_type=postgresql.ENUM(
            "EXTERNAL_UNKNOWN",
            "ABSCONSION",
            "COMMUTED",
            "DEATH",
            "DISCHARGE",
            "DISMISSED",
            "EXPIRATION",
            "INVESTIGATION",
            "PARDONED",
            "RETURN_FROM_ABSCONSION",
            "RETURN_TO_INCARCERATION",
            "REVOCATION",
            "SUSPENSION",
            "INTERNAL_UNKNOWN",
            "TRANSFER_OUT_OF_STATE",
            "TRANSFER_WITHIN_STATE",
            name="state_supervision_period_termination_reason",
        ),
        comment="The reason the period of supervision was terminated.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_history",
        "termination_reason_raw_text",
        existing_type=sa.VARCHAR(length=255),
        comment="The raw text value of the supervision period's termination reason.",
        existing_nullable=True,
    )
    op.create_table_comment(
        "state_supervision_period_history",
        "Represents all updates that have made to a(n) StateSupervisionPeriod object over time.",
        existing_comment=None,
        schema=None,
    )
    op.alter_column(
        "state_supervision_period_program_assignment_association",
        "program_assignment_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) program assignment, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to relevant program assignment information.",
        existing_nullable=True,
    )
    op.alter_column(
        "state_supervision_period_program_assignment_association",
        "supervision_period_id",
        existing_type=sa.INTEGER(),
        comment="Unique identifier for a(n) supervision period, generated automatically by the Recidiviz system. This identifier is not stable over time (it may change if historical data is re-ingested), but should be used within the context of a given dataset to connect this object to relevant supervision period information.",
        existing_nullable=True,
    )
    # ### end Alembic commands ###


def downgrade() -> None: