Update models on pc run --no-frontend (#516)
This commit is contained in:
parent
1479411c4f
commit
d3c3174ba4
@ -12,7 +12,6 @@ from pynecone.compiler import utils as compiler_utils
|
||||
from pynecone.components.component import Component, ComponentStyle
|
||||
from pynecone.event import Event, EventHandler
|
||||
from pynecone.middleware import HydrateMiddleware, Middleware
|
||||
from pynecone.model import Model
|
||||
from pynecone.state import DefaultState, Delta, State, StateManager, StateUpdate
|
||||
|
||||
# Define custom types.
|
||||
@ -313,10 +312,6 @@ class App(Base):
|
||||
print("Skipping compilation in non-dev mode.")
|
||||
return
|
||||
|
||||
# Create the database models.
|
||||
if config.db_url is not None:
|
||||
Model.create_all()
|
||||
|
||||
# Empty the .web pages directory
|
||||
compiler.purge_web_pages_dir()
|
||||
|
||||
|
@ -49,6 +49,7 @@ if TYPE_CHECKING:
|
||||
from pynecone.components.component import ImportDict
|
||||
from pynecone.config import Config
|
||||
from pynecone.event import Event, EventHandler, EventSpec
|
||||
from pynecone.model import Model
|
||||
from pynecone.var import Var
|
||||
|
||||
# Shorthand for join.
|
||||
@ -714,6 +715,15 @@ def change_or_terminate_port(port, _type) -> str:
|
||||
sys.exit()
|
||||
|
||||
|
||||
def setup_backend():
|
||||
"""Sets up backend. Specifically ensures backend
|
||||
database is updated when running --no-frontend.
|
||||
"""
|
||||
config = get_config()
|
||||
if config.db_url is not None:
|
||||
Model.create_all()
|
||||
|
||||
|
||||
def run_backend(
|
||||
app_name: str, port: int, loglevel: constants.LogLevel = constants.LogLevel.ERROR
|
||||
):
|
||||
@ -724,6 +734,8 @@ def run_backend(
|
||||
port: The app port
|
||||
loglevel: The log level.
|
||||
"""
|
||||
setup_backend()
|
||||
|
||||
uvicorn.run(
|
||||
f"{app_name}:{constants.APP_VAR}.{constants.API_VAR}",
|
||||
host=constants.BACKEND_HOST,
|
||||
@ -743,6 +755,8 @@ def run_backend_prod(
|
||||
port: The app port
|
||||
loglevel: The log level.
|
||||
"""
|
||||
setup_backend()
|
||||
|
||||
num_workers = get_num_workers()
|
||||
command = constants.RUN_BACKEND_PROD + [
|
||||
"--bind",
|
||||
|
Loading…
Reference in New Issue
Block a user