116 for table_name, column_list in itertools.groupby(COLUMNS, operator.itemgetter(0)):
117 subject =
table(table_name)
118 values_exprs = {}
119 for _, column_name in column_list:
120 subject.append_column(column(column_name))
121 values_exprs[column_name] = cast(
122 case((or_(subject.c[column_name] ==
text(
"'yes'"),
123 subject.c[column_name] ==
text(
"'1'"),
124 subject.c[column_name] ==
text(
"'on'"),
125 subject.c[column_name] ==
text(
"'true'")),
text(
"'yes'")),
127 ast_bool_values)
128
129 op.execute(
130 subject.update().
values(values_exprs)
131 )
132
133 for table_name, column_list in itertools.groupby(COLUMNS, operator.itemgetter(0)):
134 with op.batch_alter_table(table_name) as batch_op:
135 for _, column_name in column_list:
136 batch_op.alter_column(column_name,
137 type_=yesno_values,
138 existing_type=ast_bool_values,
139 postgresql_using='"{}"::text::{}'.format(column_name, YESNO_NAME))