"Fossies" - the Fresh Open Source Software Archive

Member "mailman-3.3.7/src/mailman/database/alembic/versions/33e1f5f6fa8_.py" (10 Nov 2022, 2169 Bytes) of package /linux/misc/mailman-3.3.7.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "33e1f5f6fa8_.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 3.3.5_vs_3.3.6.

    1 # Copyright (C) 2015-2022 by the Free Software Foundation, Inc.
    2 #
    3 # This file is part of GNU Mailman.
    4 #
    5 # GNU Mailman is free software: you can redistribute it and/or modify it under
    6 # the terms of the GNU General Public License as published by the Free
    7 # Software Foundation, either version 3 of the License, or (at your option)
    8 # any later version.
    9 #
   10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
   11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   12 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   13 # more details.
   14 #
   15 # You should have received a copy of the GNU General Public License along with
   16 # GNU Mailman.  If not, see <https://www.gnu.org/licenses/>.
   17 
   18 """Migration from Python 2 to Python 3.
   19 
   20 Some columns changed from LargeBinary type to Unicode type.
   21 
   22 Revision ID: 33e1f5f6fa8
   23 Revises: 51b7f92bd06c
   24 Create Date: 2015-01-20 17:32:30.144083
   25 
   26 """
   27 
   28 import sqlalchemy as sa
   29 
   30 from alembic import op
   31 from mailman.database.helpers import is_sqlite
   32 from mailman.database.types import SAUnicode
   33 
   34 
   35 # Revision identifiers, used by Alembic.
   36 revision = '33e1f5f6fa8'
   37 down_revision = '51b7f92bd06c'
   38 
   39 
   40 COLUMNS_TO_CHANGE = (
   41     ('message', 'message_id_hash'),
   42     ('message', 'path'),
   43     ('pended', 'token'),
   44     ('_request', 'data_hash'),
   45     ('user', 'password'),
   46     )
   47 
   48 
   49 def upgrade():
   50     if is_sqlite(op.get_bind()):
   51         # SQLite does not support altering columns.
   52         return
   53     for table, column in COLUMNS_TO_CHANGE:
   54         op.alter_column(table, column, type_=SAUnicode)
   55 
   56 
   57 def downgrade():
   58     if is_sqlite(op.get_bind()):
   59         # SQLite does not support altering columns.
   60         return
   61     for table, column in COLUMNS_TO_CHANGE:
   62         if op.get_bind().dialect.name == 'postgresql':
   63             # PostgreSQL needs the USING clause that Alembic does not support
   64             # yet.
   65             op.execute(
   66                 ('ALTER TABLE "{table}" ALTER COLUMN "{column}" '
   67                  'TYPE BYTEA USING decode("{column}", \'UTF8\')').format(
   68                      table=table, column=column))
   69         else:
   70             op.alter_column(table, column, type_=sa.LargeBinary)