-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2216 from auslin-aot/feature/FWF-3581-add-major-m…
…inor-versions-to-form-history ❇️ FWF-3581: [Feature] Add major and minor versions to form versioning
- Loading branch information
Showing
7 changed files
with
161 additions
and
33 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...tions/versions/9929f234cef0_script_to_add_major_minor_version_to_existing_form_history.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Script to update existing form history records by inserting values | ||
into the major_version and minor_version columns. | ||
Revision ID: 9929f234cef0 | ||
Revises: ae48e890f2e2 | ||
Create Date: 2024-08-28 16:49:12.699755 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '9929f234cef0' | ||
down_revision = 'ae48e890f2e2' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
conn = op.get_bind() | ||
# Get distinct parent_form_ids | ||
distinct_parent_ids = conn.execute(sa.text( | ||
"SELECT DISTINCT parent_form_id FROM form_history")).fetchall() | ||
|
||
for parent_id in distinct_parent_ids: | ||
# Get all rows for this parent_form_id in ascending order by id | ||
stmt = "SELECT id, change_log FROM form_history WHERE parent_form_id = :parent_id ORDER BY id ASC" | ||
rows = conn.execute(sa.text(stmt), {"parent_id": parent_id[0]}).mappings().all() | ||
|
||
previous_version = None | ||
|
||
for row in rows: | ||
change_log = row['change_log'] | ||
current_version = change_log.get('version') | ||
|
||
if current_version: | ||
major_version = int(current_version.strip('v')) | ||
previous_version = major_version | ||
else: | ||
major_version = previous_version | ||
|
||
if major_version is not None: | ||
update_stmt ="UPDATE form_history SET minor_version=0, major_version = :major_version WHERE id = :id" | ||
conn.execute(sa.text(update_stmt), {"major_version": major_version, "id": row['id']}) | ||
|
||
|
||
def downgrade(): | ||
# Add downgrade logic if necessary | ||
pass | ||
|
34 changes: 34 additions & 0 deletions
34
forms-flow-api/migrations/versions/ae48e890f2e2_added_major_minor_version_to_form_history.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Added major & minor version columns to form history table. | ||
Revision ID: ae48e890f2e2 | ||
Revises: b0ecd447cfa5 | ||
Create Date: 2024-08-28 11:29:41.480868 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'ae48e890f2e2' | ||
down_revision = 'b0ecd447cfa5' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('form_history', sa.Column('major_version', sa.Integer(), nullable=True)) | ||
op.add_column('form_history', sa.Column('minor_version', sa.Integer(), nullable=True)) | ||
op.create_index(op.f('ix_form_history_major_version'), 'form_history', ['major_version'], unique=False) | ||
op.create_index(op.f('ix_form_history_minor_version'), 'form_history', ['minor_version'], unique=False) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index(op.f('ix_form_history_minor_version'), table_name='form_history') | ||
op.drop_index(op.f('ix_form_history_major_version'), table_name='form_history') | ||
op.drop_column('form_history', 'minor_version') | ||
op.drop_column('form_history', 'major_version') | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters