|
| 1 | +# Copyright European Organization for Nuclear Research (CERN) since 2012 |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +''' Add deleted_did_meta table ''' |
| 16 | + |
| 17 | +import sqlalchemy as sa |
| 18 | +from alembic import context |
| 19 | +from alembic.op import create_index, create_primary_key, create_table, drop_table |
| 20 | + |
| 21 | +from rucio.db.sqla.constants import DIDType |
| 22 | +from rucio.db.sqla.types import JSON |
| 23 | + |
| 24 | +# Alembic revision identifiers |
| 25 | +revision = 'b0070f3695c8' |
| 26 | +down_revision = 'b5493606bbf5' |
| 27 | + |
| 28 | + |
| 29 | +def upgrade(): |
| 30 | + ''' |
| 31 | + Upgrade the database to this revision |
| 32 | + ''' |
| 33 | + |
| 34 | + if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']: |
| 35 | + create_table('deleted_did_meta', |
| 36 | + sa.Column('scope', sa.String(25)), |
| 37 | + sa.Column('name', sa.String(255)), |
| 38 | + sa.Column('did_type', sa.Enum(DIDType, |
| 39 | + name='DEL_DID_META_DID_TYPE_CHK', |
| 40 | + create_constraint=True, |
| 41 | + values_callable=lambda obj: [e.value for e in obj])), |
| 42 | + sa.Column('meta', JSON()), |
| 43 | + sa.Column('created_at', sa.DateTime), |
| 44 | + sa.Column('updated_at', sa.DateTime), |
| 45 | + sa.Column('deleted_at', sa.DateTime)) |
| 46 | + |
| 47 | + create_primary_key('DEL_DID_META_PK', 'deleted_did_meta', ['scope', 'name']) |
| 48 | + create_index('DEL_DID_META_DID_TYPE_IDX', 'deleted_did_meta', ['did_type']) |
| 49 | + |
| 50 | + |
| 51 | +def downgrade(): |
| 52 | + ''' |
| 53 | + Downgrade the database to the previous revision |
| 54 | + ''' |
| 55 | + |
| 56 | + if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']: |
| 57 | + drop_table('deleted_did_meta') |
0 commit comments