
# revision identifiers, used by Alembic.
revision = '16ef0d8ffae1'
down_revision = '8acb1453abb'

from alembic import op
import sqlalchemy as sa

from findaconf import db
from findaconf.models import Group


def upgrade():
    roles = ['user', 'moderator', 'admin']
    [db.session.add(Group(title=role)) for role in roles]
    db.session.commit()


def downgrade():
    [db.session.delete(role) for role in Group.query.all()]
    db.session.commit()


# revision identifiers, used by Alembic.
revision = '16ef0d8ffae1'
down_revision = '8acb1453abb'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import table, column

from findaconf.models import Group


def upgrade():
    roles = ['user', 'moderator', 'admin']
    data = [{'title': r} for r in roles]

    # Create an ad-hoc table to use for the insert statement.
    group_table = table('group',
        column('title', sa.String),
    )

    # Insert data.
    op.bulk_insert(group_table, data)


def downgrade():
    op.execute(Group.__table__.delete())

Refactor data migration for Group model
Refactor data migration for Group model

Undelying explanation as in commit f580a63909166efccc8030eb36d8b2fe697f7236

  
  # revision identifiers, used by Alembic.
  revision = '16ef0d8ffae1'
  down_revision = '8acb1453abb'
  
  from alembic import op
  import sqlalchemy as sa
+ from sqlalchemy.sql import table, column
  
- from findaconf import db
  from findaconf.models import Group
  
  
  def upgrade():
      roles = ['user', 'moderator', 'admin']
-     [db.session.add(Group(title=role)) for role in roles]
-     db.session.commit()
+     data = [{'title': r} for r in roles]
+ 
+     # Create an ad-hoc table to use for the insert statement.
+     group_table = table('group',
+         column('title', sa.String),
+     )
+ 
+     # Insert data.
+     op.bulk_insert(group_table, data)
  
  
  def downgrade():
+     op.execute(Group.__table__.delete())
-     [db.session.delete(role) for role in Group.query.all()]
-     db.session.commit()
  
Refactor data migration for Group model
## Code Before:

# revision identifiers, used by Alembic.
revision = '16ef0d8ffae1'
down_revision = '8acb1453abb'

from alembic import op
import sqlalchemy as sa

from findaconf import db
from findaconf.models import Group


def upgrade():
    roles = ['user', 'moderator', 'admin']
    [db.session.add(Group(title=role)) for role in roles]
    db.session.commit()


def downgrade():
    [db.session.delete(role) for role in Group.query.all()]
    db.session.commit()

## Instruction:
Refactor data migration for Group model
## Code After:

# revision identifiers, used by Alembic.
revision = '16ef0d8ffae1'
down_revision = '8acb1453abb'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import table, column

from findaconf.models import Group


def upgrade():
    roles = ['user', 'moderator', 'admin']
    data = [{'title': r} for r in roles]

    # Create an ad-hoc table to use for the insert statement.
    group_table = table('group',
        column('title', sa.String),
    )

    # Insert data.
    op.bulk_insert(group_table, data)


def downgrade():
    op.execute(Group.__table__.delete())
