revert: app/ → site/ (drhider proves site/ works fine)
This commit is contained in:
+64
@@ -0,0 +1,64 @@
|
||||
"""contracts-flask v2.0 — полный перенос с ВМ на Flask.
|
||||
Больше никаких прокси на contracts.kube5s.ru — всё локально.
|
||||
"""
|
||||
from flask import Flask
|
||||
from site.config import VERSION, MAX_CONTENT_LENGTH
|
||||
from site.routes import register_routes
|
||||
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
app.config["VERSION"] = VERSION
|
||||
app.config["MAX_CONTENT_LENGTH"] = MAX_CONTENT_LENGTH
|
||||
|
||||
# DB auto-seed — schema migration + seed prompts + crash recovery
|
||||
_init_db()
|
||||
|
||||
# Регистрация всех blueprint'ов
|
||||
register_routes(app)
|
||||
|
||||
# no_cache на все ответы
|
||||
@app.after_request
|
||||
def no_cache(response):
|
||||
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
|
||||
response.headers["Pragma"] = "no-cache"
|
||||
response.headers["Expires"] = "0"
|
||||
return response
|
||||
|
||||
return app
|
||||
|
||||
|
||||
def _init_db():
|
||||
"""Schema migration + recovery: сброс застрявших classify."""
|
||||
try:
|
||||
from site.db.connection import execute
|
||||
|
||||
for sql in [
|
||||
"ALTER TABLE documents ADD COLUMN IF NOT EXISTS classify_raw text",
|
||||
"ALTER TABLE documents ADD COLUMN IF NOT EXISTS classify_input text",
|
||||
"ALTER TABLE documents ADD COLUMN IF NOT EXISTS zip_source text",
|
||||
"ALTER TABLE documents ADD COLUMN IF NOT EXISTS content_hash text",
|
||||
"ALTER TABLE documents ADD COLUMN IF NOT EXISTS batch_id uuid",
|
||||
"ALTER TABLE documents ADD COLUMN IF NOT EXISTS classify_status text DEFAULT 'pending'",
|
||||
"ALTER TABLE documents ALTER COLUMN classify_status SET DEFAULT 'pending'",
|
||||
"ALTER TABLE documents ADD COLUMN IF NOT EXISTS doc_type text",
|
||||
"ALTER TABLE documents ADD COLUMN IF NOT EXISTS own_number text",
|
||||
"ALTER TABLE documents ADD COLUMN IF NOT EXISTS parent_number text",
|
||||
"ALTER TABLE documents ADD COLUMN IF NOT EXISTS doc_date date",
|
||||
"ALTER TABLE documents ADD COLUMN IF NOT EXISTS counterparty text",
|
||||
]:
|
||||
execute(sql)
|
||||
|
||||
from site.db import prompts as db_prompts
|
||||
db_prompts.seed_defaults()
|
||||
|
||||
# Crash recovery: сбросить застрявшие classify
|
||||
execute(
|
||||
"UPDATE documents SET classify_status='pending', error_message=NULL "
|
||||
"WHERE classify_status='processing'"
|
||||
)
|
||||
except Exception:
|
||||
pass # БД недоступна при старте — не фатально
|
||||
|
||||
|
||||
app = create_app()
|
||||
Reference in New Issue
Block a user