This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/data/migrations/versions/be8d1c402ce0_add_teamsync_table.py
Joseph Schorr f6ff0d6ca0 Add support for populating test data during migration testing
This change ensures that the tables in the database during migration have at least one row of "real" data, which should help catch issues in the future where we forget to set column defaults and other such schema oversights that can only be truly tested with non-empty tables

Fixes https://jira.coreos.com/browse/QUAY-913
2018-06-18 14:14:32 -04:00

49 lines
1.9 KiB
Python

"""Add TeamSync table
Revision ID: be8d1c402ce0
Revises: a6c463dfb9fe
Create Date: 2017-02-23 13:34:52.356812
"""
# revision identifiers, used by Alembic.
revision = 'be8d1c402ce0'
down_revision = 'a6c463dfb9fe'
from alembic import op
import sqlalchemy as sa
from util.migrate import UTF8LongText
def upgrade(tables, tester):
### commands auto generated by Alembic - please adjust! ###
op.create_table('teamsync',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('transaction_id', sa.String(length=255), nullable=False),
sa.Column('last_updated', sa.DateTime(), nullable=True),
sa.Column('service_id', sa.Integer(), nullable=False),
sa.Column('config', UTF8LongText(), nullable=False),
sa.ForeignKeyConstraint(['service_id'], ['loginservice.id'], name=op.f('fk_teamsync_service_id_loginservice')),
sa.ForeignKeyConstraint(['team_id'], ['team.id'], name=op.f('fk_teamsync_team_id_team')),
sa.PrimaryKeyConstraint('id', name=op.f('pk_teamsync'))
)
op.create_index('teamsync_last_updated', 'teamsync', ['last_updated'], unique=False)
op.create_index('teamsync_service_id', 'teamsync', ['service_id'], unique=False)
op.create_index('teamsync_team_id', 'teamsync', ['team_id'], unique=True)
### end Alembic commands ###
# ### population of test data ### #
tester.populate_table('teamsync', [
('team_id', tester.TestDataType.Foreign('team')),
('transaction_id', tester.TestDataType.String),
('last_updated', tester.TestDataType.DateTime),
('service_id', tester.TestDataType.Foreign('loginservice')),
('config', tester.TestDataType.JSON),
])
# ### end population of test data ### #
def downgrade(tables, tester):
### commands auto generated by Alembic - please adjust! ###
op.drop_table('teamsync')
### end Alembic commands ###