Coverage for /builds/BuildGrid/buildgrid/buildgrid/server/persistence/sql/alembic/versions/bc324dfd3610_add_cascades_for_job_platforms_table.py: 75.00%

20 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-06-11 15:37 +0000

1# Copyright (C) 2023 Bloomberg LP 

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 cascades for job_platforms table 

16 

17Revision ID: bc324dfd3610 

18Revises: afa46425330d 

19Create Date: 2023-12-01 11:30:54.380837 

20 

21""" 

22import sqlalchemy as sa 

23from alembic import op 

24 

25# revision identifiers, used by Alembic. 

26revision = "bc324dfd3610" 

27down_revision = "afa46425330d" 

28branch_labels = None 

29depends_on = None 

30 

31naming_convention = { 

32 "fk": "job_platforms_job_name_fkey", 

33} 

34 

35 

36def upgrade() -> None: 

37 # ### commands auto generated by Alembic - please adjust! ### 

38 bind = op.get_context().bind 

39 assert bind is not None, "Alembic database connection is missing" 

40 

41 with op.batch_alter_table("job_platforms", naming_convention=naming_convention) as batch_op: 

42 batch_op.drop_constraint("job_platforms_job_name_fkey", type_="foreignkey") 

43 batch_op.create_foreign_key( 

44 "job_platforms_job_name_fkey", "jobs", ["job_name"], ["name"], onupdate="CASCADE", ondelete="CASCADE" 

45 ) 

46 

47 # ### end Alembic commands ### 

48 

49 

50def downgrade() -> None: 

51 bind = op.get_context().bind 

52 assert bind is not None, "Alembic database connection is missing" 

53 

54 with op.batch_alter_table("job_platforms", naming_convention=naming_convention) as batch_op: 

55 batch_op.drop_constraint("job_platforms_job_name_fkey", type_="foreignkey") 

56 batch_op.create_foreign_key("job_platforms_job_name_fkey", "jobs", ["job_name"], ["name"])