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
070d9083
Commit
070d9083
authored
Jun 24, 2024
by
Jonathan Rohde
Browse files
feat(sqlalchemy): use subprocess to do migrations
parent
bee835cb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
8 deletions
+6
-8
backend/alembic.ini
backend/alembic.ini
+1
-1
backend/main.py
backend/main.py
+5
-7
No files found.
backend/alembic.ini
View file @
070d9083
...
...
@@ -58,7 +58,7 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne
# are written from script.py.mako
# output_encoding = utf-8
sqlalchemy.url
=
REPLACE_WITH_DATABASE_URL
#
sqlalchemy.url = REPLACE_WITH_DATABASE_URL
[post_write_hooks]
...
...
backend/main.py
View file @
070d9083
...
...
@@ -173,13 +173,11 @@ https://github.com/open-webui/open-webui
def
run_migrations
():
from
alembic.config
import
Config
from
alembic
import
command
alembic_cfg
=
Config
(
f
"
{
BACKEND_DIR
}
/alembic.ini"
)
alembic_cfg
.
set_main_option
(
"sqlalchemy.url"
,
DATABASE_URL
)
alembic_cfg
.
set_main_option
(
"script_location"
,
f
"
{
BACKEND_DIR
}
/migrations"
)
command
.
upgrade
(
alembic_cfg
,
"head"
)
env
=
os
.
environ
.
copy
()
env
[
"DATABASE_URL"
]
=
DATABASE_URL
migration_task
=
subprocess
.
run
([
"alembic"
,
f
"-c
{
BACKEND_DIR
}
/alembic.ini"
,
"upgrade"
,
"head"
],
env
=
env
)
if
migration_task
.
returncode
>
0
:
raise
ValueError
(
"Error running migrations"
)
@
asynccontextmanager
...
...
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