main
py 154 lines 8.25 KB
Raw
1 """Add github audit tables
2
3 Revision ID: fb51d610b306
4 Revises: 72635705c067
5 Create Date: 2026-02-09 13:20:39.267397
6
7 """
8 from typing import Sequence
9 from typing import Union
10
11 import sqlalchemy as sa
12
13 from alembic import op
14
15 # revision identifiers, used by Alembic.
16 revision: str = "fb51d610b306"
17 down_revision: Union[str, None] = "72635705c067"
18 branch_labels: Union[str, Sequence[str], None] = None
19 depends_on: Union[str, Sequence[str], None] = None
20
21
22 def upgrade() -> None:
23 # ### commands auto generated by Alembic - please adjust! ###
24 op.create_table(
25 "github_audit_config",
26 sa.Column("repo_filter_list", sa.JSON(), nullable=True),
27 sa.Column("id", sa.Integer(), nullable=False),
28 sa.Column("customer_code", sa.String(length=50), nullable=False),
29 sa.Column("github_token", sa.String(length=500), nullable=False),
30 sa.Column("organization", sa.String(length=100), nullable=False),
31 sa.Column("token_type", sa.String(length=50), nullable=False),
32 sa.Column("token_expires_at", sa.DateTime(), nullable=True),
33 sa.Column("enabled", sa.Boolean(), nullable=False),
34 sa.Column("auto_audit_enabled", sa.Boolean(), nullable=False),
35 sa.Column("audit_schedule_cron", sa.String(length=50), nullable=True),
36 sa.Column("include_repos", sa.Boolean(), nullable=False),
37 sa.Column("include_workflows", sa.Boolean(), nullable=False),
38 sa.Column("include_members", sa.Boolean(), nullable=False),
39 sa.Column("include_archived_repos", sa.Boolean(), nullable=False),
40 sa.Column("repo_filter_mode", sa.String(length=20), nullable=False),
41 sa.Column("notify_on_critical", sa.Boolean(), nullable=False),
42 sa.Column("notify_on_high", sa.Boolean(), nullable=False),
43 sa.Column("notification_webhook_url", sa.String(length=500), nullable=True),
44 sa.Column("notification_email", sa.String(length=255), nullable=True),
45 sa.Column("minimum_passing_score", sa.Float(), nullable=False),
46 sa.Column("created_at", sa.DateTime(), nullable=False),
47 sa.Column("updated_at", sa.DateTime(), nullable=False),
48 sa.Column("created_by", sa.String(length=100), nullable=True),
49 sa.Column("updated_by", sa.String(length=100), nullable=True),
50 sa.Column("last_audit_at", sa.DateTime(), nullable=True),
51 sa.Column("last_audit_score", sa.Float(), nullable=True),
52 sa.Column("last_audit_grade", sa.String(length=2), nullable=True),
53 sa.PrimaryKeyConstraint("id"),
54 )
55 op.create_index(op.f("ix_github_audit_config_customer_code"), "github_audit_config", ["customer_code"], unique=False)
56 op.create_table(
57 "github_audit_check_exclusion",
58 sa.Column("id", sa.Integer(), nullable=False),
59 sa.Column("config_id", sa.Integer(), nullable=False),
60 sa.Column("customer_code", sa.String(length=50), nullable=False),
61 sa.Column("check_id", sa.String(length=100), nullable=False),
62 sa.Column("resource_name", sa.String(length=255), nullable=True),
63 sa.Column("resource_type", sa.String(length=50), nullable=True),
64 sa.Column("reason", sa.String(length=1024), nullable=False),
65 sa.Column("approved_by", sa.String(length=100), nullable=True),
66 sa.Column("approved_at", sa.DateTime(), nullable=True),
67 sa.Column("expires_at", sa.DateTime(), nullable=True),
68 sa.Column("enabled", sa.Boolean(), nullable=False),
69 sa.Column("created_at", sa.DateTime(), nullable=False),
70 sa.Column("created_by", sa.String(length=100), nullable=False),
71 sa.ForeignKeyConstraint(
72 ["config_id"],
73 ["github_audit_config.id"],
74 ),
75 sa.PrimaryKeyConstraint("id"),
76 )
77 op.create_index(op.f("ix_github_audit_check_exclusion_config_id"), "github_audit_check_exclusion", ["config_id"], unique=False)
78 op.create_index(op.f("ix_github_audit_check_exclusion_customer_code"), "github_audit_check_exclusion", ["customer_code"], unique=False)
79 op.create_table(
80 "github_audit_report",
81 sa.Column("full_report", sa.JSON(), nullable=True),
82 sa.Column("top_findings", sa.JSON(), nullable=True),
83 sa.Column("id", sa.Integer(), nullable=False),
84 sa.Column("config_id", sa.Integer(), nullable=False),
85 sa.Column("customer_code", sa.String(length=50), nullable=False),
86 sa.Column("report_name", sa.String(length=255), nullable=False),
87 sa.Column("organization", sa.String(length=100), nullable=False),
88 sa.Column("audit_started_at", sa.DateTime(), nullable=False),
89 sa.Column("audit_completed_at", sa.DateTime(), nullable=True),
90 sa.Column("audit_duration_seconds", sa.Float(), nullable=True),
91 sa.Column("total_repos_audited", sa.Integer(), nullable=False),
92 sa.Column("total_checks", sa.Integer(), nullable=False),
93 sa.Column("passed_checks", sa.Integer(), nullable=False),
94 sa.Column("failed_checks", sa.Integer(), nullable=False),
95 sa.Column("warning_checks", sa.Integer(), nullable=False),
96 sa.Column("critical_findings", sa.Integer(), nullable=False),
97 sa.Column("high_findings", sa.Integer(), nullable=False),
98 sa.Column("medium_findings", sa.Integer(), nullable=False),
99 sa.Column("low_findings", sa.Integer(), nullable=False),
100 sa.Column("score", sa.Float(), nullable=False),
101 sa.Column("grade", sa.String(length=2), nullable=False),
102 sa.Column("status", sa.String(length=50), nullable=False),
103 sa.Column("error_message", sa.String(length=1024), nullable=True),
104 sa.Column("triggered_by", sa.String(length=50), nullable=False),
105 sa.Column("triggered_by_user", sa.String(length=100), nullable=True),
106 sa.ForeignKeyConstraint(
107 ["config_id"],
108 ["github_audit_config.id"],
109 ),
110 sa.PrimaryKeyConstraint("id"),
111 )
112 op.create_index(op.f("ix_github_audit_report_config_id"), "github_audit_report", ["config_id"], unique=False)
113 op.create_index(op.f("ix_github_audit_report_customer_code"), "github_audit_report", ["customer_code"], unique=False)
114 op.create_table(
115 "github_audit_baseline",
116 sa.Column("expected_checks", sa.JSON(), nullable=True),
117 sa.Column("id", sa.Integer(), nullable=False),
118 sa.Column("config_id", sa.Integer(), nullable=False),
119 sa.Column("customer_code", sa.String(length=50), nullable=False),
120 sa.Column("name", sa.String(length=255), nullable=False),
121 sa.Column("description", sa.String(length=1024), nullable=True),
122 sa.Column("baseline_report_id", sa.Integer(), nullable=True),
123 sa.Column("is_active", sa.Boolean(), nullable=False),
124 sa.Column("created_at", sa.DateTime(), nullable=False),
125 sa.Column("created_by", sa.String(length=100), nullable=False),
126 sa.ForeignKeyConstraint(
127 ["baseline_report_id"],
128 ["github_audit_report.id"],
129 ),
130 sa.ForeignKeyConstraint(
131 ["config_id"],
132 ["github_audit_config.id"],
133 ),
134 sa.PrimaryKeyConstraint("id"),
135 )
136 op.create_index(op.f("ix_github_audit_baseline_config_id"), "github_audit_baseline", ["config_id"], unique=False)
137 op.create_index(op.f("ix_github_audit_baseline_customer_code"), "github_audit_baseline", ["customer_code"], unique=False)
138 # ### end Alembic commands ###
139
140
141 def downgrade() -> None:
142 # ### commands auto generated by Alembic - please adjust! ###
143 op.drop_index(op.f("ix_github_audit_baseline_customer_code"), table_name="github_audit_baseline")
144 op.drop_index(op.f("ix_github_audit_baseline_config_id"), table_name="github_audit_baseline")
145 op.drop_table("github_audit_baseline")
146 op.drop_index(op.f("ix_github_audit_report_customer_code"), table_name="github_audit_report")
147 op.drop_index(op.f("ix_github_audit_report_config_id"), table_name="github_audit_report")
148 op.drop_table("github_audit_report")
149 op.drop_index(op.f("ix_github_audit_check_exclusion_customer_code"), table_name="github_audit_check_exclusion")
150 op.drop_index(op.f("ix_github_audit_check_exclusion_config_id"), table_name="github_audit_check_exclusion")
151 op.drop_table("github_audit_check_exclusion")
152 op.drop_index(op.f("ix_github_audit_config_customer_code"), table_name="github_audit_config")
153 op.drop_table("github_audit_config")
154 # ### end Alembic commands ###