3 Revision ID: fbb7766f17bc 5 Create Date: 2019-09-18 10:24:18.731798 10 revision =
'fbb7766f17bc' 11 down_revision =
'3a094a18e75b' 13 from alembic
import op
14 import sqlalchemy
as sa
17 def enum_update(table_name, column_name, enum_name, enum_values):
18 if op.get_context().bind.dialect.name !=
'postgresql':
19 if op.get_context().bind.dialect.name ==
'mssql':
20 op.drop_constraint(
'ck_musiconhold_mode_moh_mode_values',
'musiconhold')
21 op.alter_column(table_name, column_name,
22 type_=sa.Enum(*enum_values, name=enum_name))
26 tmp = enum_name +
'_tmp' 28 op.execute(
'ALTER TYPE ' + enum_name +
' RENAME TO ' + tmp)
30 updated = sa.Enum(*enum_values, name=enum_name)
31 updated.create(op.get_bind(), checkfirst=
False)
33 op.execute(
'ALTER TABLE ' + table_name +
' ALTER COLUMN ' + column_name +
34 ' TYPE ' + enum_name +
' USING mode::text::' + enum_name)
36 op.execute(
'DROP TYPE ' + tmp)
42 sa.Column(
'name', sa.String(80), primary_key=
True, nullable=
False),
43 sa.Column(
'position', sa.Integer, primary_key=
True, nullable=
False),
44 sa.Column(
'entry', sa.String(1024), nullable=
False)
46 op.create_foreign_key(
'fk_musiconhold_entry_name_musiconhold',
'musiconhold_entry',
'musiconhold', [
'name'], [
'name'])
47 enum_update(
'musiconhold',
'mode',
'moh_mode_values',
48 [
'custom',
'files',
'mp3nb',
'quietmp3nb',
'quietmp3',
'playlist'])
52 enum_update(
'musiconhold',
'mode',
'moh_mode_values',
53 [
'custom',
'files',
'mp3nb',
'quietmp3nb',
'quietmp3'])
54 op.drop_table(
'musiconhold_entry')
def enum_update(table_name, column_name, enum_name, enum_values)