rebuild(stage-8): deliver market insight workspaces

This commit is contained in:
leefer
2026-07-30 04:12:04 +08:00
parent a18e8e9d27
commit 976a5cac03
39 changed files with 3671 additions and 14 deletions
@@ -0,0 +1,49 @@
from __future__ import annotations
import sqlite3
from backend.database.migrations.runner import Migration
def upgrade(connection: sqlite3.Connection) -> None:
connection.execute(
"""
CREATE TABLE market_insight_snapshots (
kind TEXT NOT NULL CHECK (
kind IN ('auction', 'themes', 'popularity', 'dragon-list')
),
trade_date TEXT NOT NULL,
entity_key TEXT NOT NULL DEFAULT '',
observed_at TEXT NOT NULL,
state TEXT NOT NULL CHECK (state IN ('realtime', 'final', 'archive')),
source TEXT NOT NULL,
coverage REAL NOT NULL CHECK (coverage >= 0 AND coverage <= 1),
payload_json TEXT NOT NULL,
PRIMARY KEY (kind, trade_date, entity_key)
)
"""
)
connection.execute(
"""
CREATE TABLE seat_aliases (
seat_name TEXT PRIMARY KEY,
alias_name TEXT NOT NULL,
updated_at TEXT NOT NULL,
updated_by INTEGER REFERENCES users(id) ON DELETE SET NULL
)
"""
)
def downgrade(connection: sqlite3.Connection) -> None:
connection.execute("DROP TABLE seat_aliases")
connection.execute("DROP TABLE market_insight_snapshots")
MIGRATION = Migration(
version=5,
name="create_market_insight_archives",
signature="market:v3:auction-themes-popularity-dragon-list",
upgrade=upgrade,
downgrade=downgrade,
)
@@ -0,0 +1,33 @@
from __future__ import annotations
import sqlite3
from backend.database.migrations.runner import Migration
def upgrade(connection: sqlite3.Connection) -> None:
connection.execute(
"""
CREATE TABLE watchlist_entries (
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
identifier TEXT NOT NULL,
name TEXT NOT NULL,
sector TEXT,
created_at TEXT NOT NULL,
PRIMARY KEY (user_id, identifier)
)
"""
)
def downgrade(connection: sqlite3.Connection) -> None:
connection.execute("DROP TABLE watchlist_entries")
MIGRATION = Migration(
version=6,
name="create_account_watchlists",
signature="accounts:v2:isolated-watchlist-entries",
upgrade=upgrade,
downgrade=downgrade,
)
+10 -1
View File
@@ -2,6 +2,15 @@ from backend.database.migrations.m0001_accounts import MIGRATION as ACCOUNTS
from backend.database.migrations.m0002_model_pool import MIGRATION as MODEL_POOL
from backend.database.migrations.m0003_market_foundation import MIGRATION as MARKET_FOUNDATION
from backend.database.migrations.m0004_sector_members import MIGRATION as SECTOR_MEMBERS
from backend.database.migrations.m0005_market_insights import MIGRATION as MARKET_INSIGHTS
from backend.database.migrations.m0006_watchlists import MIGRATION as WATCHLISTS
from backend.database.migrations.runner import Migration
MIGRATIONS: tuple[Migration, ...] = (ACCOUNTS, MODEL_POOL, MARKET_FOUNDATION, SECTOR_MEMBERS)
MIGRATIONS: tuple[Migration, ...] = (
ACCOUNTS,
MODEL_POOL,
MARKET_FOUNDATION,
SECTOR_MEMBERS,
MARKET_INSIGHTS,
WATCHLISTS,
)