~edwargix/git.sr.ht

c912f6e8c9929b51ff2ef7fc27b47fde5a684959 — Drew DeVault 7 years ago 540c859
Add webhook type
A gitsrht/alembic/versions/daf28fd9e001_add_webhook_table.py => gitsrht/alembic/versions/daf28fd9e001_add_webhook_table.py +40 -0
@@ 0,0 1,40 @@
"""Add webhook table

Revision ID: daf28fd9e001
Revises: bfcdce82e0fc
Create Date: 2017-09-19 20:53:10.516308

"""

# revision identifiers, used by Alembic.
revision = 'daf28fd9e001'
down_revision = 'bfcdce82e0fc'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('webhook',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('created', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.Column('updated', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.Column('description', sa.VARCHAR(length=1024), autoincrement=False, nullable=True),
    sa.Column('oauth_token_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('repo_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('url', sa.VARCHAR(length=2048), autoincrement=False, nullable=False),
    sa.Column('validate_ssl', sa.BOOLEAN(), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['oauth_token_id'], ['oauthtoken.id'], name='webhook_oauth_token_id_fkey'),
    sa.ForeignKeyConstraint(['repo_id'], ['repository.id'], name='webhook_repo_id_fkey'),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], name='webhook_user_id_fkey'),
    sa.PrimaryKeyConstraint('id', name='webhook_pkey')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('webhook')
    # ### end Alembic commands ###

M gitsrht/types/__init__.py => gitsrht/types/__init__.py +1 -0
@@ 1,3 1,4 @@
from .user import User
from .repository import Repository, RepoVisibility
from .oauthtoken import OAuthToken
from .webhook import Webhook

A gitsrht/types/webhook.py => gitsrht/types/webhook.py +24 -0
@@ 0,0 1,24 @@
import sqlalchemy as sa
import sqlalchemy_utils as sau
from srht.database import Base

class Webhook(Base):
    __tablename__ = "webhook"
    id = sa.Column(sa.Integer, primary_key=True)
    created = sa.Column(sa.DateTime, nullable=False)
    updated = sa.Column(sa.DateTime, nullable=False)
    description = sa.Column(sa.Unicode(1024))

    oauth_token_id = sa.Column(sa.Integer, sa.ForeignKey("oauthtoken.id"))
    oauth_token = sa.orm.relationship("OAuthToken",
            backref=sa.orm.backref("webhooks"))

    user_id = sa.Column(sa.Integer, sa.ForeignKey("user.id"), nullable=False)
    user = sa.orm.relationship("User", backref=sa.orm.backref("webhooks"))

    repo_id = sa.Column(sa.Integer, sa.ForeignKey("repository.id"))
    repository = sa.orm.relationship("Repository",
            backref=sa.orm.backref("webhooks"))

    url = sa.Column(sa.Unicode(2048), nullable=False)
    validate_ssl = sa.Column(sa.Boolean, nullable=False, default=True)