Skip to content

Commit ad71550

Browse files
AkhileshNegisourabhlodhasourabhlodhaavirajsingh7nishika26
authored
Migration PR: Staging to main (#86)
* Update README.md (#44) * changes (#45) Co-authored-by: sourabhlodha <sourabhlodha@Administrators-MacBook-Pro.local> * Readme update (#47) rename project and stack --------- Co-authored-by: sourabhlodha <sourabhlodha@Administrators-MacBook-Pro.local> * fix create_user endpoint (#62) * standard api response and http exception handling (#67) * Upgrade PostgreSQL to 16 & Fix CORS Configuration (#57) * use latest docker image * update envsample * Add Customizable Token Expiry Time in Login API (#70) * token expiry time can be customize * default to one day * Organization/project : Crud, Endpoint and Test Cases (#63) * trial * pushing all * models file * renaming * Rename Project.py to project.py * Rename oganization.py to organization.py * Update README.md (#44) * changes (#45) Co-authored-by: sourabhlodha <sourabhlodha@Administrators-MacBook-Pro.local> * Readme update (#47) rename project and stack --------- Co-authored-by: sourabhlodha <sourabhlodha@Administrators-MacBook-Pro.local> * fix create_user endpoint (#62) * standard api response and http exception handling (#67) * standardization and edits * small edits * small edits * small edits * fixed project post * trial * pushing all * models file * renaming * Rename Project.py to project.py * Rename oganization.py to organization.py * standardization and edits * small edits * small edits * small edits * fixed project post * remove these files since they were somehow pushed into this branch * re-push the docker file * re-push utils file * re-push the file * fixing test cases --------- Co-authored-by: Sourabh Lodha <sourabh_lodha@ymail.com> Co-authored-by: sourabhlodha <sourabhlodha@Administrators-MacBook-Pro.local> Co-authored-by: Aviraj Gour <100823015+avirajsingh7@users.noreply.github.com> Co-authored-by: Ishankoradia <ikoradia@umich.edu> * Add Project User Management (#65) * intial commit user project mapping and authorization * fix alembic migration * Use standard API response * add pagination * add index and use base model * Alembic: migration fixes for organization (#77) * fixing testcases and migrations * changes migration file name * remove old migration --------- Co-authored-by: Akhilesh Negi <akhileshnegi.an3@gmail.com> * Added Support of API Key Authentication (#76) * Intial setup api key * added Api key auth flow * support both api key and oauth --------- Co-authored-by: Sourabh Lodha <sourabh_lodha@ymail.com> * Main to stage code sync (#80) Back merge Production to staging code * added migration for api table (#81) --------- Co-authored-by: Sourabh Lodha <sourabh_lodha@ymail.com> Co-authored-by: sourabhlodha <sourabhlodha@Administrators-MacBook-Pro.local> Co-authored-by: Aviraj Gour <100823015+avirajsingh7@users.noreply.github.com> Co-authored-by: Nishika Yadav <89646695+nishika26@users.noreply.github.com> Co-authored-by: Ishankoradia <ikoradia@umich.edu>
1 parent 4e28bd1 commit ad71550

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2184
-61
lines changed
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
11
# Domain
2+
23
# This would be set to the production domain with an env var on deployment
4+
35
# used by Traefik to transmit traffic and aqcuire TLS certificates
6+
47
DOMAIN=localhost
8+
59
# To test the local Traefik config
10+
611
# DOMAIN=localhost.tiangolo.com
712

813
# Used by the backend to generate links in emails to the frontend
14+
915
FRONTEND_HOST=http://localhost:5173
16+
1017
# In staging and production, set this env var to the frontend host, e.g.
18+
1119
# FRONTEND_HOST=https://dashboard.example.com
1220

1321
# Environment: local, staging, production
22+
1423
ENVIRONMENT=local
1524

1625

1726
PROJECT_NAME="AI Platform"
1827
STACK_NAME=ai-platform
1928

2029
# Backend
21-
BACKEND_CORS_ORIGINS="http://localhost"
30+
31+
BACKEND_CORS_ORIGINS="http://localhost:5173"
2232
SECRET_KEY=changethis
2333
FIRST_SUPERUSER=admin@example.com
2434
FIRST_SUPERUSER_PASSWORD=changethis
2535

2636
# Emails
37+
2738
SMTP_HOST=
2839
SMTP_USER=
2940
SMTP_PASSWORD=
@@ -33,14 +44,19 @@ SMTP_SSL=False
3344
SMTP_PORT=587
3445

3546
# Postgres
47+
3648
POSTGRES_SERVER=localhost
3749
POSTGRES_PORT=5432
38-
POSTGRES_DB=app
50+
POSTGRES_DB=ai_platform
3951
POSTGRES_USER=postgres
40-
POSTGRES_PASSWORD=changethis
52+
POSTGRES_PASSWORD=postgres
4153

4254
SENTRY_DSN=
4355

4456
# Configure these with your own Docker registry images
57+
4558
DOCKER_IMAGE_BACKEND=backend
46-
DOCKER_IMAGE_FRONTEND=frontend
59+
DOCKER_IMAGE_FRONTEND=frontend
60+
61+
CI=""
62+
OPENAI_API_KEY="this_is_not_a_secret"

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
## Summary
22

33
Target issue is #_PLEASE_TYPE_ISSUE_NUMBER_
4-
Explain the **motivation** for making this change. What existing problem does the pull request solve?
4+
Explain the **motivation** for making this change. What existing problem does the pull request solve?
55

66
## Checklist
77

88
Before submitting a pull request, please ensure that you mark these task.
99

10-
- [ ] Ran `poetry run uvicorn src.app.main:app --reload` in the repository root and test.
10+
- [ ] Ran `fastapi run --reload app/main.py` or `docker compose up` in the repository root and test.
1111
- [ ] If you've fixed a bug or added code that is tested and has test cases.
1212

1313
## Notes
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: AI Platform CI
2+
3+
on:
4+
push:
5+
branches: [staging]
6+
pull_request:
7+
branches: [staging]
8+
9+
jobs:
10+
checks:
11+
runs-on: ubuntu-latest
12+
services:
13+
postgres:
14+
image: postgres:16
15+
env:
16+
POSTGRES_USER: postgres
17+
POSTGRES_PASSWORD: postgres
18+
POSTGRES_DB: ai_platform
19+
ports:
20+
- 5432:5432
21+
options: --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5
22+
23+
strategy:
24+
matrix:
25+
python-version: ["3.11.7"]
26+
redis-version: [6]
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Set up Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@v4
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
36+
- name: Making env file
37+
run: cp .env.example .env
38+
39+
- name: Install uv
40+
uses: astral-sh/setup-uv@v5
41+
with:
42+
version: "0.4.15"
43+
enable-cache: true
44+
45+
- name: Install dependencies
46+
run: uv sync
47+
working-directory: backend
48+
49+
- name: Activate virtual environment and run Alembic migrations
50+
run: |
51+
source .venv/bin/activate
52+
alembic upgrade head
53+
working-directory: backend
54+
55+
- name: Run tests
56+
run: uv run bash scripts/tests-start.sh "Coverage for ${{ github.sha }}"
57+
working-directory: backend
58+
59+
- name: Upload coverage reports to codecov
60+
uses: codecov/codecov-action@v5
61+
with:
62+
token: ${{ secrets.CODECOV_TOKEN }}
63+
fail_ci_if_error: true
64+
65+
- name: Check coverage percentage
66+
run: |
67+
source .venv/bin/activate
68+
coverage report --fail-under=70
69+
working-directory: backend

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# AI Platform
22

3+
[![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
4+
![](https://github.com/ProjectTech4DevAI/ai-platform/workflows/Continuous%20Integration/badge.svg)
5+
[![Code coverage badge](https://img.shields.io/codecov/c/github/ProjectTech4DevAI/ai-platform/staging.svg)](https://codecov.io/gh/ProjectTech4DevAI/ai-platform/branch/staging)
6+
![GitHub issues](https://img.shields.io/github/issues-raw/ProjectTech4DevAI/ai-platform)
7+
[![codebeat badge](https://codebeat.co/badges/dd951390-5f51-4c98-bddc-0b618bdb43fd)](https://codebeat.co/projects/github-com-ProjectTech4DevAI/ai-platform-staging)
8+
[![Commits](https://img.shields.io/github/commit-activity/m/ProjectTech4DevAI/ai-platform)](https://img.shields.io/github/commit-activity/m/ProjectTech4DevAI/ai-platform)
9+
310
## Pre-requisites
411

512
- [docker](https://docs.docker.com/get-started/get-docker/) Docker
@@ -16,7 +23,7 @@ You can **just fork or clone** this repository and use it as is.
1623
Create env file using example file
1724

1825
```bash
19-
cp envSample .env
26+
cp .env.example .env
2027
```
2128

2229
You can then update configs in the `.env` files to customize your configurations.
@@ -26,7 +33,8 @@ Before deploying it, make sure you change at least the values for:
2633
- `SECRET_KEY`
2734
- `FIRST_SUPERUSER_PASSWORD`
2835
- `POSTGRES_PASSWORD`
29-
```bash
36+
37+
````bash
3038

3139
### Generate Secret Keys
3240

@@ -36,7 +44,7 @@ You have to change them with a secret key, to generate secret keys you can run t
3644

3745
```bash
3846
python -c "import secrets; print(secrets.token_urlsafe(32))"
39-
```
47+
````
4048
4149
Copy the content and use that as password / secret key. And run that again to generate another secure key.
4250
@@ -62,7 +70,6 @@ or by visiting: http://[your-domain]:8000/api/v1/utils/health-check/ in the brow
6270

6371
Backend docs: [backend/README.md](./backend/README.md).
6472

65-
6673
## Deployment
6774

6875
Deployment docs: [deployment.md](./deployment.md).

backend/app/alembic/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from logging.config import fileConfig
33

44
from alembic import context
5-
from sqlmodel import SQLModel
5+
from app.models import SQLModel
66
from sqlalchemy import engine_from_config, pool
77

88
# this is the Alembic Config object, which provides
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""add api key table
2+
3+
Revision ID: 0f205e3779ee
4+
Revises: 99f4fc325617
5+
Create Date: 2025-03-21 23:43:34.181704
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
import sqlmodel.sql.sqltypes
11+
12+
13+
# revision identifiers, used by Alembic.
14+
revision = '0f205e3779ee'
15+
down_revision = '99f4fc325617'
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.create_table('apikey',
23+
sa.Column('organization_id', sa.Integer(), nullable=False),
24+
sa.Column('user_id', sa.Uuid(), nullable=False),
25+
sa.Column('key', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
26+
sa.Column('id', sa.Integer(), nullable=False),
27+
sa.Column('created_at', sa.DateTime(), nullable=False),
28+
sa.Column('is_deleted', sa.Boolean(), nullable=False),
29+
sa.Column('deleted_at', sa.DateTime(), nullable=True),
30+
sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ondelete='CASCADE'),
31+
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE'),
32+
sa.PrimaryKeyConstraint('id')
33+
)
34+
op.create_index(op.f('ix_apikey_key'), 'apikey', ['key'], unique=True)
35+
# ### end Alembic commands ###
36+
37+
38+
def downgrade():
39+
# ### commands auto generated by Alembic - please adjust! ###
40+
op.drop_index(op.f('ix_apikey_key'), table_name='apikey')
41+
op.drop_table('apikey')
42+
# ### end Alembic commands ###
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""add organization project setup
2+
3+
Revision ID: 99f4fc325617
4+
Revises: 1a31ce608336
5+
Create Date: 2025-03-21 20:51:00.759926
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
import sqlmodel.sql.sqltypes
11+
12+
13+
# revision identifiers, used by Alembic.
14+
revision = '99f4fc325617'
15+
down_revision = '1a31ce608336'
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.create_table('organization',
23+
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
24+
sa.Column('is_active', sa.Boolean(), nullable=False),
25+
sa.Column('id', sa.Integer(), nullable=False),
26+
sa.PrimaryKeyConstraint('id')
27+
)
28+
op.create_index(op.f('ix_organization_name'), 'organization', ['name'], unique=True)
29+
op.create_table('project',
30+
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
31+
sa.Column('description', sqlmodel.sql.sqltypes.AutoString(length=500), nullable=True),
32+
sa.Column('is_active', sa.Boolean(), nullable=False),
33+
sa.Column('id', sa.Integer(), nullable=False),
34+
sa.Column('organization_id', sa.Integer(), nullable=False),
35+
sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ),
36+
sa.PrimaryKeyConstraint('id')
37+
)
38+
op.create_index(op.f('ix_project_name'), 'project', ['name'], unique=False)
39+
op.create_index(op.f('ix_project_organization_id'), 'project', ['organization_id'], unique=False)
40+
op.create_table('projectuser',
41+
sa.Column('project_id', sa.Integer(), nullable=False),
42+
sa.Column('user_id', sa.Uuid(), nullable=False),
43+
sa.Column('is_admin', sa.Boolean(), nullable=False),
44+
sa.Column('id', sa.Integer(), nullable=False),
45+
sa.Column('created_at', sa.DateTime(), nullable=False),
46+
sa.Column('updated_at', sa.DateTime(), nullable=False),
47+
sa.Column('is_deleted', sa.Boolean(), nullable=False),
48+
sa.Column('deleted_at', sa.DateTime(), nullable=True),
49+
sa.ForeignKeyConstraint(['project_id'], ['project.id'], ondelete='CASCADE'),
50+
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE'),
51+
sa.PrimaryKeyConstraint('id')
52+
)
53+
# ### end Alembic commands ###
54+
55+
56+
def downgrade():
57+
# ### commands auto generated by Alembic - please adjust! ###
58+
op.drop_table('projectuser')
59+
op.drop_index(op.f('ix_project_organization_id'), table_name='project')
60+
op.drop_index(op.f('ix_project_name'), table_name='project')
61+
op.drop_table('project')
62+
op.drop_index(op.f('ix_organization_name'), table_name='organization')
63+
op.drop_table('organization')
64+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)