Skip to content

Commit

Permalink
Merge pull request #147 from cs3216-a3-group-4/seeleng/add-gh-actions…
Browse files Browse the repository at this point in the history
…-prod

ci: add github actions to deploy production branch
  • Loading branch information
seelengxd authored Oct 3, 2024
2 parents 4a722c6 + 5f20194 commit de63b2c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: deploy-prod
on:
push:
branches:
- production
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: executing remote ssh commands using password
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
script: |
export PATH="$PATH:/home/ci/.cargo/bin:/home/ci/.nvm/versions/node/v20.13.1/bin"
./deploy-jippy-prod.sh
58 changes: 58 additions & 0 deletions backend/src/scripts/transfer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""This script is used to sync staging articles/event/analysis"""

import argparse
from typing import Tuple

from sqlalchemy import Engine, create_engine, select
from sqlalchemy.orm import Session, make_transient
from src.events.models import Analysis, Article, Event


def get_engines() -> Tuple[Engine, Engine]:
parser = argparse.ArgumentParser()
parser.add_argument(
"-f", "--from-url", help="extract from this db url", required=True
)
parser.add_argument("-t", "--to-url", help="add to this db url", required=True)
args = parser.parse_args()

from_engine = create_engine(args.from_url)
to_engine = create_engine(args.to_url)
return from_engine, to_engine


def transfer_model(from_engine: Engine, to_engine: Engine, model_class):
# Select id from to engine
with Session(to_engine) as session:
ids = session.scalars(select(model_class.id)).all()

# Select models from from_engine where ids are not in to_engine
with Session(from_engine) as session:
models = session.scalars(
select(model_class).where(model_class.id.not_in(ids))
).all()

for model in models:
make_transient(model)
model.id = None

# Add to to_engine
with Session(to_engine) as session:
if models:
session.add_all(models)
session.commit()
print(f"Transferred {len(models)} {model_class}")
else:
print(f"No models to transfer for {model_class}")


def transfer():
from_engine, to_engine = get_engines()

transfer_model(from_engine, to_engine, Article)
transfer_model(from_engine, to_engine, Event)
transfer_model(from_engine, to_engine, Analysis)


if __name__ == "__main__":
transfer()

0 comments on commit de63b2c

Please sign in to comment.