Skip to content

Commit

Permalink
Add a new usage function to get the onboarded projects (#2330)
Browse files Browse the repository at this point in the history
Add a new usage function to get the onboarded projects

I re-ran it with the production db locally and I got this:
Merge before packit/dashboard#373
{
  "onboarded": {
    "31087": "https://src.fedoraproject.org/rpms/dnf5",
    "31092": "https://src.fedoraproject.org/rpms/libreport",
    "31094": "https://src.fedoraproject.org/rpms/osbuild",
    "31096": "https://src.fedoraproject.org/rpms/linux-system-roles",
    "31098": "https://src.fedoraproject.org/rpms/packit",
    "31099": "https://src.fedoraproject.org/rpms/python-scikit-build-core",
    "31107": "https://src.fedoraproject.org/rpms/container-selinux",
    "31108": "https://src.fedoraproject.org/rpms/fedora-messaging",
    "31109": "https://src.fedoraproject.org/rpms/python-noggin-messages",
    "31111": "https://src.fedoraproject.org/rpms/cockpit-podman",
    "31112": "https://src.fedoraproject.org/rpms/cockpit",
    "31113": "https://src.fedoraproject.org/rpms/python-awscrt",
    "31116": "https://src.fedoraproject.org/rpms/nmstate",
    "31117": "https://src.fedoraproject.org/rpms/cockpit-machines",
    "31118": "https://src.fedoraproject.org/rpms/anaconda",
    "31129": "https://src.fedoraproject.org/rpms/podman",
    "31139": "https://src.fedoraproject.org/rpms/awscli2",
    "31142": "https://src.fedoraproject.org/rpms/python-specfile",
    "31153": "https://src.fedoraproject.org/rpms/gpxsee",
    "31154": "https://src.fedoraproject.org/rpms/cockpit-ostree",
    "31155": "https://src.fedoraproject.org/rpms/subscription-manager",
    "31157": "https://src.fedoraproject.org/rpms/qm",
    "31311": "https://src.fedoraproject.org/rpms/osbuild-composer",
    "31312": "https://src.fedoraproject.org/rpms/cockpit-session-recording",
    "31356": "https://src.fedoraproject.org/rpms/abrt-java-connector",
    "31359": "https://src.fedoraproject.org/rpms/man-pages-l10n",
    "31365": "https://src.fedoraproject.org/rpms/python-deprecated",
    "31372": "https://src.fedoraproject.org/rpms/fasterxml-oss-parent",
    "31392": "https://src.fedoraproject.org/rpms/python-ogr",
    "31394": "https://src.fedoraproject.org/rpms/python-fasjson-client",
    "31395": "https://src.fedoraproject.org/rpms/tmt",
    "31404": "https://src.fedoraproject.org/rpms/mrack",
    "31405": "https://src.fedoraproject.org/rpms/blivet-gui",
    "31406": "https://src.fedoraproject.org/rpms/koji-osbuild",
    "31409": "https://src.fedoraproject.org/rpms/python-unidiff",
    "31412": "https://src.fedoraproject.org/rpms/perl-Date-Manip",
    "31413": "https://src.fedoraproject.org/rpms/libbytesize",
    "31414": "https://src.fedoraproject.org/rpms/python-requre",
    "31416": "https://src.fedoraproject.org/rpms/openscap-report",
    "31417": "https://src.fedoraproject.org/rpms/retrace-server",
    "31420": "https://src.fedoraproject.org/rpms/python-simpleline",
    "31421": "https://src.fedoraproject.org/rpms/python-dbusmock",
    "31423": "https://src.fedoraproject.org/rpms/jss",
    "31424": "https://src.fedoraproject.org/rpms/ldapjdk",
    "31425": "https://src.fedoraproject.org/rpms/tomcatjss",
    "31432": "https://src.fedoraproject.org/rpms/rakudo",
    "31497": "https://src.fedoraproject.org/rpms/sscg",
    "31521": "https://src.fedoraproject.org/rpms/contour-terminal",
    "31522": "https://src.fedoraproject.org/rpms/sen",
    "31524": "https://src.fedoraproject.org/rpms/man-pages",
    "31525": "https://src.fedoraproject.org/rpms/netavark",
    "31526": "https://src.fedoraproject.org/rpms/aardvark-dns",
    "31570": "https://src.fedoraproject.org/rpms/gnome-abrt",
    "31584": "https://src.fedoraproject.org/rpms/golang",
    "31585": "https://src.fedoraproject.org/rpms/rebase-helper",
    "31586": "https://src.fedoraproject.org/rpms/python-oci",
    "31587": "https://src.fedoraproject.org/rpms/google-guest-agent",
    "31590": "https://src.fedoraproject.org/rpms/oci-cli",
    "31592": "https://src.fedoraproject.org/rpms/golang-github-vultr-govultr-3",
    "31597": "https://src.fedoraproject.org/rpms/golang-github-google-dap",
    "31598": "https://src.fedoraproject.org/rpms/git-credential-oauth",
    "31602": "https://src.fedoraproject.org/rpms/cockpit-composer",
    "31609": "https://src.fedoraproject.org/rpms/greenboot",
    "31611": "https://src.fedoraproject.org/rpms/liboauth2",
    "31613": "https://src.fedoraproject.org/rpms/python-google-cloud-bigquery",
    "31618": "https://src.fedoraproject.org/rpms/umockdev",
    "31620": "https://src.fedoraproject.org/rpms/will-crash",
    "31622": "https://src.fedoraproject.org/rpms/p11-kit",
    "31624": "https://src.fedoraproject.org/rpms/python-google-cloud-spanner",
    "31628": "https://src.fedoraproject.org/rpms/python-google-cloud-container",
    "31629": "https://src.fedoraproject.org/rpms/google-compute-engine-guest-configs",
    "31632": "https://src.fedoraproject.org/rpms/python-google-cloud-kms",
    "31633": "https://src.fedoraproject.org/rpms/python-google-cloud-firestore",
    "31634": "https://src.fedoraproject.org/rpms/python-awsiotsdk",
    "31693": "https://src.fedoraproject.org/rpms/python-google-cloud-billing",
    "31694": "https://src.fedoraproject.org/rpms/python-google-cloud-functions",
    "31695": "https://src.fedoraproject.org/rpms/python-google-cloud-deploy",
    "31696": "https://src.fedoraproject.org/rpms/python-google-cloud-dataproc",
    "31698": "https://src.fedoraproject.org/rpms/git-credential-azure",
    "31715": "https://src.fedoraproject.org/rpms/python-google-cloud-bigtable",
    "31717": "https://src.fedoraproject.org/rpms/snakemake",
    "31789": "https://src.fedoraproject.org/rpms/python-setuptools-git-versioning",
    "31792": "https://src.fedoraproject.org/rpms/python-datalad",
    "31793": "https://src.fedoraproject.org/rpms/buildah",
    "31794": "https://src.fedoraproject.org/rpms/skopeo",
    "31795": "https://src.fedoraproject.org/rpms/python-pymatreader",
    "31798": "https://src.fedoraproject.org/rpms/python-yfinance",
    "31799": "https://src.fedoraproject.org/rpms/python-looseversion",
    "31800": "https://src.fedoraproject.org/rpms/python-formulaic",
    "31801": "https://src.fedoraproject.org/rpms/python-pandas-flavor",
    "31802": "https://src.fedoraproject.org/rpms/python-dunamai",
    "31804": "https://src.fedoraproject.org/rpms/python-matrix-nio",
    "31805": "https://src.fedoraproject.org/rpms/ocserv",
    "31814": "https://src.fedoraproject.org/rpms/python-pydicom",
    "31819": "https://src.fedoraproject.org/rpms/crun",
    "31820": "https://src.fedoraproject.org/rpms/golang-github-hetznercloud-hcloud",
    "31821": "https://src.fedoraproject.org/rpms/hcloud",
    "31826": "https://src.fedoraproject.org/rpms/python-flask-oidc",
    "31830": "https://src.fedoraproject.org/rpms/vultr-cli",
    "31838": "https://src.fedoraproject.org/rpms/python-mne",
    "31839": "https://src.fedoraproject.org/rpms/python-mne-bids",
    "31840": "https://src.fedoraproject.org/rpms/python-urwid",
    "31841": "https://src.fedoraproject.org/rpms/python-pybids",
    "31847": "https://src.fedoraproject.org/rpms/python-geopy",
    "31848": "https://src.fedoraproject.org/rpms/python-linuxdoc",
    "31870": "https://src.fedoraproject.org/rpms/python-poetry-dynamic-versioning",
    "31872": "https://src.fedoraproject.org/rpms/python-google-cloud-billing-budgets",
    "31922": "https://src.fedoraproject.org/rpms/distribution-gpg-keys",
    "31952": "https://src.fedoraproject.org/rpms/fedora-license-data",
    "31953": "https://src.fedoraproject.org/rpms/libmks",
    "31956": "https://src.fedoraproject.org/rpms/mysql-selinux",
    "31958": "https://src.fedoraproject.org/rpms/google-osconfig-agent",
    "31960": "https://src.fedoraproject.org/rpms/timew",
    "32022": "https://src.fedoraproject.org/rpms/python-google-cloud-data-fusion",
    "32023": "https://src.fedoraproject.org/rpms/python-google-cloud-storage",
    "32024": "https://src.fedoraproject.org/rpms/python-google-cloud-iam",
    "32026": "https://src.fedoraproject.org/rpms/morphio",
    "32038": "https://src.fedoraproject.org/rpms/python-twilio",
    "32040": "https://src.fedoraproject.org/rpms/gvisor-tap-vsock",
    "32041": "https://src.fedoraproject.org/rpms/python-podman",
    "32044": "https://src.fedoraproject.org/rpms/rpmdeplint",
    "32046": "https://src.fedoraproject.org/rpms/datagrepper",
    "32047": "https://src.fedoraproject.org/rpms/autorestic",
    "32050": "https://src.fedoraproject.org/rpms/python-google-cloud-os-config",
    "32052": "https://src.fedoraproject.org/rpms/python-google-cloud-dataproc-metastore",
    "32053": "https://src.fedoraproject.org/rpms/python-google-cloud-bigquery-reservation",
    "32054": "https://src.fedoraproject.org/rpms/python-google-cloud-bigquery-datatransfer",
    "32055": "https://src.fedoraproject.org/rpms/python-google-cloud-bigquery-connection",
    "32056": "https://src.fedoraproject.org/rpms/python-google-cloud-api-gateway",
    "32058": "https://src.fedoraproject.org/rpms/python-ibm-cloud-sdk-core",
    "32063": "https://src.fedoraproject.org/rpms/python-msal",
    "32066": "https://src.fedoraproject.org/rpms/labwc",
    "32067": "https://src.fedoraproject.org/rpms/vokoscreenNG",
    "32076": "https://src.fedoraproject.org/rpms/python-ibm-vpc",
    "32077": "https://src.fedoraproject.org/rpms/xaos",
    "32078": "https://src.fedoraproject.org/rpms/icewm",
    "32079": "https://src.fedoraproject.org/rpms/python-neurom",
    "32086": "https://src.fedoraproject.org/rpms/speedtest",
    "32087": "https://src.fedoraproject.org/rpms/qownnotes",
    "32100": "https://src.fedoraproject.org/rpms/python-lsp-server",
    "32104": "https://src.fedoraproject.org/rpms/nwg-panel",
    "32107": "https://src.fedoraproject.org/rpms/python-googleapis-common-protos",
    "32110": "https://src.fedoraproject.org/rpms/cpu-x",
    "32111": "https://src.fedoraproject.org/rpms/komikku",
    "32114": "https://src.fedoraproject.org/rpms/python-bids-validator",
    "32116": "https://src.fedoraproject.org/rpms/corectrl",
    "32120": "https://src.fedoraproject.org/rpms/profile-sync-daemon",
    "32132": "https://src.fedoraproject.org/rpms/libunarr",
    "32135": "https://src.fedoraproject.org/rpms/python-google-cloud-build",
    "32136": "https://src.fedoraproject.org/rpms/python-google-cloud-automl",
    "32138": "https://src.fedoraproject.org/rpms/python-google-cloud-asset",
    "32182": "https://src.fedoraproject.org/rpms/python-qcengine",
    "32184": "https://src.fedoraproject.org/rpms/console-setup",
    "32185": "https://src.fedoraproject.org/rpms/blosc2",
    "32186": "https://src.fedoraproject.org/rpms/rpm-head-signing",
    "32189": "https://src.fedoraproject.org/rpms/imapfilter",
    "32190": "https://src.fedoraproject.org/rpms/nghttp2",
    "32199": "https://src.fedoraproject.org/rpms/python-google-cloud-dlp",
    "32200": "https://src.fedoraproject.org/rpms/python-APScheduler",
    "32203": "https://src.fedoraproject.org/rpms/gedit-control-your-tabs",
    "32205": "https://src.fedoraproject.org/rpms/python-adjustText",
    "32206": "https://src.fedoraproject.org/rpms/python-license-expression",
    "32208": "https://src.fedoraproject.org/rpms/python-libNeuroML",
    "32219": "https://src.fedoraproject.org/rpms/polybar",
    "32220": "https://src.fedoraproject.org/rpms/jackson-annotations",
    "32221": "https://src.fedoraproject.org/rpms/jackson-core",
    "32222": "https://src.fedoraproject.org/rpms/jackson-jaxrs-providers",
    "32223": "https://src.fedoraproject.org/rpms/jackson-modules-base",
    "32224": "https://src.fedoraproject.org/rpms/jackson-bom",
    "32230": "https://src.fedoraproject.org/rpms/micropipenv",
    "32234": "https://src.fedoraproject.org/rpms/video-downloader",
    "32237": "https://src.fedoraproject.org/rpms/efs-utils",
    "32239": "https://src.fedoraproject.org/rpms/python-imapclient",
    "32247": "https://src.fedoraproject.org/rpms/python-grpc-google-iam-v1",
    "32267": "https://src.fedoraproject.org/rpms/delve",
    "32272": "https://src.fedoraproject.org/rpms/foliate",
    "32314": "https://src.fedoraproject.org/rpms/groonga",
    "32326": "https://src.fedoraproject.org/rpms/anaconda-webui",
    "32364": "https://src.fedoraproject.org/rpms/python-google-cloud-bigquery-storage",
    "32365": "https://src.fedoraproject.org/rpms/python-google-cloud-org-policy",
    "32367": "https://src.fedoraproject.org/rpms/legendary",
    "32378": "https://src.fedoraproject.org/rpms/python-damo",
    "32382": "https://src.fedoraproject.org/rpms/python-google-cloud-source-context",
    "32383": "https://src.fedoraproject.org/rpms/python-google-cloud-redis",
    "32384": "https://src.fedoraproject.org/rpms/python-google-cloud-dms",
    "32385": "https://src.fedoraproject.org/rpms/python-google-cloud-private-ca",
    "32387": "https://src.fedoraproject.org/rpms/nispor",
    "32389": "https://src.fedoraproject.org/rpms/boxed-cpp",
    "32391": "https://src.fedoraproject.org/rpms/qt5-qtpbfimageformat",
    "32394": "https://src.fedoraproject.org/rpms/croaring",
    "32395": "https://src.fedoraproject.org/rpms/ddnet",
    "32396": "https://src.fedoraproject.org/rpms/libphonenumber",
    "32397": "https://src.fedoraproject.org/rpms/python-trimesh",
    "32400": "https://src.fedoraproject.org/rpms/rust-coreos-installer",
    "32405": "https://src.fedoraproject.org/rpms/moarvm",
    "32406": "https://src.fedoraproject.org/rpms/nqp",
    "32419": "https://src.fedoraproject.org/rpms/python-snakemake-interface-common",
    "32425": "https://src.fedoraproject.org/rpms/python-pyspellchecker",
    "32428": "https://src.fedoraproject.org/rpms/python-textdistance",
    "32435": "https://src.fedoraproject.org/rpms/protontricks",
    "32439": "https://src.fedoraproject.org/rpms/python-engineio",
    "32440": "https://src.fedoraproject.org/rpms/pipx",
    "32441": "https://src.fedoraproject.org/rpms/texworks",
    "32446": "https://src.fedoraproject.org/rpms/zydis",
    "32449": "https://src.fedoraproject.org/rpms/python-fsleyes",
    "32451": "https://src.fedoraproject.org/rpms/python-nihtest",
    "32452": "https://src.fedoraproject.org/rpms/brewtarget",
    "32454": "https://src.fedoraproject.org/rpms/python-fslpy",
    "32545": "https://src.fedoraproject.org/rpms/gtk-layer-shell",
    "32546": "https://src.fedoraproject.org/rpms/python-h5io",
    "32548": "https://src.fedoraproject.org/rpms/python-gsd",
    "32842": "https://src.fedoraproject.org/rpms/golang-x-term",
    "32844": "https://src.fedoraproject.org/rpms/python-distro",
    "32846": "https://src.fedoraproject.org/rpms/minder",
    "32860": "https://src.fedoraproject.org/rpms/python-esbonio",
    "32865": "https://src.fedoraproject.org/rpms/golang-github-opencontainers-runc",
    "32869": "https://src.fedoraproject.org/rpms/paho-cpp",
    "32876": "https://src.fedoraproject.org/rpms/python-pyroaring",
    "32893": "https://src.fedoraproject.org/rpms/minigalaxy",
    "32895": "https://src.fedoraproject.org/rpms/picom",
    "32986": "https://src.fedoraproject.org/rpms/gwe",
    "32987": "https://src.fedoraproject.org/rpms/s-tui"
  },
  "almost_onboarded": {
    "31104": "https://src.fedoraproject.org/rpms/python-scikit-build",
    "31371": "https://src.fedoraproject.org/rpms/libxcrypt",
    "31408": "https://src.fedoraproject.org/rpms/python-docker",
    "31508": "https://src.fedoraproject.org/rpms/mfem",
    "31574": "https://src.fedoraproject.org/rpms/golang-github-docker-distribution",
    "31691": "https://src.fedoraproject.org/rpms/python-dockerfile-parse",
    "31700": "https://src.fedoraproject.org/rpms/python-fabric",
    "31803": "https://src.fedoraproject.org/rpms/python-pyspike",
    "31822": "https://src.fedoraproject.org/rpms/jowl",
    "31871": "https://src.fedoraproject.org/rpms/spglib",
    "31951": "https://src.fedoraproject.org/rpms/pyodbc",
    "31954": "https://src.fedoraproject.org/rpms/alot",
    "31957": "https://src.fedoraproject.org/rpms/unixODBC",
    "32057": "https://src.fedoraproject.org/rpms/python-google-cloud-access-approval",
    "32098": "https://src.fedoraproject.org/rpms/adw-gtk3-theme",
    "32112": "https://src.fedoraproject.org/rpms/golang-x-oauth2",
    "32113": "https://src.fedoraproject.org/rpms/python-nilearn",
    "32126": "https://src.fedoraproject.org/rpms/license-validate",
    "32183": "https://src.fedoraproject.org/rpms/python-jupyter-server",
    "32232": "https://src.fedoraproject.org/rpms/python-fastavro",
    "32252": "https://src.fedoraproject.org/rpms/python-apypie",
    "32422": "https://src.fedoraproject.org/rpms/python-fastapi",
    "32849": "https://src.fedoraproject.org/rpms/pcs",
    "32854": "https://src.fedoraproject.org/rpms/distrobox",
    "32866": "https://src.fedoraproject.org/rpms/golang-x-arch",
    "32880": "https://src.fedoraproject.org/rpms/python-jaraco-envs",
    "32881": "https://src.fedoraproject.org/rpms/ini2toml",
    "32906": "https://src.fedoraproject.org/rpms/python-marshmallow",
    "32970": "https://src.fedoraproject.org/rpms/rubygem-cucumber-gherkin",
    "32983": "https://src.fedoraproject.org/rpms/rubygem-cucumber-cucumber-expressions",
    "32984": "https://src.fedoraproject.org/rpms/rubygem-cucumber-messages",
    "32985": "https://src.fedoraproject.org/rpms/python-fastjsonschema"
  }
}
Fixes #2304

Reviewed-by: Laura Barcziová
Reviewed-by: Maja Massarini
Reviewed-by: František Lachman <flachman@redhat.com>
  • Loading branch information
softwarefactory-project-zuul[bot] authored Feb 13, 2024
2 parents 2d6a08f + 48e8208 commit 77896a1
Show file tree
Hide file tree
Showing 19 changed files with 780 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Add onboarded check in GitProjectModel table
Revision ID: 31111f804dec
Revises: a3a17014c282
Create Date: 2024-02-02 09:18:57.399510
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "31111f804dec"
down_revision = "a3a17014c282"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"git_projects", sa.Column("onboarded_downstream", sa.Boolean(), nullable=True)
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("git_projects", "onboarded_downstream")
# ### end Alembic commands ###
199 changes: 199 additions & 0 deletions alembic/versions/7d2b9fb924fa_add_sync_release_pull_request_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
"""Add sync_release_pull_request table
Revision ID: 7d2b9fb924fa
Revises: 31111f804dec
Create Date: 2024-02-07 09:53:51.363885
"""
import sqlalchemy as sa

from alembic import op
from typing import TYPE_CHECKING

from sqlalchemy import (
Column,
ForeignKey,
Integer,
String,
)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship

if TYPE_CHECKING:
Base = object
else:
Base = declarative_base()


# revision identifiers, used by Alembic.
revision = "7d2b9fb924fa"
down_revision = "31111f804dec"
branch_labels = None
depends_on = None


class SyncReleaseTargetModel(Base):
__tablename__ = "sync_release_run_targets"
id = Column(Integer, primary_key=True)
downstream_pr_url = Column(String)
downstream_pr_id = Column(Integer, ForeignKey("sync_release_pull_request.id"))

pull_request = relationship(
"SyncReleasePullRequestModel", back_populates="sync_release_targets"
)


class GitProjectModel(Base):
__tablename__ = "git_projects"
id = Column(Integer, primary_key=True)
namespace = Column(String, index=True)
repo_name = Column(String, index=True)
sync_release_pull_requests = relationship(
"SyncReleasePullRequestModel", back_populates="project"
)
project_url = Column(String)
instance_url = Column(String, nullable=False)

@classmethod
def get_or_create(
cls, namespace: str, repo_name: str, project_url: str, session: sa.orm.Session
) -> "GitProjectModel":
project = (
session.query(GitProjectModel)
.filter_by(
namespace=namespace, repo_name=repo_name, project_url=project_url
)
.first()
)
if not project:
project = cls()
project.repo_name = repo_name
project.namespace = namespace
project.project_url = project_url
project.instance_url = "https://src.fedoraproject.org/"
session.add(project)
return project


class SyncReleasePullRequestModel(Base):
__tablename__ = "sync_release_pull_request"

id = Column(Integer, primary_key=True)
pr_id = Column(Integer, index=True)
project_id = Column(Integer, ForeignKey("git_projects.id"), index=True)
project = relationship(
"GitProjectModel", back_populates="sync_release_pull_requests"
)
sync_release_targets = relationship(
"SyncReleaseTargetModel", back_populates="pull_request"
)

@classmethod
def get_or_create(
cls,
pr_id: int,
namespace: str,
repo_name: str,
project_url: str,
session: sa.orm.Session,
) -> "SyncReleasePullRequestModel":
project = GitProjectModel.get_or_create(
namespace=namespace,
repo_name=repo_name,
project_url=project_url,
session=session,
)
pr = (
session.query(SyncReleasePullRequestModel)
.filter_by(pr_id=pr_id, project_id=project.id)
.first()
)
if not pr:
pr = SyncReleasePullRequestModel()
pr.pr_id = pr_id
pr.project_id = project.id
session.add(pr)
return pr


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"sync_release_pull_request",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("pr_id", sa.Integer(), nullable=True),
sa.Column("project_id", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
["project_id"],
["git_projects.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_sync_release_pull_request_pr_id"),
"sync_release_pull_request",
["pr_id"],
unique=False,
)
op.create_index(
op.f("ix_sync_release_pull_request_project_id"),
"sync_release_pull_request",
["project_id"],
unique=False,
)
op.add_column(
"sync_release_run_targets",
sa.Column("downstream_pr_id", sa.Integer(), nullable=True),
)
op.create_foreign_key(
None,
"sync_release_run_targets",
"sync_release_pull_request",
["downstream_pr_id"],
["id"],
)

# ### end Alembic commands ###
bind = op.get_bind()
session = sa.orm.Session(bind=bind)

# Create Packit downstream pull request models
# and missing git projects.

# Split the groups back, this may not fully produce the same thing.
for sync_release in session.query(SyncReleaseTargetModel):
if sync_release.downstream_pr_url and not sync_release.pull_request:
try:
url = sync_release.downstream_pr_url
# noqa[203]: prettier like it this way
project_url = url[0 : (url.rfind("/pull-request/"))] # noqa[203]
pr_id = int(url[(url.rfind("/pull-request/") + 14) :]) # noqa[203]
namespace = "rpms"
repo = url[
(url.rfind("rpms/") + 5) : url.rfind("/pull-request") # noqa[203]
]
pull_request = SyncReleasePullRequestModel.get_or_create(
pr_id, namespace, repo, project_url, session
)
sync_release.pull_request = pull_request
session.add(pull_request)
except Exception as e:
print(
f"Error creating SyncReleasePullRequestModel during migration {e}"
)


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, "sync_release_run_targets", type_="foreignkey")
op.drop_column("sync_release_run_targets", "downstream_pr_id")
op.drop_index(
op.f("ix_sync_release_pull_request_project_id"),
table_name="sync_release_pull_request",
)
op.drop_index(
op.f("ix_sync_release_pull_request_pr_id"),
table_name="sync_release_pull_request",
)
op.drop_table("sync_release_pull_request")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
Create Date: 2021-08-26 15:19:49.615046
"""

from typing import TYPE_CHECKING

from alembic import op
import sqlalchemy as sa
from packit_service.models import GitProjectModel
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base

# https://github.com/python/mypy/issues/2477#issuecomment-313984522 ^_^
if TYPE_CHECKING:
Base = object
else:
Base = declarative_base()

# revision identifiers, used by Alembic.
revision = "8fee25b27402"
Expand All @@ -16,6 +26,14 @@
depends_on = None


class GitProjectModel(Base):
__tablename__ = "git_projects"
id = Column(Integer, primary_key=True)

project_url = Column(String)
instance_url = Column(String, nullable=False)


def upgrade():
bind = op.get_bind()
session = sa.orm.Session(bind=bind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
Create Date: 2020-11-05 11:33:02.769607
"""
from typing import TYPE_CHECKING

from urllib.parse import urlparse

from alembic import op
import sqlalchemy as sa
from sqlalchemy import orm

from packit_service.models import GitProjectModel
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base

# https://github.com/python/mypy/issues/2477#issuecomment-313984522 ^_^
if TYPE_CHECKING:
Base = object
else:
Base = declarative_base()

# revision identifiers, used by Alembic.
revision = "e35bb9ce7313"
Expand All @@ -20,6 +29,14 @@
depends_on = None


class GitProjectModel(Base):
__tablename__ = "git_projects"
id = Column(Integer, primary_key=True)

project_url = Column(String)
instance_url = Column(String, nullable=False)


def upgrade():
bind = op.get_bind()
session = orm.Session(bind=bind)
Expand Down
Loading

0 comments on commit 77896a1

Please sign in to comment.