
# revision identifiers, used by Alembic.
revision = '26d9c9c91542'
down_revision = '19a67dc67c3'

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.add_column('cycle_task_group_objects', sa.Column('object_id', sa.Integer(), nullable=False))
    op.add_column('cycle_task_group_objects', sa.Column('object_type', sa.String(length=250), nullable=False))


def downgrade():
    op.drop_column('cycle_task_group_objects', 'object_type')
    op.drop_column('cycle_task_group_objects', 'object_id')


# revision identifiers, used by Alembic.
revision = '26d9c9c91542'
down_revision = '19a67dc67c3'

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.add_column('cycle_task_group_objects', sa.Column('object_id', sa.Integer(), nullable=False))
    op.add_column('cycle_task_group_objects', sa.Column('object_type', sa.String(length=250), nullable=False))

    op.execute('''
        UPDATE cycle_task_group_objects
            JOIN task_group_objects
                ON cycle_task_group_objects.task_group_object_id = task_group_objects.id
            SET
                cycle_task_group_objects.object_id = task_group_objects.object_id,
                cycle_task_group_objects.object_type = task_group_objects.object_type;
        ''')


def downgrade():
    op.drop_column('cycle_task_group_objects', 'object_type')
    op.drop_column('cycle_task_group_objects', 'object_id')

Update migration to fix existing CycleTaskGroupObjects
Update migration to fix existing CycleTaskGroupObjects

  
  # revision identifiers, used by Alembic.
  revision = '26d9c9c91542'
  down_revision = '19a67dc67c3'
  
  from alembic import op
  import sqlalchemy as sa
  
  
  def upgrade():
      op.add_column('cycle_task_group_objects', sa.Column('object_id', sa.Integer(), nullable=False))
      op.add_column('cycle_task_group_objects', sa.Column('object_type', sa.String(length=250), nullable=False))
  
+     op.execute('''
+         UPDATE cycle_task_group_objects
+             JOIN task_group_objects
+                 ON cycle_task_group_objects.task_group_object_id = task_group_objects.id
+             SET
+                 cycle_task_group_objects.object_id = task_group_objects.object_id,
+                 cycle_task_group_objects.object_type = task_group_objects.object_type;
+         ''')
+ 
  
  def downgrade():
      op.drop_column('cycle_task_group_objects', 'object_type')
      op.drop_column('cycle_task_group_objects', 'object_id')
  
Update migration to fix existing CycleTaskGroupObjects
## Code Before:

# revision identifiers, used by Alembic.
revision = '26d9c9c91542'
down_revision = '19a67dc67c3'

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.add_column('cycle_task_group_objects', sa.Column('object_id', sa.Integer(), nullable=False))
    op.add_column('cycle_task_group_objects', sa.Column('object_type', sa.String(length=250), nullable=False))


def downgrade():
    op.drop_column('cycle_task_group_objects', 'object_type')
    op.drop_column('cycle_task_group_objects', 'object_id')

## Instruction:
Update migration to fix existing CycleTaskGroupObjects
## Code After:

# revision identifiers, used by Alembic.
revision = '26d9c9c91542'
down_revision = '19a67dc67c3'

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.add_column('cycle_task_group_objects', sa.Column('object_id', sa.Integer(), nullable=False))
    op.add_column('cycle_task_group_objects', sa.Column('object_type', sa.String(length=250), nullable=False))

    op.execute('''
        UPDATE cycle_task_group_objects
            JOIN task_group_objects
                ON cycle_task_group_objects.task_group_object_id = task_group_objects.id
            SET
                cycle_task_group_objects.object_id = task_group_objects.object_id,
                cycle_task_group_objects.object_type = task_group_objects.object_type;
        ''')


def downgrade():
    op.drop_column('cycle_task_group_objects', 'object_type')
    op.drop_column('cycle_task_group_objects', 'object_id')
