-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '166-implement-endpoints-for-uploading-version-state' in…
…to 'main' Resolve "Implement endpoints for uploading version state" Closes #166 See merge request pub/terra/terrarun!99
- Loading branch information
Showing
37 changed files
with
1,555 additions
and
777 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ schedule==1.2.0 | |
semantic-version==2.10.0 | ||
blinker==1.6.2 | ||
werkzeug<3 | ||
typing_extensions==4.12.2 |
32 changes: 32 additions & 0 deletions
32
terrarun/alembic/versions/376a843af267_add_status_column_to_state_version.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,32 @@ | ||
"""Add status column to state version | ||
Revision ID: 376a843af267 | ||
Revises: 6209dfe486dc | ||
Create Date: 2024-08-01 05:31:11.690395 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import mysql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '376a843af267' | ||
down_revision = '6209dfe486dc' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('state_version', sa.Column('status', sa.Enum('PENDING', 'FINALIZED', 'DISCARDED', 'BACKING_DATA_SOFT_DELETED', 'BACKING_DATA_PERMANENTLY_DELETED', name='stateversionstatus'), nullable=False)) | ||
bind = op.get_bind() | ||
bind.execute("""UPDATE state_version SET status='FINALIZED' WHERE state_json_id IS NOT NULL""") | ||
# This shouldn't be required, as state data was required in API upload, but it is a safety net | ||
bind.execute("""UPDATE state_version SET status='DISCARDED' WHERE state_json_id IS NULL""") | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column('state_version', 'status') | ||
# ### end Alembic commands ### |
30 changes: 30 additions & 0 deletions
30
terrarun/alembic/versions/9309cba5bed5_add_json_output_to_state_version.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,30 @@ | ||
"""Add JSON output to state version and make state_version unique | ||
Revision ID: 9309cba5bed5 | ||
Revises: c2ecefd99159 | ||
Create Date: 2024-08-05 06:39:12.553556 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import mysql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '9309cba5bed5' | ||
down_revision = 'c2ecefd99159' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('state_version', sa.Column('json_state_outputs_id', sa.Integer(), nullable=True)) | ||
op.create_foreign_key('fk_blob_state_version_json_state_outputs', 'state_version', 'blob', ['json_state_outputs_id'], ['id']) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_constraint('fk_blob_state_version_json_state_outputs', 'state_version', type_='foreignkey') | ||
op.drop_column('state_version', 'json_state_outputs_id') | ||
# ### end Alembic commands ### |
69 changes: 69 additions & 0 deletions
69
terrarun/alembic/versions/c2ecefd99159_add_columns_to_state_version_to_handle_.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,69 @@ | ||
"""Add columns to state version to handle new attributes and upload endpoint | ||
Revision ID: c2ecefd99159 | ||
Revises: 376a843af267 | ||
Create Date: 2024-08-03 05:49:29.376688 | ||
""" | ||
import json | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import mysql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'c2ecefd99159' | ||
down_revision = '376a843af267' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
# Rename state_json to state column | ||
op.drop_constraint('state_version_ibfk_3', 'state_version', type_='foreignkey') | ||
op.alter_column('state_version', 'state_json_id', existing_type=sa.Integer(), nullable=True, new_column_name='state_id') | ||
op.create_foreign_key('fk_blob_state_version_state', 'state_version', 'blob', ['state_id'], ['id']) | ||
|
||
op.add_column('state_version', sa.Column('json_state_id', sa.Integer(), nullable=True)) | ||
op.add_column('state_version', sa.Column('lineage', sa.String(length=128), nullable=True)) | ||
op.add_column('state_version', sa.Column('md5', sa.String(length=128), nullable=True)) | ||
op.add_column('state_version', sa.Column('serial', sa.Integer(), nullable=True)) | ||
op.add_column('state_version', sa.Column('state_version', sa.Integer(), nullable=True)) | ||
op.add_column('state_version', sa.Column('terraform_version', sa.String(length=128), nullable=True)) | ||
op.add_column('state_version', sa.Column('intermediate', sa.Boolean(), nullable=False)) | ||
op.create_foreign_key('fk_blob_state_version_json_state', 'state_version', 'blob', ['json_state_id'], ['id']) | ||
|
||
bind = op.get_bind() | ||
for row in bind.execute("""SELECT state_version.id AS state_version_id, `blob`.data AS state_version_data FROM state_version INNER JOIN `blob` ON state_version.state_id=`blob`.id""").all(): | ||
state = {} | ||
if row['state_version_data']: | ||
state = json.loads(row['state_version_data'].decode('utf-8')) | ||
bind.execute( | ||
sa.sql.text( | ||
"""UPDATE state_version SET lineage=:lineage, md5=:md5, serial=:serial, state_version=:state_version, terraform_version=:terraform_version, intermediate=:intermediate WHERE id=:state_version_id""" | ||
), | ||
lineage=state.get("lineage"), | ||
md5=None, | ||
serial=state.get("serial"), | ||
state_version=state.get("version"), | ||
terraform_version=state.get("terraform_version"), | ||
intermediate=False, | ||
state_version_id=row['state_version_id'] | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_constraint('fk_blob_state_version_json_state', 'state_version', type_='foreignkey') | ||
op.drop_constraint('fk_blob_state_version_state', 'state_version', type_='foreignkey') | ||
op.alter_column('state_version', 'state_id', existing_type=sa.Integer(), nullable=True, new_column_name='state_json_id') | ||
op.create_foreign_key('state_version_ibfk_3', 'state_version', 'blob', ['state_json_id'], ['id']) | ||
op.drop_column('state_version', 'intermediate') | ||
op.drop_column('state_version', 'terraform_version') | ||
op.drop_column('state_version', 'state_version') | ||
op.drop_column('state_version', 'serial') | ||
op.drop_column('state_version', 'md5') | ||
op.drop_column('state_version', 'lineage') | ||
op.drop_column('state_version', 'json_state_id') | ||
# ### 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
Oops, something went wrong.