joysthadd commited on
Commit
061be31
·
verified ·
1 Parent(s): 7094b82

Upload 4 files

Browse files
Files changed (4) hide show
  1. alembic.ini +147 -0
  2. entrypoint.sh +19 -0
  3. main.py +56 -0
  4. requirements.txt +56 -0
alembic.ini ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # A generic, single database configuration.
2
+
3
+ [alembic]
4
+ # path to migration scripts.
5
+ # this is typically a path given in POSIX (e.g. forward slashes)
6
+ # format, relative to the token %(here)s which refers to the location of this
7
+ # ini file
8
+ script_location = alembic
9
+
10
+ # template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
11
+ # Uncomment the line below if you want the files to be prepended with date and time
12
+ # see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
13
+ # for all available tokens
14
+ # file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
15
+
16
+ # sys.path path, will be prepended to sys.path if present.
17
+ # defaults to the current working directory. for multiple paths, the path separator
18
+ # is defined by "path_separator" below.
19
+ prepend_sys_path = .
20
+
21
+
22
+ # timezone to use when rendering the date within the migration file
23
+ # as well as the filename.
24
+ # If specified, requires the python>=3.9 or backports.zoneinfo library and tzdata library.
25
+ # Any required deps can installed by adding `alembic[tz]` to the pip requirements
26
+ # string value is passed to ZoneInfo()
27
+ # leave blank for localtime
28
+ # timezone =
29
+
30
+ # max length of characters to apply to the "slug" field
31
+ # truncate_slug_length = 40
32
+
33
+ # set to 'true' to run the environment during
34
+ # the 'revision' command, regardless of autogenerate
35
+ # revision_environment = false
36
+
37
+ # set to 'true' to allow .pyc and .pyo files without
38
+ # a source .py file to be detected as revisions in the
39
+ # versions/ directory
40
+ # sourceless = false
41
+
42
+ # version location specification; This defaults
43
+ # to <script_location>/versions. When using multiple version
44
+ # directories, initial revisions must be specified with --version-path.
45
+ # The path separator used here should be the separator specified by "path_separator"
46
+ # below.
47
+ # version_locations = %(here)s/bar:%(here)s/bat:%(here)s/alembic/versions
48
+
49
+ # path_separator; This indicates what character is used to split lists of file
50
+ # paths, including version_locations and prepend_sys_path within configparser
51
+ # files such as alembic.ini.
52
+ # The default rendered in new alembic.ini files is "os", which uses os.pathsep
53
+ # to provide os-dependent path splitting.
54
+ #
55
+ # Note that in order to support legacy alembic.ini files, this default does NOT
56
+ # take place if path_separator is not present in alembic.ini. If this
57
+ # option is omitted entirely, fallback logic is as follows:
58
+ #
59
+ # 1. Parsing of the version_locations option falls back to using the legacy
60
+ # "version_path_separator" key, which if absent then falls back to the legacy
61
+ # behavior of splitting on spaces and/or commas.
62
+ # 2. Parsing of the prepend_sys_path option falls back to the legacy
63
+ # behavior of splitting on spaces, commas, or colons.
64
+ #
65
+ # Valid values for path_separator are:
66
+ #
67
+ # path_separator = :
68
+ # path_separator = ;
69
+ # path_separator = space
70
+ # path_separator = newline
71
+ #
72
+ # Use os.pathsep. Default configuration used for new projects.
73
+ path_separator = os
74
+
75
+ # set to 'true' to search source files recursively
76
+ # in each "version_locations" directory
77
+ # new in Alembic version 1.10
78
+ # recursive_version_locations = false
79
+
80
+ # the output encoding used when revision files
81
+ # are written from script.py.mako
82
+ # output_encoding = utf-8
83
+
84
+ # database URL. This is consumed by the user-maintained env.py script only.
85
+ # other means of configuring database URLs may be customized within the env.py
86
+ # file.
87
+ sqlalchemy.url = driver://user:pass@localhost/dbname
88
+
89
+
90
+ [post_write_hooks]
91
+ # post_write_hooks defines scripts or Python functions that are run
92
+ # on newly generated revision scripts. See the documentation for further
93
+ # detail and examples
94
+
95
+ # format using "black" - use the console_scripts runner, against the "black" entrypoint
96
+ # hooks = black
97
+ # black.type = console_scripts
98
+ # black.entrypoint = black
99
+ # black.options = -l 79 REVISION_SCRIPT_FILENAME
100
+
101
+ # lint with attempts to fix using "ruff" - use the module runner, against the "ruff" module
102
+ # hooks = ruff
103
+ # ruff.type = module
104
+ # ruff.module = ruff
105
+ # ruff.options = check --fix REVISION_SCRIPT_FILENAME
106
+
107
+ # Alternatively, use the exec runner to execute a binary found on your PATH
108
+ # hooks = ruff
109
+ # ruff.type = exec
110
+ # ruff.executable = ruff
111
+ # ruff.options = check --fix REVISION_SCRIPT_FILENAME
112
+
113
+ # Logging configuration. This is also consumed by the user-maintained
114
+ # env.py script only.
115
+ [loggers]
116
+ keys = root,sqlalchemy,alembic
117
+
118
+ [handlers]
119
+ keys = console
120
+
121
+ [formatters]
122
+ keys = generic
123
+
124
+ [logger_root]
125
+ level = WARNING
126
+ handlers = console
127
+ qualname =
128
+
129
+ [logger_sqlalchemy]
130
+ level = WARNING
131
+ handlers =
132
+ qualname = sqlalchemy.engine
133
+
134
+ [logger_alembic]
135
+ level = INFO
136
+ handlers =
137
+ qualname = alembic
138
+
139
+ [handler_console]
140
+ class = StreamHandler
141
+ args = (sys.stderr,)
142
+ level = NOTSET
143
+ formatter = generic
144
+
145
+ [formatter_generic]
146
+ format = %(levelname)-5.5s [%(name)s] %(message)s
147
+ datefmt = %H:%M:%S
entrypoint.sh ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ # Exit immediately on error
4
+ set -e
5
+
6
+ # Wait for PostgreSQL to be ready
7
+ echo "⏳ Waiting for PostgreSQL..."
8
+ while ! nc -z "$DATABASE_HOST" "$DATABASE_PORT"; do
9
+ sleep 1
10
+ done
11
+ echo "✅ PostgreSQL is ready."
12
+
13
+ # Run migrations
14
+ echo "🔄 Running migrations..."
15
+ python alembic upgrade head || true
16
+
17
+ # Start the server
18
+ echo "🚀 Starting Fastapi server..."
19
+ exec uvicorn main:app --host 0.0.0.0 --port 8001 --reload
main.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ from fastapi import FastAPI, Depends
3
+ from fastapi.responses import JSONResponse
4
+ from problemsolution.urls import api
5
+ from problemsolution.setting import settings
6
+ from fastapi_pagination import add_pagination
7
+
8
+ from fastapi_limiter import FastAPILimiter
9
+ from fastapi_limiter.depends import RateLimiter
10
+ import redis.asyncio as aioredis
11
+ from fastapi import FastAPI
12
+ from fastapi.middleware.cors import CORSMiddleware
13
+ from problemsolution.utils.exception_handler import register_error_handlers
14
+
15
+ app = FastAPI(title=settings.APP_NAME, version=settings.APP_VERSION)
16
+
17
+
18
+ origins = [
19
+ "http://127.0.0.1:8001",
20
+ "http://localhost:8001",
21
+ "https://medicalscheduler.onrender.com",
22
+ ]
23
+
24
+ app.add_middleware(
25
+ CORSMiddleware,
26
+ allow_origins=origins,
27
+ allow_credentials=True,
28
+ allow_methods=["*"],
29
+ allow_headers=["*"],
30
+ )
31
+
32
+
33
+ app.include_router(api)
34
+
35
+
36
+ @app.on_event("startup")
37
+ async def startup():
38
+ redis = await aioredis.from_url("redis://localhost", encoding="utf-8", decode_responses=True)
39
+ await FastAPILimiter.init(redis)
40
+
41
+ @app.exception_handler(Exception)
42
+ async def global_exception_handler(request, exc: Exception):
43
+ logging.error(f"Unhandled exception: {exc}", exc_info=True)
44
+ return JSONResponse(status_code=500, content={"detail": "Internal Server Error"})
45
+
46
+ register_error_handlers(app)
47
+ # Example endpoint with rate limiting
48
+ @app.get("/limited", dependencies=[Depends(RateLimiter(times=5, seconds=60))])
49
+ async def limited_endpoint():
50
+ return {"message": "This endpoint is limited to 5 requests per 60 seconds"}
51
+
52
+
53
+ async def user_identifier(request, _: str):
54
+ return request.state.user.id
55
+
56
+ add_pagination(app)
requirements.txt ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ sentence-transformers==3.0.1
2
+ alembic==1.16.4
3
+ annotated-types==0.7.0
4
+ anyio==4.10.0
5
+ async-timeout==5.0.1
6
+ asyncpg==0.30.0
7
+ bcrypt==4.3.0
8
+ certifi==2025.8.3
9
+ celery[redis]==5.5.3
10
+ charset-normalizer==3.4.3
11
+ click==8.2.1
12
+ dnspython==2.7.0
13
+ email_validator==2.2.0
14
+ fastapi==0.116.1
15
+ fastapi-limiter==0.1.6
16
+ fastapi-pagination==0.13.3
17
+ greenlet==3.2.4
18
+ grpcio==1.74.0
19
+ h11==0.16.0
20
+ h2==4.2.0
21
+ hpack==4.1.0
22
+ httpcore==1.0.9
23
+ httpx==0.28.1
24
+ hyperframe==6.1.0
25
+ idna==3.10
26
+ Mako==1.3.10
27
+ MarkupSafe==3.0.2
28
+ numpy==2.3.2
29
+ pandas==2.3.1
30
+ passlib==1.7.4
31
+ portalocker==3.2.0
32
+ protobuf==6.32.0
33
+ psycopg==3.2.9
34
+ psycopg-binary==3.2.9
35
+ pydantic==2.11.7
36
+ pydantic-settings==2.10.1
37
+ pydantic_core==2.33.2
38
+ PyJWT==2.10.1
39
+ python-dateutil==2.9.0.post0
40
+ python-decouple==3.8
41
+ python-dotenv==1.1.1
42
+ python-multipart==0.0.20
43
+ pytz==2025.2
44
+ qdrant-client==1.15.1
45
+ redis==5.2.0
46
+ requests==2.32.5
47
+ six==1.17.0
48
+ sniffio==1.3.1
49
+ SQLAlchemy==2.0.43
50
+ sseclient==0.0.27
51
+ starlette==0.47.2
52
+ typing-inspection==0.4.1
53
+ typing_extensions==4.14.1
54
+ tzdata==2025.2
55
+ urllib3==2.5.0
56
+ uvicorn==0.35.0