Skip to content

Commit 4bf5318

Browse files
robbarnsleybari12
authored andcommitted
Adding db schema changes for metadata deletion
1 parent 2b628c2 commit 4bf5318

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

lib/rucio/alembicrevision.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
ALEMBIC_REVISION = 'b5493606bbf5' # the current alembic head revision
15+
ALEMBIC_REVISION = 'b0070f3695c8' # the current alembic head revision
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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')

lib/rucio/db/sqla/models.py

+15
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def _oracle_json_constraint(target: Table, connection: "Connection", **kw) -> No
9595
if oracle_version >= 12:
9696
if target.name == 'did_meta':
9797
target.append_constraint(CheckConstraint('META IS JSON', 'ORACLE_META_JSON_CHK'))
98+
if target.name == 'deleted_did_meta':
99+
target.append_constraint(CheckConstraint('META IS JSON', 'ORACLE_DELETE_META_JSON_CHK'))
98100
if target.name == 'virtual_placements':
99101
target.append_constraint(CheckConstraint('PLACEMENTS IS JSON', 'ORACLE_PLACEMENTS_JSON_CHK'))
100102

@@ -487,6 +489,19 @@ class DidMeta(BASE, ModelBase):
487489
Index('DID_META_DID_TYPE_IDX', 'did_type'))
488490

489491

492+
class DeletedDidMeta(BASE, ModelBase):
493+
__tablename__ = 'deleted_did_meta'
494+
scope: Mapped[InternalScope] = mapped_column(InternalScopeString(get_schema_value('SCOPE_LENGTH')))
495+
name: Mapped[str] = mapped_column(String(get_schema_value('NAME_LENGTH')))
496+
did_type: Mapped[Optional[DIDType]] = mapped_column(Enum(DIDType, name='DEL_DID_META_DID_TYPE_CHK',
497+
create_constraint=True,
498+
values_callable=lambda obj: [e.value for e in obj]))
499+
meta: Mapped[Optional[Union[str, dict[str, Any]]]] = mapped_column(JSON())
500+
deleted_at: Mapped[Optional[datetime]] = mapped_column(DateTime)
501+
_table_args = (PrimaryKeyConstraint('scope', 'name', name='DEL_DID_META_PK'),
502+
Index('DEL_DID_META_DID_TYPE_IDX', 'did_type'))
503+
504+
490505
class DeletedDataIdentifier(BASE, ModelBase):
491506
"""Represents a dataset"""
492507
__tablename__ = 'deleted_dids'

0 commit comments

Comments
 (0)