change tables
This commit is contained in:
parent
caa7ed9357
commit
2a1d2be232
|
@ -10,9 +10,6 @@ sys.path.append(str(pathlib.Path(__file__).resolve().parents[3]))
|
|||
|
||||
from app.utils.config_loader import ConfigLoader
|
||||
|
||||
import pymysql
|
||||
pymysql.install_as_MySQLdb() # we are using python3
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
|
@ -29,7 +26,7 @@ from app.db.tables import sqlalchemy_orm
|
|||
target_metadata = sqlalchemy_orm.Base.metadata
|
||||
|
||||
env = ConfigLoader().load_env()
|
||||
connection_url = "mysql+mysqldb://{user}:{password}@{host}:{port}/{db}".format(user=env["MYSQL"]["USER"], password=env["MYSQL"]["PASSWORD"], host=env["MYSQL"]["HOST"], port=env["MYSQL"]["PORT"], db=env["MYSQL"]["DB"])
|
||||
connection_url = "mysql+pymysql://{user}:{password}@{host}:{port}/{db}".format(user=env["MYSQL"]["USER"], password=env["MYSQL"]["PASSWORD"], host=env["MYSQL"]["HOST"], port=env["MYSQL"]["PORT"], db=env["MYSQL"]["DB"])
|
||||
config.set_main_option("sqlalchemy.url", connection_url) # we need to add this in main option, because the configuration of sqlalchemy.url is in .env.yaml, not in alembic.ini
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
"""add two indexes to pull_requests
|
||||
|
||||
Revision ID: 3f138d51442c
|
||||
Revises: 8ef9b7227965
|
||||
Create Date: 2021-08-15 15:25:04.176696
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '3f138d51442c'
|
||||
down_revision = '8ef9b7227965'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
|
@ -0,0 +1,34 @@
|
|||
"""change comment_or_not to default=0 and not nullable and add unique index for unique pull_request
|
||||
|
||||
Revision ID: 4939a95bd8e1
|
||||
Revises: ec616b7d4340
|
||||
Create Date: 2021-08-15 15:50:55.855430
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '4939a95bd8e1'
|
||||
down_revision = 'ec616b7d4340'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.alter_column('pull_requests', 'comment_or_not',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
nullable=False)
|
||||
op.create_index('owner_repo_num', 'pull_requests', ['owner_login', 'repo_name', 'number'], unique=True)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index('owner_repo_num', table_name='pull_requests')
|
||||
op.alter_column('pull_requests', 'comment_or_not',
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
nullable=True)
|
||||
# ### end Alembic commands ###
|
|
@ -0,0 +1,28 @@
|
|||
"""add column installation_id to pull_requests
|
||||
|
||||
Revision ID: 8ef9b7227965
|
||||
Revises: e69e7db9d798
|
||||
Create Date: 2021-08-15 15:21:53.401153
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '8ef9b7227965'
|
||||
down_revision = 'e69e7db9d798'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('pull_requests', sa.Column('installation_id', sa.Integer(), nullable=False))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('pull_requests', 'installation_id')
|
||||
# ### end Alembic commands ###
|
|
@ -0,0 +1,30 @@
|
|||
"""change table pull_requests
|
||||
|
||||
Revision ID: e69e7db9d798
|
||||
Revises: 4ad7b4a06e6c
|
||||
Create Date: 2021-08-15 13:15:50.974380
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'e69e7db9d798'
|
||||
down_revision = '4ad7b4a06e6c'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('pull_requests', sa.Column('last_comment_at', sa.TIMESTAMP(), nullable=True))
|
||||
op.drop_column('pull_requests', 'updated_at')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('pull_requests', sa.Column('updated_at', mysql.TIMESTAMP(), nullable=True))
|
||||
op.drop_column('pull_requests', 'last_comment_at')
|
||||
# ### end Alembic commands ###
|
|
@ -0,0 +1,32 @@
|
|||
"""change index format
|
||||
|
||||
Revision ID: ec616b7d4340
|
||||
Revises: f076c766cb48
|
||||
Create Date: 2021-08-15 15:30:23.121589
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'ec616b7d4340'
|
||||
down_revision = 'f076c766cb48'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_index(op.f('ix_comments_pull_request_id'), 'comments', ['pull_request_id'], unique=False)
|
||||
op.create_index(op.f('ix_pull_requests_locked'), 'pull_requests', ['locked'], unique=False)
|
||||
op.create_index(op.f('ix_pull_requests_state'), 'pull_requests', ['state'], unique=False)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index(op.f('ix_pull_requests_state'), table_name='pull_requests')
|
||||
op.drop_index(op.f('ix_pull_requests_locked'), table_name='pull_requests')
|
||||
op.drop_index(op.f('ix_comments_pull_request_id'), table_name='comments')
|
||||
# ### end Alembic commands ###
|
|
@ -0,0 +1,28 @@
|
|||
"""add an index to comments
|
||||
|
||||
Revision ID: f076c766cb48
|
||||
Revises: 3f138d51442c
|
||||
Create Date: 2021-08-15 15:25:58.162771
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'f076c766cb48'
|
||||
down_revision = '3f138d51442c'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
|
@ -10,6 +10,8 @@ class BaseOperator:
|
|||
|
||||
def __init__(self) -> None:
|
||||
try:
|
||||
self.engine = create_async_engine(ConfigLoader().load_env()["MYSQL"]["MYSQL_CONNECTION"], echo=True)
|
||||
env = ConfigLoader().load_env()
|
||||
url = "mysql+aiomysql://{user}:{password}@{host}:{port}/{db}".format(user=env["MYSQL"]["USER"], password=env["MYSQL"]["PASSWORD"], host=env["MYSQL"]["HOST"], port=env["MYSQL"]["PORT"], db=env["MYSQL"]["DB"])
|
||||
self.engine = create_async_engine(url, echo=True)
|
||||
except Exception as e:
|
||||
print("error with initialization of BaseOperator: %s" % (repr(e)))
|
|
@ -17,11 +17,15 @@ class PullRequestOperator(BaseOperator):
|
|||
super().__init__()
|
||||
|
||||
|
||||
'''
|
||||
check whether pr exists, if exists then update
|
||||
'''
|
||||
async def insert_pull_request(self, pr: PullRequest) -> None:
|
||||
def run_queries(session):
|
||||
session.execute(insert(tModel.PullRequest).values(
|
||||
owner_login = pr.owner.login,
|
||||
repo_name = pr.repo.name,
|
||||
installation_id = pr.installation.id,
|
||||
number = pr.number,
|
||||
state = pr.state,
|
||||
locked = pr.locked,
|
||||
|
@ -35,6 +39,13 @@ class PullRequestOperator(BaseOperator):
|
|||
except Exception as e:
|
||||
print("error with func insert_pull_request: %s" % (repr(e)))
|
||||
|
||||
|
||||
async def update_pull_request(self, pr: PullRequest) -> None:
|
||||
try:
|
||||
pass
|
||||
except Exception as e:
|
||||
print("error with func update_pull_request: %s" % (repr(e)))
|
||||
|
||||
|
||||
async def query_prs_4_scheduler(self) -> List[PullRequest]:
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue