|
| 1 | +"""Add contributor_engagement table |
| 2 | +
|
| 3 | +Revision ID: 35 |
| 4 | +Revises: 33 |
| 5 | +Create Date: 2025-07-26 10:00:00.000000 |
| 6 | +
|
| 7 | +""" |
| 8 | + |
| 9 | +import sqlalchemy as sa |
| 10 | +from alembic import op |
| 11 | +from sqlalchemy.dialects import postgresql |
| 12 | + |
| 13 | +# revision identifiers, used by Alembic. |
| 14 | +revision = "35" |
| 15 | +down_revision = "33" |
| 16 | +branch_labels = None |
| 17 | +depends_on = None |
| 18 | + |
| 19 | + |
| 20 | +def upgrade(): |
| 21 | + op.create_table( |
| 22 | + "contributor_engagement", |
| 23 | + sa.Column("engagement_id", sa.BigInteger(), autoincrement=True, nullable=False), |
| 24 | + sa.Column("repo_id", sa.BigInteger(), nullable=False), |
| 25 | + sa.Column("cntrb_id", postgresql.UUID(as_uuid=True), nullable=False), |
| 26 | + sa.Column("username", sa.String(), nullable=False), |
| 27 | + sa.Column("full_name", sa.String(), nullable=True), |
| 28 | + sa.Column("country", sa.String(), nullable=True), |
| 29 | + sa.Column("platform", sa.String(), nullable=True), |
| 30 | + # D0 Level - Basic Engagement |
| 31 | + sa.Column( |
| 32 | + "d0_forked", sa.Boolean(), server_default=sa.text("false"), nullable=True |
| 33 | + ), |
| 34 | + sa.Column( |
| 35 | + "d0_starred_or_watched", |
| 36 | + sa.Boolean(), |
| 37 | + server_default=sa.text("false"), |
| 38 | + nullable=True, |
| 39 | + ), |
| 40 | + sa.Column("d0_engagement_timestamp", sa.TIMESTAMP, nullable=True), |
| 41 | + # D1 Level - Issue/Review Engagement |
| 42 | + sa.Column("d1_first_issue_created_at", sa.TIMESTAMP, nullable=True), |
| 43 | + sa.Column("d1_first_pr_opened_at", sa.TIMESTAMP, nullable=True), |
| 44 | + sa.Column("d1_first_pr_commented_at", sa.TIMESTAMP, nullable=True), |
| 45 | + # D2 Level - Significant Contributions |
| 46 | + sa.Column( |
| 47 | + "d2_has_merged_pr", |
| 48 | + sa.Boolean(), |
| 49 | + server_default=sa.text("false"), |
| 50 | + nullable=True, |
| 51 | + ), |
| 52 | + sa.Column( |
| 53 | + "d2_created_many_issues", |
| 54 | + sa.Boolean(), |
| 55 | + server_default=sa.text("false"), |
| 56 | + nullable=True, |
| 57 | + ), |
| 58 | + sa.Column( |
| 59 | + "d2_total_comments", |
| 60 | + sa.BigInteger(), |
| 61 | + server_default=sa.text("0"), |
| 62 | + nullable=True, |
| 63 | + ), |
| 64 | + sa.Column( |
| 65 | + "d2_has_pr_with_many_commits", |
| 66 | + sa.Boolean(), |
| 67 | + server_default=sa.text("false"), |
| 68 | + nullable=True, |
| 69 | + ), |
| 70 | + sa.Column( |
| 71 | + "d2_commented_on_multiple_prs", |
| 72 | + sa.Boolean(), |
| 73 | + server_default=sa.text("false"), |
| 74 | + nullable=True, |
| 75 | + ), |
| 76 | + # Metadata |
| 77 | + sa.Column("tool_source", sa.String(), nullable=True), |
| 78 | + sa.Column("tool_version", sa.String(), nullable=True), |
| 79 | + sa.Column("data_source", sa.String(), nullable=True), |
| 80 | + sa.Column( |
| 81 | + "data_collection_date", |
| 82 | + sa.TIMESTAMP, |
| 83 | + server_default=sa.text("CURRENT_TIMESTAMP"), |
| 84 | + nullable=True, |
| 85 | + ), |
| 86 | + sa.ForeignKeyConstraint( |
| 87 | + ["repo_id"], |
| 88 | + ["augur_data.repo.repo_id"], |
| 89 | + name="fk_contributor_engagement_repo", |
| 90 | + ), |
| 91 | + sa.ForeignKeyConstraint( |
| 92 | + ["cntrb_id"], |
| 93 | + ["augur_data.contributors.cntrb_id"], |
| 94 | + name="fk_contributor_engagement_contributors", |
| 95 | + ), |
| 96 | + sa.PrimaryKeyConstraint("engagement_id"), |
| 97 | + schema="augur_data", |
| 98 | + ) |
| 99 | + |
| 100 | + |
| 101 | +def downgrade(): |
| 102 | + op.drop_table("contributor_engagement", schema="augur_data") |
0 commit comments