Coverage for /builds/BuildGrid/buildgrid/buildgrid/server/persistence/sql/alembic/versions/38340cc0cfb7_partial_indices.py: 78.95%

19 statements  

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

1# Copyright (C) 2020 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"""partial_indices 

16 

17Revision ID: 38340cc0cfb7 

18Revises: 1553978c6e69 

19Create Date: 2020-10-20 08:56:42.559227 

20 

21""" 

22import sqlalchemy as sa 

23from alembic import op 

24 

25# revision identifiers, used by Alembic. 

26revision = "38340cc0cfb7" 

27down_revision = "1553978c6e69" 

28branch_labels = None 

29depends_on = None 

30 

31 

32def upgrade() -> None: 

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

34 bind = op.get_context().bind 

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

36 

37 if bind.dialect.name == "postgresql": 

38 op.create_index( 

39 "ix_worker_start_timestamp", 

40 "jobs", 

41 ["worker_start_timestamp"], 

42 unique=False, 

43 postgresql_where=sa.text("worker_start_timestamp IS NOT NULL"), 

44 ) 

45 op.create_index( 

46 "ix_worker_completed_timestamp", 

47 "jobs", 

48 ["worker_completed_timestamp"], 

49 unique=False, 

50 postgresql_where=sa.text("worker_completed_timestamp IS NOT NULL"), 

51 ) 

52 elif bind.dialect.name == "sqlite": 

53 op.create_index( 

54 "ix_worker_start_timestamp", 

55 "jobs", 

56 ["worker_start_timestamp"], 

57 unique=False, 

58 sqlite_where=sa.text("worker_start_timestamp IS NOT NULL"), 

59 ) 

60 op.create_index( 

61 "ix_worker_completed_timestamp", 

62 "jobs", 

63 ["worker_completed_timestamp"], 

64 unique=False, 

65 sqlite_where=sa.text("worker_completed_timestamp IS NOT NULL"), 

66 ) 

67 # ### end Alembic commands ### 

68 

69 

70def downgrade() -> None: 

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

72 op.drop_index("ix_worker_start_timestamp", table_name="jobs") 

73 op.drop_index("ix_worker_completed_timestamp", table_name="jobs") 

74 # ### end Alembic commands ###