Asterisk - The Open Source Telephony Project  18.5.0
fbb7766f17bc_add_playlist_to_moh.py
Go to the documentation of this file.
1 """add playlist to moh
2 
3 Revision ID: fbb7766f17bc
4 Revises: 3a094a18e75b
5 Create Date: 2019-09-18 10:24:18.731798
6 
7 """
8 
9 # revision identifiers, used by Alembic.
10 revision = 'fbb7766f17bc'
11 down_revision = '3a094a18e75b'
12 
13 from alembic import op
14 import sqlalchemy as sa
15 
16 
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))
23  return
24 
25  # Postgres requires a few more steps
26  tmp = enum_name + '_tmp'
27 
28  op.execute('ALTER TYPE ' + enum_name + ' RENAME TO ' + tmp)
29 
30  updated = sa.Enum(*enum_values, name=enum_name)
31  updated.create(op.get_bind(), checkfirst=False)
32 
33  op.execute('ALTER TABLE ' + table_name + ' ALTER COLUMN ' + column_name +
34  ' TYPE ' + enum_name + ' USING mode::text::' + enum_name)
35 
36  op.execute('DROP TYPE ' + tmp)
37 
38 
39 def upgrade():
40  op.create_table(
41  'musiconhold_entry',
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)
45  )
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'])
49 
50 
51 def downgrade():
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)