M api/graph/model/repository.go => api/graph/model/repository.go +0 -2
@@ 21,7 21,6 @@ type Repository struct {
Updated time.Time `json:"updated"`
Name string `json:"name"`
Description *string `json:"description"`
- UpstreamURL *string `json:"upstreamUrl"`
Readme *string `json:"readme"`
Path string
@@ 96,7 95,6 @@ func (r *Repository) Fields() *database.ModelFields {
{"name", "name", &r.Name},
{"description", "description", &r.Description},
{"visibility", "visibility", &r.RawVisibility},
- {"upstream_uri", "upstreamUrl", &r.UpstreamURL},
{"readme", "readme", &r.Readme},
// Always fetch:
M api/graph/schema.graphqls => api/graph/schema.graphqls +0 -6
@@ 134,12 134,6 @@ type Repository {
"""
readme: String
- """
- If this repository was cloned from another, this is set to the original
- clone URL.
- """
- upstreamUrl: String
-
accessControlList(cursor: Cursor): ACLCursor! @access(scope: ACLS, kind: RO)
## Plumbing API:
M api/graph/schema.resolvers.go => api/graph/schema.resolvers.go +6 -6
@@ 140,10 140,10 @@ func (r *mutationResolver) CreateRepository(ctx context.Context, name string, vi
$1, $2, $3, $4, $5, $6
) RETURNING
id, created, updated, name, description, visibility,
- upstream_uri, path, owner_id;
+ path, owner_id;
`, name, description, repoPath, dvis, user.UserID, cloneInProgress)
if err := row.Scan(&repo.ID, &repo.Created, &repo.Updated, &repo.Name,
- &repo.Description, &repo.RawVisibility, &repo.UpstreamURL,
+ &repo.Description, &repo.RawVisibility,
&repo.Path, &repo.OwnerID); err != nil {
if strings.Contains(err.Error(), "duplicate key value violates unique constraint") {
return valid.Errorf(ctx, "name", "A repository with this name already exists.")
@@ 379,12 379,12 @@ func (r *mutationResolver) UpdateRepository(ctx context.Context, id int, input m
Set(`updated`, sq.Expr(`now() at time zone 'utc'`)).
Suffix(`RETURNING
id, created, updated, name, description, visibility,
- upstream_uri, path, owner_id`)
+ path, owner_id`)
row := query.RunWith(tx).QueryRowContext(ctx)
if err := row.Scan(&repo.ID, &repo.Created, &repo.Updated,
&repo.Name, &repo.Description, &repo.RawVisibility,
- &repo.UpstreamURL, &repo.Path, &repo.OwnerID); err != nil {
+ &repo.Path, &repo.OwnerID); err != nil {
if err == sql.ErrNoRows {
return fmt.Errorf("No repository by ID %d found for this user", id)
}
@@ 452,12 452,12 @@ func (r *mutationResolver) DeleteRepository(ctx context.Context, id int) (*model
WHERE id = $1 AND owner_id = $2
RETURNING
id, created, updated, name, description, visibility,
- upstream_uri, path, owner_id;
+ path, owner_id;
`, id, auth.ForContext(ctx).UserID)
if err := row.Scan(&repo.ID, &repo.Created, &repo.Updated,
&repo.Name, &repo.Description, &repo.RawVisibility,
- &repo.UpstreamURL, &repo.Path, &repo.OwnerID); err != nil {
+ &repo.Path, &repo.OwnerID); err != nil {
if err == sql.ErrNoRows {
return fmt.Errorf("No repository by ID %d found for this user", id)
}
A gitsrht/alembic/versions/163a7732e6a0_drop_source_repo_id_from_repository.py => gitsrht/alembic/versions/163a7732e6a0_drop_source_repo_id_from_repository.py +32 -0
@@ 0,0 1,32 @@
+"""Drop source_repo_id from repository
+
+Revision ID: 163a7732e6a0
+Revises: 5f59f2639ca3
+Create Date: 2022-02-14 09:59:52.962377
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '163a7732e6a0'
+down_revision = '5f59f2639ca3'
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+ op.execute("""
+ ALTER TABLE repository
+ DROP COLUMN upstream_uri;
+ ALTER TABLE repository
+ DROP COLUMN source_repo_id;
+ """)
+
+
+def downgrade():
+ op.execute("""
+ ALTER TABLE repository
+ ADD COLUMN upstream_uri varchar;
+ ALTER TABLE repository
+ ADD COLUMN source_repo_id integer;
+ """)
M gitsrht/types/__init__.py => gitsrht/types/__init__.py +45 -3
@@ 1,11 1,13 @@
import os
import sqlalchemy as sa
from sqlalchemy import event
+import sqlalchemy_utils as sau
+from sqlalchemy.ext.declarative import declared_attr
from srht.database import Base
from srht.oauth import ExternalUserMixin, ExternalOAuthTokenMixin
from gitsrht.git import Repository as GitRepository
from scmsrht.repos import BaseAccessMixin, BaseRedirectMixin
-from scmsrht.repos import BaseRepositoryMixin, RepoVisibility
+from scmsrht.repos import RepoVisibility
class User(Base, ExternalUserMixin):
pass
@@ 19,11 21,51 @@ class Access(Base, BaseAccessMixin):
class Redirect(Base, BaseRedirectMixin):
pass
-class Repository(Base, BaseRepositoryMixin):
- _git_repo = None
+class Repository(Base):
+ @declared_attr
+ def __tablename__(cls):
+ return "repository"
+
+ @declared_attr
+ def __table_args__(cls):
+ return (
+ sa.UniqueConstraint('owner_id', 'name',
+ name="uq_repo_owner_id_name"),
+ )
+ _git_repo = None
+ id = sa.Column(sa.Integer, primary_key=True)
+ created = sa.Column(sa.DateTime, nullable=False)
+ updated = sa.Column(sa.DateTime, nullable=False)
+ name = sa.Column(sa.Unicode(256), nullable=False)
+ description = sa.Column(sa.Unicode(1024))
+ path = sa.Column(sa.Unicode(1024))
+ visibility = sa.Column(
+ sau.ChoiceType(RepoVisibility, impl=sa.String()),
+ nullable=False,
+ default=RepoVisibility.public)
+ readme = sa.Column(sa.Unicode)
clone_in_progress = sa.Column(sa.Boolean, nullable=False)
+ @declared_attr
+ def owner_id(cls):
+ return sa.Column(sa.Integer, sa.ForeignKey('user.id'), nullable=False)
+
+ @declared_attr
+ def owner(cls):
+ return sa.orm.relationship('User', backref=sa.orm.backref('repos'))
+
+ def to_dict(self):
+ return {
+ "id": self.id,
+ "created": self.created,
+ "updated": self.updated,
+ "name": self.name,
+ "owner": self.owner.to_dict(short=True),
+ "description": self.description,
+ "visibility": self.visibility,
+ }
+
@property
def git_repo(self):
if not self._git_repo: