Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
d3ef3a74
Commit
d3ef3a74
authored
Jul 08, 2024
by
Timothy J. Baek
Browse files
refac
parent
68d775e1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
12 deletions
+6
-12
backend/apps/webui/internal/db.py
backend/apps/webui/internal/db.py
+6
-4
backend/apps/webui/models/chats.py
backend/apps/webui/models/chats.py
+0
-2
backend/migrations/env.py
backend/migrations/env.py
+0
-6
No files found.
backend/apps/webui/internal/db.py
View file @
d3ef3a74
...
@@ -53,9 +53,12 @@ else:
...
@@ -53,9 +53,12 @@ else:
# Workaround to handle the peewee migration
# Workaround to handle the peewee migration
# This is required to ensure the peewee migration is handled before the alembic migration
# This is required to ensure the peewee migration is handled before the alembic migration
def
handle_peewee_migration
():
def
handle_peewee_migration
(
DATABASE_URL
):
try
:
try
:
db
=
register_connection
(
DATABASE_URL
)
# Replace the postgresql:// with postgres:// and %40 with @ in the DATABASE_URL
db
=
register_connection
(
DATABASE_URL
.
replace
(
"postgresql://"
,
"postgres://"
).
replace
(
"%40"
,
"@"
)
)
migrate_dir
=
BACKEND_DIR
/
"apps"
/
"webui"
/
"internal"
/
"migrations"
migrate_dir
=
BACKEND_DIR
/
"apps"
/
"webui"
/
"internal"
/
"migrations"
router
=
Router
(
db
,
logger
=
log
,
migrate_dir
=
migrate_dir
)
router
=
Router
(
db
,
logger
=
log
,
migrate_dir
=
migrate_dir
)
router
.
run
()
router
.
run
()
...
@@ -76,11 +79,10 @@ def handle_peewee_migration():
...
@@ -76,11 +79,10 @@ def handle_peewee_migration():
assert
db
.
is_closed
(),
"Database connection is still open."
assert
db
.
is_closed
(),
"Database connection is still open."
handle_peewee_migration
()
handle_peewee_migration
(
DATABASE_URL
)
SQLALCHEMY_DATABASE_URL
=
DATABASE_URL
SQLALCHEMY_DATABASE_URL
=
DATABASE_URL
if
"sqlite"
in
SQLALCHEMY_DATABASE_URL
:
if
"sqlite"
in
SQLALCHEMY_DATABASE_URL
:
engine
=
create_engine
(
engine
=
create_engine
(
SQLALCHEMY_DATABASE_URL
,
connect_args
=
{
"check_same_thread"
:
False
}
SQLALCHEMY_DATABASE_URL
,
connect_args
=
{
"check_same_thread"
:
False
}
...
...
backend/apps/webui/models/chats.py
View file @
d3ef3a74
...
@@ -248,9 +248,7 @@ class ChatTable:
...
@@ -248,9 +248,7 @@ class ChatTable:
def
get_chat_list_by_chat_ids
(
def
get_chat_list_by_chat_ids
(
self
,
chat_ids
:
List
[
str
],
skip
:
int
=
0
,
limit
:
int
=
50
self
,
chat_ids
:
List
[
str
],
skip
:
int
=
0
,
limit
:
int
=
50
)
->
List
[
ChatModel
]:
)
->
List
[
ChatModel
]:
with
get_db
()
as
db
:
with
get_db
()
as
db
:
all_chats
=
(
all_chats
=
(
db
.
query
(
Chat
)
db
.
query
(
Chat
)
.
filter
(
Chat
.
id
.
in_
(
chat_ids
))
.
filter
(
Chat
.
id
.
in_
(
chat_ids
))
...
...
backend/migrations/env.py
View file @
d3ef3a74
...
@@ -41,17 +41,11 @@ target_metadata = Auth.metadata
...
@@ -41,17 +41,11 @@ target_metadata = Auth.metadata
# ... etc.
# ... etc.
DB_URL
=
DATABASE_URL
DB_URL
=
DATABASE_URL
# Replace the postgres:// with postgresql://
if
"postgres://"
in
DB_URL
:
DB_URL
=
DB_URL
.
replace
(
"postgres://"
,
"postgresql://"
)
if
DB_URL
:
if
DB_URL
:
config
.
set_main_option
(
"sqlalchemy.url"
,
DB_URL
)
config
.
set_main_option
(
"sqlalchemy.url"
,
DB_URL
)
print
(
"DB_URL"
,
DB_URL
)
def
run_migrations_offline
()
->
None
:
def
run_migrations_offline
()
->
None
:
"""Run migrations in 'offline' mode.
"""Run migrations in 'offline' mode.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment