From d6e0cfecfb69594c984563ac7e32d98f1b409e8a Mon Sep 17 00:00:00 2001 From: Jad Date: Thu, 11 Jan 2024 13:51:22 -0800 Subject: [PATCH 1/2] Add None ministry row --- .../09a79ca8e8fd_add_none_ministry.py | 60 +++++++++++++++++++ .../src/components/work/WorkForm/index.tsx | 3 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 epictrack-api/migrations/versions/09a79ca8e8fd_add_none_ministry.py diff --git a/epictrack-api/migrations/versions/09a79ca8e8fd_add_none_ministry.py b/epictrack-api/migrations/versions/09a79ca8e8fd_add_none_ministry.py new file mode 100644 index 000000000..a2ff43b41 --- /dev/null +++ b/epictrack-api/migrations/versions/09a79ca8e8fd_add_none_ministry.py @@ -0,0 +1,60 @@ +"""Add None ministry in ministries table + +Revision ID: 09a79ca8e8fd +Revises: 65cb91595d6a +Create Date: 2024-01-11 13:19:49.744798 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '09a79ca8e8fd' +down_revision = '65cb91595d6a' +branch_labels = None +depends_on = None + +NoneMinistryName = 'None' +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + + ministries = sa.table( + 'ministries', + sa.Column('id', sa.Integer), + sa.Column('name', sa.String), + sa.column('abbreviation', sa.String), + sa.Column('is_active', sa.Boolean), + sa.Column('is_deleted', sa.Boolean), + sa.Column('sort_order', sa.Integer), + ) + + ## select greatest id from ministries + conn = op.get_bind() + result = conn.execute( + sa.text( + "SELECT max(id) FROM ministries" + ) + ) + new_id = result.fetchone()[0] + 1 + + op.execute( + ministries.insert().values( + id=new_id, + name=NoneMinistryName, + abbreviation=NoneMinistryName, + is_active=True, + is_deleted=False, + sort_order=-1, + ) + ) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + + op.execute(f"delete from ministries where name='{NoneMinistryName}'") + + # ### end Alembic commands ### diff --git a/epictrack-web/src/components/work/WorkForm/index.tsx b/epictrack-web/src/components/work/WorkForm/index.tsx index c02b6167f..a228ec8ea 100644 --- a/epictrack-web/src/components/work/WorkForm/index.tsx +++ b/epictrack-web/src/components/work/WorkForm/index.tsx @@ -32,6 +32,7 @@ const schema = yup.object().shape({ work_type_id: yup.number().required("Work type is required"), start_date: yup.date().required("Start date is required"), project_id: yup.number().required("Project is required"), + ministry_id: yup.number().required("Responsible Ministry is required"), federal_involvement_id: yup .number() .required("Federal Involvement is required"), @@ -279,7 +280,7 @@ export default function WorkForm({ ...props }) { > - Responsible Ministry + Responsible Ministry Date: Fri, 12 Jan 2024 08:53:10 -0800 Subject: [PATCH 2/2] Remove unnecessary increment id logic --- .../versions/09a79ca8e8fd_add_none_ministry.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/epictrack-api/migrations/versions/09a79ca8e8fd_add_none_ministry.py b/epictrack-api/migrations/versions/09a79ca8e8fd_add_none_ministry.py index a2ff43b41..fb7cd5e7a 100644 --- a/epictrack-api/migrations/versions/09a79ca8e8fd_add_none_ministry.py +++ b/epictrack-api/migrations/versions/09a79ca8e8fd_add_none_ministry.py @@ -21,7 +21,6 @@ def upgrade(): ministries = sa.table( 'ministries', - sa.Column('id', sa.Integer), sa.Column('name', sa.String), sa.column('abbreviation', sa.String), sa.Column('is_active', sa.Boolean), @@ -29,18 +28,8 @@ def upgrade(): sa.Column('sort_order', sa.Integer), ) - ## select greatest id from ministries - conn = op.get_bind() - result = conn.execute( - sa.text( - "SELECT max(id) FROM ministries" - ) - ) - new_id = result.fetchone()[0] + 1 - op.execute( ministries.insert().values( - id=new_id, name=NoneMinistryName, abbreviation=NoneMinistryName, is_active=True,