-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metadata form versioning - 1 (#1637)
### Feature or Bugfix <!-- please choose --> - Feature ### Detail - new db model - migration: -- create default version one -- backfill existing MF fields and attached MFs - when MF is created, service automatically create version 1 - fields and attached metadata forms automatically use the latest version (for now version === 1) ### Relates - #1621 ### Security Please answer the questions below briefly where applicable, or write `N/A`. Based on [OWASP 10](https://owasp.org/Top10/en/). - Does this PR introduce or modify any input fields or queries - this includes fetching data from storage outside the application (e.g. a database, an S3 bucket)? - Is the input sanitized? - What precautions are you taking before deserializing the data you consume? - Is injection prevented by parametrizing queries? - Have you ensured no `eval` or similar functions are used? - Does this PR introduce any functionality or component that requires authorization? - How have you ensured it respects the existing AuthN/AuthZ mechanisms? - Are you logging failed auth attempts? - Are you using or adding any cryptographic features? - Do you use a standard proven implementations? - Are the used keys controlled by the customer? Where are they stored? - Are you introducing any new policies/roles/users? - Have you used the least-privilege principle? How? By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Sofia Sazonova <sazonova@amazon.co.uk>
- Loading branch information
1 parent
0eed4cd
commit 25dd41a
Showing
4 changed files
with
193 additions
and
5 deletions.
There are no files selected for viewing
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
125 changes: 125 additions & 0 deletions
125
backend/migrations/versions/5a798acc6282_create_version_mf.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,125 @@ | ||
"""create_version_mf | ||
Revision ID: 5a798acc6282 | ||
Revises: 075d344ae2cc | ||
Create Date: 2024-10-10 17:25:09.687099 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy import orm | ||
|
||
from dataall.modules.metadata_forms.db.metadata_form_models import ( | ||
MetadataForm, | ||
MetadataFormVersion, | ||
AttachedMetadataForm, | ||
MetadataFormField, | ||
) | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '5a798acc6282' | ||
down_revision = '075d344ae2cc' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
bind = op.get_bind() | ||
session = orm.Session(bind=bind) | ||
|
||
op.create_table( | ||
'metadata_form_version', | ||
sa.Column('metadataFormUri', sa.String(), nullable=False), | ||
sa.Column('version', sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
['metadataFormUri'], ['metadata_form.uri'], name='f_key_version_metadata', ondelete='CASCADE' | ||
), | ||
sa.PrimaryKeyConstraint('metadataFormUri', 'version'), | ||
) | ||
for mf in session.query(MetadataForm).all(): | ||
version = MetadataFormVersion(metadataFormUri=mf.uri, version=1) | ||
session.add(version) | ||
session.commit() | ||
|
||
op.add_column('attached_metadata_form', sa.Column('version', sa.Integer())) | ||
for amf in session.query(AttachedMetadataForm).all(): | ||
amf.version = 1 | ||
session.commit() | ||
op.alter_column('attached_metadata_form', 'version', nullable=False) | ||
op.drop_constraint('fk_attached_mf_uri', 'attached_metadata_form', type_='foreignkey') | ||
op.create_foreign_key( | ||
'fk_attached_mf_version_uri', | ||
'attached_metadata_form', | ||
'metadata_form_version', | ||
['metadataFormUri', 'version'], | ||
['metadataFormUri', 'version'], | ||
ondelete='CASCADE', | ||
) | ||
|
||
op.add_column('metadata_form_enforcement_rule', sa.Column('version', sa.Integer(), nullable=False)) | ||
op.create_foreign_key( | ||
'f_key_enforcement_version_metadata', | ||
'metadata_form_enforcement_rule', | ||
'metadata_form_version', | ||
['metadataFormUri', 'version'], | ||
['metadataFormUri', 'version'], | ||
ondelete='CASCADE', | ||
) | ||
op.drop_constraint('f_key_enforcement_metadata', 'metadata_form_enforcement_rule', type_='foreignkey') | ||
|
||
op.add_column('metadata_form_field', sa.Column('version', sa.Integer())) | ||
for field in session.query(MetadataFormField).all(): | ||
field.version = 1 | ||
session.commit() | ||
op.alter_column('metadata_form_field', 'version', nullable=False) | ||
op.drop_constraint('fk_mf_filed_form_uri', 'metadata_form_field', type_='foreignkey') | ||
op.create_foreign_key( | ||
'fk_version', | ||
'metadata_form_field', | ||
'metadata_form_version', | ||
['metadataFormUri', 'version'], | ||
['metadataFormUri', 'version'], | ||
ondelete='CASCADE', | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_constraint('fk_version', 'metadata_form_field', type_='foreignkey') | ||
op.drop_column('metadata_form_field', 'version') | ||
op.drop_constraint('f_key_enforcement_version_metadata', 'metadata_form_enforcement_rule', type_='foreignkey') | ||
op.drop_column('metadata_form_enforcement_rule', 'version') | ||
op.drop_constraint('fk_attached_mf_version_uri', 'attached_metadata_form', type_='foreignkey') | ||
op.drop_column('attached_metadata_form', 'version') | ||
op.drop_table('metadata_form_version') | ||
|
||
op.create_foreign_key( | ||
'fk_mf_filed_form_uri', | ||
'metadata_form_field', | ||
'metadata_form', | ||
['metadataFormUri'], | ||
['uri'], | ||
ondelete='CASCADE', | ||
) | ||
|
||
op.create_foreign_key( | ||
'f_key_enforcement_metadata', | ||
'metadata_form_enforcement_rule', | ||
'metadata_form', | ||
['metadataFormUri'], | ||
['uri'], | ||
ondelete='CASCADE', | ||
) | ||
|
||
op.create_foreign_key( | ||
'fk_attached_mf_uri', | ||
'attached_metadata_form', | ||
'metadata_form', | ||
['metadataFormUri'], | ||
['uri'], | ||
ondelete='CASCADE', | ||
) | ||
# ### end Alembic commands ### |