Coverage for /builds/BuildGrid/buildgrid/buildgrid/server/persistence/sql/alembic/versions/e287a533bbd7_new_database.py: 63.64%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

33 statements  

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"""New database with all earlier migrations squashed 

16 

17Revision ID: e287a533bbd7 

18Revises: 

19Create Date: 2020-02-06 13:36:00.607572 

20 

21""" 

22 

23from alembic import op 

24import sqlalchemy as sa 

25 

26 

27# revision identifiers, used by Alembic. 

28revision = 'e287a533bbd7' 

29down_revision = None 

30branch_labels = None 

31depends_on = None 

32 

33 

34def upgrade(): 

35 # ### commands auto generated by Alembic ### 

36 op.create_table( 

37 'index', sa.Column('digest_hash', sa.String(), nullable=False), 

38 sa.Column('digest_size_bytes', sa.Integer(), nullable=False), 

39 sa.Column('accessed_timestamp', sa.DateTime(), nullable=False), 

40 sa.PrimaryKeyConstraint('digest_hash')) 

41 op.create_index(op.f('ix_index_accessed_timestamp'), 

42 'index', ['accessed_timestamp'], 

43 unique=False) 

44 op.create_index(op.f('ix_index_digest_hash'), 

45 'index', ['digest_hash'], 

46 unique=False) 

47 op.create_table( 

48 'jobs', sa.Column('name', sa.String(), nullable=False), 

49 sa.Column('action_digest', sa.String(), nullable=False), 

50 sa.Column('priority', sa.Integer(), nullable=False), 

51 sa.Column('stage', sa.Integer(), nullable=False), 

52 sa.Column('do_not_cache', sa.Boolean(), nullable=False), 

53 sa.Column('cancelled', sa.Boolean(), nullable=False), 

54 sa.Column('queued_timestamp', sa.DateTime(), nullable=True), 

55 sa.Column('queued_time_duration', sa.Integer(), nullable=True), 

56 sa.Column('worker_start_timestamp', sa.DateTime(), nullable=True), 

57 sa.Column('worker_completed_timestamp', sa.DateTime(), nullable=True), 

58 sa.Column('result', sa.String(), nullable=True), 

59 sa.Column('assigned', sa.Boolean(), nullable=True), 

60 sa.Column('n_tries', sa.Integer(), nullable=True), 

61 sa.Column('platform_requirements', sa.String(), nullable=True), 

62 sa.PrimaryKeyConstraint('name')) 

63 op.create_index(op.f('ix_jobs_action_digest'), 

64 'jobs', ['action_digest'], 

65 unique=False) 

66 op.create_index(op.f('ix_jobs_priority'), 

67 'jobs', ['priority'], 

68 unique=False) 

69 op.create_index(op.f('ix_jobs_stage'), 'jobs', ['stage'], unique=False) 

70 op.create_table( 

71 'leases', sa.Column('id', sa.Integer(), nullable=False), 

72 sa.Column('job_name', sa.String(), nullable=False), 

73 sa.Column('status', sa.Integer(), nullable=True), 

74 sa.Column('state', sa.Integer(), nullable=False), 

75 sa.Column('worker_name', sa.String(), nullable=True), 

76 sa.ForeignKeyConstraint(['job_name'], ['jobs.name'], 

77 onupdate='CASCADE', 

78 ondelete='CASCADE'), 

79 sa.PrimaryKeyConstraint('id')) 

80 op.create_index(op.f('ix_leases_job_name'), 

81 'leases', ['job_name'], 

82 unique=False) 

83 op.create_index(op.f('ix_leases_worker_name'), 

84 'leases', ['worker_name'], 

85 unique=False) 

86 op.create_table( 

87 'operations', sa.Column('name', sa.String(), nullable=False), 

88 sa.Column('job_name', sa.String(), nullable=False), 

89 sa.Column('cancelled', sa.Boolean(), nullable=False), 

90 sa.ForeignKeyConstraint(['job_name'], ['jobs.name'], 

91 onupdate='CASCADE', 

92 ondelete='CASCADE'), 

93 sa.PrimaryKeyConstraint('name')) 

94 op.create_index(op.f('ix_operations_job_name'), 

95 'operations', ['job_name'], 

96 unique=False) 

97 # ### end Alembic commands ### 

98 

99 

100def downgrade(): 

101 # ### commands auto generated by Alembic ### 

102 op.drop_index(op.f('ix_operations_job_name'), table_name='operations') 

103 op.drop_table('operations') 

104 op.drop_index(op.f('ix_leases_worker_name'), table_name='leases') 

105 op.drop_index(op.f('ix_leases_job_name'), table_name='leases') 

106 op.drop_table('leases') 

107 op.drop_index(op.f('ix_jobs_stage'), table_name='jobs') 

108 op.drop_index(op.f('ix_jobs_priority'), table_name='jobs') 

109 op.drop_index(op.f('ix_jobs_action_digest'), table_name='jobs') 

110 op.drop_table('jobs') 

111 op.drop_index(op.f('ix_index_digest_hash'), table_name='index') 

112 op.drop_index(op.f('ix_index_accessed_timestamp'), table_name='index') 

113 op.drop_table('index') 

114 # ### end Alembic commands ###