Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

system rework #5

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
auto-spark-key.json
*.csv
!*.example.csv
*.txt
Expand Down Expand Up @@ -186,3 +187,5 @@ fabric.properties

# idea folder, uncomment if you don't need it
.idea

alembic.ini
6 changes: 6 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ python-multipart = "*"
pandas = "*"
aiocache = {extras = ["redis", "memcached"], version = "*"}
slack-sdk = "*"
sqlmodel = "*"
pyright = "*"
mypy = "*"
alembic = "*"
google-api-python-client = "*"
install = "*"

[dev-packages]

Expand Down
825 changes: 647 additions & 178 deletions Pipfile.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/alembic/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generic single-database configuration.
77 changes: 77 additions & 0 deletions app/alembic/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool

from alembic import context

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
from models import Base
target_metadata = Base.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.

This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.

Calls to context.execute() here emit the given string to the
script output.

"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)

with context.begin_transaction():
context.run_migrations()


def run_migrations_online() -> None:
"""Run migrations in 'online' mode.

In this scenario we need to create an Engine
and associate a connection with the context.

"""
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)

with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)

with context.begin_transaction():
context.run_migrations()


if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
26 changes: 26 additions & 0 deletions app/alembic/script.py.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""${message}

Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
${imports if imports else ""}

# revision identifiers, used by Alembic.
revision: str = ${repr(up_revision)}
down_revision: Union[str, None] = ${repr(down_revision)}
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}


def upgrade() -> None:
${upgrades if upgrades else "pass"}


def downgrade() -> None:
${downgrades if downgrades else "pass"}
30 changes: 30 additions & 0 deletions app/alembic/versions/0481276c6c83_fix_unique_constraints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Fix unique constraints

Revision ID: 0481276c6c83
Revises: 94fce2a59224
Create Date: 2024-12-17 21:12:10.001325

"""
from typing import Sequence, Union

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

# revision identifiers, used by Alembic.
revision: str = '0481276c6c83'
down_revision: Union[str, None] = '94fce2a59224'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('unique_project_email', 'ingest_user_project_csv', type_='unique')
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint('unique_project_email', 'ingest_user_project_csv', ['project_name', 'project_tag', 'first_name', 'last_name', 'email', 'buid', 'github_username'])
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Make columns nullable and add unique constraint

Revision ID: 1bba57a81eea
Revises: 0481276c6c83
Create Date: 2024-12-17 23:16:51.909305

"""
from typing import Sequence, Union

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

# revision identifiers, used by Alembic.
revision: str = '1bba57a81eea'
down_revision: Union[str, None] = '0481276c6c83'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('ingest_user_project_csv', 'email',
existing_type=sa.TEXT(),
nullable=True,
existing_server_default=sa.text("''::text"))
op.alter_column('ingest_user_project_csv', 'buid',
existing_type=sa.TEXT(),
nullable=True,
existing_server_default=sa.text("''::text"))
op.alter_column('ingest_user_project_csv', 'github_username',
existing_type=sa.TEXT(),
nullable=True,
existing_server_default=sa.text("''::text"))
op.create_index('ix_ingest_user_project_csv_unique', 'ingest_user_project_csv', [sa.text("COALESCE(project_name, '')"), sa.text("COALESCE(project_tag, '')"), sa.text("COALESCE(first_name, '')"), sa.text("COALESCE(last_name, '')"), sa.text("COALESCE(email, '')"), sa.text("COALESCE(buid, '')"), sa.text("COALESCE(github_username, '')")], unique=True)
op.create_unique_constraint('uq_ingest_user_project_csv_all_columns', 'ingest_user_project_csv', ['project_name', 'project_tag', 'first_name', 'last_name', 'email', 'buid', 'github_username'])
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('uq_ingest_user_project_csv_all_columns', 'ingest_user_project_csv', type_='unique')
op.drop_index('ix_ingest_user_project_csv_unique', table_name='ingest_user_project_csv')
op.alter_column('ingest_user_project_csv', 'github_username',
existing_type=sa.TEXT(),
nullable=False,
existing_server_default=sa.text("''::text"))
op.alter_column('ingest_user_project_csv', 'buid',
existing_type=sa.TEXT(),
nullable=False,
existing_server_default=sa.text("''::text"))
op.alter_column('ingest_user_project_csv', 'email',
existing_type=sa.TEXT(),
nullable=False,
existing_server_default=sa.text("''::text"))
# ### end Alembic commands ###
46 changes: 46 additions & 0 deletions app/alembic/versions/94fce2a59224_change_null_constraints_on_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Change null constraints on IngestuserProjectCSV

Revision ID: 94fce2a59224
Revises: b0a85b0a1488
Create Date: 2024-12-17 21:05:47.505382

"""
from typing import Sequence, Union

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

# revision identifiers, used by Alembic.
revision: str = '94fce2a59224'
down_revision: Union[str, None] = 'b0a85b0a1488'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('ingest_user_project_csv', 'email',
existing_type=sa.TEXT(),
nullable=False)
op.alter_column('ingest_user_project_csv', 'buid',
existing_type=sa.TEXT(),
nullable=False)
op.alter_column('ingest_user_project_csv', 'github_username',
existing_type=sa.TEXT(),
nullable=False)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('ingest_user_project_csv', 'github_username',
existing_type=sa.TEXT(),
nullable=True)
op.alter_column('ingest_user_project_csv', 'buid',
existing_type=sa.TEXT(),
nullable=True)
op.alter_column('ingest_user_project_csv', 'email',
existing_type=sa.TEXT(),
nullable=True)
# ### end Alembic commands ###
31 changes: 31 additions & 0 deletions app/alembic/versions/b0a85b0a1488_add_unique_constraint_to_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Add unique constraint to IngestUserProjectCSV

Revision ID: b0a85b0a1488
Revises:
Create Date: 2024-12-17 20:53:17.286467

"""
from typing import Sequence, Union

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

# revision identifiers, used by Alembic.
revision: str = 'b0a85b0a1488'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# Add the unique constraint
op.create_unique_constraint(
'unique_project_email',
'ingest_user_project_csv',
['project_name', 'project_tag', 'first_name', 'last_name', 'email', 'buid', 'github_username']
)

def downgrade() -> None:
# Remove the unique constraint
op.drop_constraint('unique_project_email', 'ingest_user_project_csv', type_='unique')
8 changes: 4 additions & 4 deletions app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# env
load_dotenv()
POSTGRES_URL = os.getenv('POSTGRES_URL')
TEST_GITHUB_PAT = os.getenv('TEST_GITHUB_PAT')
SPARK_GITHUB_PAT = os.getenv('SPARK_GITHUB_PAT')
TEST_GITHUB_PAT = os.getenv('TEST_GITHUB_PAT') or "-"
SPARK_GITHUB_PAT = os.getenv('SPARK_GITHUB_PAT') or "-"

# app
github = git.Github(SPARK_GITHUB_PAT, 'BU-Spark')
Expand Down Expand Up @@ -637,8 +637,8 @@ def change_users_project_status(project_name: str, user_github: str, status: sta
if __name__ == "__main__":
# for table in ['user', 'project', 'semester', 'user_project', 'csv']:
# dump(table)
ingest()
# projects()
#ingest()
print(len(projects()))
# information()
# get_users_in_project('Byte')
# print(process())
Loading