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

33 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-10-04 17:48 +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"""New database with all earlier migrations squashed 

16 

17Revision ID: e287a533bbd7 

18Revises: 

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

20 

21""" 

22 

23import sqlalchemy as sa 

24from alembic import op 

25 

26# revision identifiers, used by Alembic. 

27revision = "e287a533bbd7" 

28down_revision = None 

29branch_labels = None 

30depends_on = None 

31 

32 

33def upgrade() -> None: 

34 # ### commands auto generated by Alembic ### 

35 op.create_table( 

36 "index", 

37 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 ) 

42 op.create_index(op.f("ix_index_accessed_timestamp"), "index", ["accessed_timestamp"], unique=False) 

43 op.create_index(op.f("ix_index_digest_hash"), "index", ["digest_hash"], unique=False) 

44 op.create_table( 

45 "jobs", 

46 sa.Column("name", sa.String(), nullable=False), 

47 sa.Column("action_digest", sa.String(), nullable=False), 

48 sa.Column("priority", sa.Integer(), nullable=False), 

49 sa.Column("stage", sa.Integer(), nullable=False), 

50 sa.Column("do_not_cache", sa.Boolean(), nullable=False), 

51 sa.Column("cancelled", sa.Boolean(), nullable=False), 

52 sa.Column("queued_timestamp", sa.DateTime(), nullable=True), 

53 sa.Column("queued_time_duration", sa.Integer(), nullable=True), 

54 sa.Column("worker_start_timestamp", sa.DateTime(), nullable=True), 

55 sa.Column("worker_completed_timestamp", sa.DateTime(), nullable=True), 

56 sa.Column("result", sa.String(), nullable=True), 

57 sa.Column("assigned", sa.Boolean(), nullable=True), 

58 sa.Column("n_tries", sa.Integer(), nullable=True), 

59 sa.Column("platform_requirements", sa.String(), nullable=True), 

60 sa.PrimaryKeyConstraint("name"), 

61 ) 

62 op.create_index(op.f("ix_jobs_action_digest"), "jobs", ["action_digest"], unique=False) 

63 op.create_index(op.f("ix_jobs_priority"), "jobs", ["priority"], unique=False) 

64 op.create_index(op.f("ix_jobs_stage"), "jobs", ["stage"], unique=False) 

65 op.create_table( 

66 "leases", 

67 sa.Column("id", sa.Integer(), nullable=False), 

68 sa.Column("job_name", sa.String(), nullable=False), 

69 sa.Column("status", sa.Integer(), nullable=True), 

70 sa.Column("state", sa.Integer(), nullable=False), 

71 sa.Column("worker_name", sa.String(), nullable=True), 

72 sa.ForeignKeyConstraint(["job_name"], ["jobs.name"], onupdate="CASCADE", ondelete="CASCADE"), 

73 sa.PrimaryKeyConstraint("id"), 

74 ) 

75 op.create_index(op.f("ix_leases_job_name"), "leases", ["job_name"], unique=False) 

76 op.create_index(op.f("ix_leases_worker_name"), "leases", ["worker_name"], unique=False) 

77 op.create_table( 

78 "operations", 

79 sa.Column("name", sa.String(), nullable=False), 

80 sa.Column("job_name", sa.String(), nullable=False), 

81 sa.Column("cancelled", sa.Boolean(), nullable=False), 

82 sa.ForeignKeyConstraint(["job_name"], ["jobs.name"], onupdate="CASCADE", ondelete="CASCADE"), 

83 sa.PrimaryKeyConstraint("name"), 

84 ) 

85 op.create_index(op.f("ix_operations_job_name"), "operations", ["job_name"], unique=False) 

86 # ### end Alembic commands ### 

87 

88 

89def downgrade() -> None: 

90 # ### commands auto generated by Alembic ### 

91 op.drop_index(op.f("ix_operations_job_name"), table_name="operations") 

92 op.drop_table("operations") 

93 op.drop_index(op.f("ix_leases_worker_name"), table_name="leases") 

94 op.drop_index(op.f("ix_leases_job_name"), table_name="leases") 

95 op.drop_table("leases") 

96 op.drop_index(op.f("ix_jobs_stage"), table_name="jobs") 

97 op.drop_index(op.f("ix_jobs_priority"), table_name="jobs") 

98 op.drop_index(op.f("ix_jobs_action_digest"), table_name="jobs") 

99 op.drop_table("jobs") 

100 op.drop_index(op.f("ix_index_digest_hash"), table_name="index") 

101 op.drop_index(op.f("ix_index_accessed_timestamp"), table_name="index") 

102 op.drop_table("index") 

103 # ### end Alembic commands ###