Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions backend/alembic/versions/007_add_campaign_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""新增 Campaign 运营活动模块

Revision ID: 007_add_campaign_module
Revises: 006_link_committee_member_to_person
Create Date: 2026-02-22
"""
import sqlalchemy as sa
from alembic import op

revision = "007_add_campaign_module"
down_revision = "006_link_committee_member_to_person"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.create_table(
"campaigns",
sa.Column("id", sa.Integer, primary_key=True),
sa.Column("community_id", sa.Integer, sa.ForeignKey("communities.id", ondelete="CASCADE"), nullable=False),
sa.Column("name", sa.String(300), nullable=False),
sa.Column("description", sa.Text, nullable=True),
sa.Column("type", sa.String(50), nullable=False),
sa.Column("status", sa.String(50), nullable=False, server_default="draft"),
sa.Column("target_count", sa.Integer, nullable=True),
sa.Column("owner_id", sa.Integer, sa.ForeignKey("users.id", ondelete="SET NULL"), nullable=True),
sa.Column("start_date", sa.Date, nullable=True),
sa.Column("end_date", sa.Date, nullable=True),
sa.Column("created_at", sa.DateTime, server_default=sa.func.now()),
sa.Column("updated_at", sa.DateTime, server_default=sa.func.now()),
)
op.create_index("ix_campaigns_community_id", "campaigns", ["community_id"])

op.create_table(
"campaign_contacts",
sa.Column("id", sa.Integer, primary_key=True),
sa.Column("campaign_id", sa.Integer, sa.ForeignKey("campaigns.id", ondelete="CASCADE"), nullable=False),
sa.Column("person_id", sa.Integer, sa.ForeignKey("person_profiles.id", ondelete="CASCADE"), nullable=False),
sa.Column("status", sa.String(50), nullable=False, server_default="pending"),
sa.Column("channel", sa.String(50), nullable=True),
sa.Column("added_by", sa.String(50), nullable=False, server_default="manual"),
sa.Column("last_contacted_at", sa.DateTime, nullable=True),
sa.Column("notes", sa.Text, nullable=True),
sa.Column("assigned_to_id", sa.Integer, sa.ForeignKey("users.id", ondelete="SET NULL"), nullable=True),
sa.UniqueConstraint("campaign_id", "person_id", name="uq_campaign_contact"),
)
op.create_index("ix_campaign_contacts_campaign_id", "campaign_contacts", ["campaign_id"])
op.create_index("ix_campaign_contacts_person_id", "campaign_contacts", ["person_id"])

op.create_table(
"campaign_activities",
sa.Column("id", sa.Integer, primary_key=True),
sa.Column("campaign_id", sa.Integer, sa.ForeignKey("campaigns.id", ondelete="CASCADE"), nullable=False),
sa.Column("person_id", sa.Integer, sa.ForeignKey("person_profiles.id", ondelete="CASCADE"), nullable=False),
sa.Column("action", sa.String(50), nullable=False),
sa.Column("content", sa.Text, nullable=True),
sa.Column("outcome", sa.String(300), nullable=True),
sa.Column("operator_id", sa.Integer, sa.ForeignKey("users.id", ondelete="SET NULL"), nullable=True),
sa.Column("created_at", sa.DateTime, server_default=sa.func.now()),
)
op.create_index("ix_campaign_activities_campaign_id", "campaign_activities", ["campaign_id"])


def downgrade() -> None:
op.drop_table("campaign_activities")
op.drop_table("campaign_contacts")
op.drop_table("campaigns")
55 changes: 55 additions & 0 deletions backend/alembic/versions/008_add_ecosystem_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""新增 Ecosystem 生态洞察模块

Revision ID: 008_add_ecosystem_module
Revises: 007_add_campaign_module
Create Date: 2026-02-22
"""
import sqlalchemy as sa
from alembic import op

revision = "008_add_ecosystem_module"
down_revision = "007_add_campaign_module"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.create_table(
"ecosystem_projects",
sa.Column("id", sa.Integer, primary_key=True),
sa.Column("name", sa.String(200), nullable=False),
sa.Column("platform", sa.String(30), nullable=False),
sa.Column("org_name", sa.String(200), nullable=False),
sa.Column("repo_name", sa.String(200), nullable=True),
sa.Column("description", sa.Text, nullable=True),
sa.Column("tags", sa.JSON, nullable=True),
sa.Column("is_active", sa.Boolean, server_default="1"),
sa.Column("last_synced_at", sa.DateTime, nullable=True),
sa.Column("added_by_id", sa.Integer, sa.ForeignKey("users.id", ondelete="SET NULL"), nullable=True),
sa.Column("created_at", sa.DateTime, server_default=sa.func.now()),
)

op.create_table(
"ecosystem_contributors",
sa.Column("id", sa.Integer, primary_key=True),
sa.Column("project_id", sa.Integer, sa.ForeignKey("ecosystem_projects.id", ondelete="CASCADE"), nullable=False),
sa.Column("github_handle", sa.String(100), nullable=False),
sa.Column("display_name", sa.String(200), nullable=True),
sa.Column("avatar_url", sa.String(500), nullable=True),
sa.Column("role", sa.String(50), nullable=True),
sa.Column("commit_count_90d", sa.Integer, nullable=True),
sa.Column("pr_count_90d", sa.Integer, nullable=True),
sa.Column("star_count", sa.Integer, nullable=True),
sa.Column("followers", sa.Integer, nullable=True),
sa.Column("person_id", sa.Integer, sa.ForeignKey("person_profiles.id", ondelete="SET NULL"), nullable=True),
sa.Column("last_synced_at", sa.DateTime, server_default=sa.func.now()),
sa.UniqueConstraint("project_id", "github_handle", name="uq_eco_contributor"),
)
op.create_index("ix_ecosystem_contributors_project_id", "ecosystem_contributors", ["project_id"])
op.create_index("ix_ecosystem_contributors_github_handle", "ecosystem_contributors", ["github_handle"])
op.create_index("ix_ecosystem_contributors_person_id", "ecosystem_contributors", ["person_id"])


def downgrade() -> None:
op.drop_table("ecosystem_contributors")
op.drop_table("ecosystem_projects")
40 changes: 40 additions & 0 deletions backend/alembic/versions/009_add_ecosystem_community_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Ecosystem projects 增加 community_id 多租户字段

Revision ID: 009_add_ecosystem_community_id
Revises: 008_add_ecosystem_module
Create Date: 2026-02-22
"""
import sqlalchemy as sa
from alembic import op

revision = "009_add_ecosystem_community_id"
down_revision = "008_add_ecosystem_module"
branch_labels = None
depends_on = None


def upgrade() -> None:
# SQLite 不支持 ADD COLUMN NOT NULL without default,用 batch 模式
with op.batch_alter_table("ecosystem_projects") as batch_op:
batch_op.add_column(
sa.Column(
"community_id",
sa.Integer,
nullable=True, # 已有数据兼容;新记录由 API 层强制填写
)
)
batch_op.create_index("ix_ecosystem_projects_community_id", ["community_id"])
batch_op.create_foreign_key(
"fk_ecosystem_projects_community_id",
"communities",
["community_id"],
["id"],
ondelete="CASCADE",
)


def downgrade() -> None:
with op.batch_alter_table("ecosystem_projects") as batch_op:
batch_op.drop_constraint("fk_ecosystem_projects_community_id", type_="foreignkey")
batch_op.drop_index("ix_ecosystem_projects_community_id")
batch_op.drop_column("community_id")
Loading
Loading