Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
ci(github): fix migration & deploy jobs (#143)
Browse files Browse the repository at this point in the history
* ci(github): update deploy job

* fix(alembic): update migration scripts

* ci(gthub): fix migration job
  • Loading branch information
frgfm authored Mar 29, 2024
1 parent 4e3bc36 commit c7fea64
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,20 @@ jobs:
username: ${{ secrets.SSH_DEV_USERNAME }}
key: ${{ secrets.SSH_DEPLOY_DEV }}
script: |
cd devops
# Ensure we have max disk space
docker rm -fv $(docker ps -aq)
docker rmi -f $(docker images -f "dangling=true" -q)
docker volume rm -f $(docker volume ls -f "dangling=true" -q)
# Update the service
docker compose pull backend gradio
docker compose stop backend gradio && docker compose up -d --wait && docker compose exec backend alembic upgrade head
# Check update
docker inspect -f '{{ .Created }}' $(docker compose images -q backend)
docker inspect -f '{{ .Created }}' $(docker compose images -q gradio)
# Clean up
docker rm -fv $(docker ps -aq)
docker rmi -f $(docker images -f "dangling=true" -q)
docker volume rm -f $(docker volume ls -f "dangling=true" -q)
- name: Ping server
env:
DEV_ENDPOINT: ${{ secrets.DEV_ENDPOINT }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ jobs:
GH_OAUTH_SECRET: ${{ secrets.GH_OAUTH_SECRET }}
OLLAMA_MODEL: tinydolphin:1.1b-v2.8-q3_K_M
run: |
docker compose -f docker-compose.dev.yml up -d --build --wait
docker compose -f docker-compose.dev.yml up -d --build
sleep 20
docker compose -f docker-compose.dev.yml logs backend
docker compose -f docker-compose.dev.yml up -d --wait
# debug
docker compose -f docker-compose.dev.yml exec -T backend alembic current
docker compose -f docker-compose.dev.yml exec -T backend alembic history --verbose
Expand Down
5 changes: 3 additions & 2 deletions src/alembic/versions/2023-11-07-15-35_eb1a6567456c.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
from sqlalchemy.sql import text

# revision identifiers, used by Alembic.
revision = "eb1a6567456c"
Expand All @@ -26,7 +27,7 @@ def upgrade():
session = sa.orm.Session(bind=bind)
try:
# Update is_active to True where removed_at is NULL
session.execute("UPDATE repository SET is_active = (removed_at IS NULL)")
session.execute(text("UPDATE repository SET is_active = (removed_at IS NULL)"))
session.commit()
finally:
session.close()
Expand All @@ -46,7 +47,7 @@ def downgrade():
# Set removed_at to a specific time where is_active is False
# You may choose to leave it as NULL or set it to a specific timestamp
session.execute(
"UPDATE repository SET removed_at = CASE WHEN is_active = false THEN CURRENT_TIMESTAMP ELSE NULL END"
text("UPDATE repository SET removed_at = CASE WHEN is_active = false THEN CURRENT_TIMESTAMP ELSE NULL END")
)
session.commit()
finally:
Expand Down
8 changes: 5 additions & 3 deletions src/alembic/versions/2024-02-23-11-56_4c08af871a9e.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import sqlalchemy as sa
from alembic import op
from sqlalchemy.sql import func
from sqlalchemy.sql import func, text

# import sqlalchemy_utils
# import sqlmodel # added
Expand Down Expand Up @@ -42,7 +42,8 @@ def upgrade():
op.add_column("guideline", sa.Column("creator_id", sa.Integer(), nullable=True))
# Enforce the foreign key after initializing it
op.execute(
"""
text(
"""
DO $$
DECLARE
first_user_id INT;
Expand All @@ -56,6 +57,7 @@ def upgrade():
END IF;
END $$;
"""
)
)
op.drop_column("guideline", "repo_id")
op.drop_column("guideline", "title")
Expand All @@ -79,7 +81,7 @@ def downgrade():
op.add_column("repository", sa.Column("is_active", sa.Boolean(), nullable=False))
op.add_column("repository", sa.Column("installed_by", sa.Integer(), nullable=False))
# User table modifications
op.execute('DELETE FROM "user" WHERE provider_user_id IS NULL')
op.execute(text('DELETE FROM "user" WHERE provider_user_id IS NULL'))
op.drop_column("user", "created_at")
op.alter_column("user", "login", nullable=False)
op.alter_column("user", "hashed_password", nullable=False)
Expand Down

0 comments on commit c7fea64

Please sign in to comment.