mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-09 02:54:37 +00:00
fixes
This commit is contained in:
+21
-9
@@ -1,20 +1,30 @@
|
||||
import asyncio
|
||||
from logging.config import fileConfig
|
||||
from sqlalchemy import pool
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from alembic import context
|
||||
from sqlmodel import SQLModel
|
||||
import importlib.util
|
||||
import pathlib
|
||||
from logging.config import fileConfig
|
||||
|
||||
db_path = pathlib.Path(__file__).resolve().parents[1] / "router" / "db.py"
|
||||
spec = importlib.util.spec_from_file_location("db", db_path)
|
||||
from alembic import context
|
||||
from sqlalchemy import pool
|
||||
from sqlalchemy.engine import Connection
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from sqlmodel import SQLModel
|
||||
|
||||
db_path = pathlib.Path(__file__).resolve().parents[1] / "router" / "core" / "db.py"
|
||||
spec = importlib.util.spec_from_file_location("core.db", db_path)
|
||||
if spec is None:
|
||||
raise ImportError(f"Could not load spec from {db_path}")
|
||||
db = importlib.util.module_from_spec(spec)
|
||||
if db is None:
|
||||
raise ImportError(f"Could not load module from {db_path}")
|
||||
if spec.loader is None:
|
||||
raise ImportError(f"Spec loader is None for {db_path}")
|
||||
spec.loader.exec_module(db)
|
||||
|
||||
DATABASE_URL = getattr(db, "DATABASE_URL", "sqlite+aiosqlite:///keys.db")
|
||||
|
||||
config = context.config
|
||||
if config.config_file_name is None:
|
||||
raise ValueError("config_file_name is None")
|
||||
fileConfig(config.config_file_name)
|
||||
config.set_main_option("sqlalchemy.url", DATABASE_URL)
|
||||
|
||||
@@ -33,8 +43,10 @@ def run_migrations_offline() -> None:
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def do_run_migrations(connection):
|
||||
context.configure(connection=connection, target_metadata=target_metadata, compare_type=True)
|
||||
def do_run_migrations(connection: Connection) -> None:
|
||||
context.configure(
|
||||
connection=connection, target_metadata=target_metadata, compare_type=True
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
<%text># -*- coding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
"""
|
||||
</%text>
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
${imports if imports else ""}
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = ${repr(up_revision)}
|
||||
down_revision = ${repr(down_revision)}
|
||||
branch_labels = ${repr(branch_labels)}
|
||||
depends_on = ${repr(depends_on)}
|
||||
|
||||
def upgrade():
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
"""create api keys table
|
||||
|
||||
Revision ID: 8eaf6006fa28
|
||||
Revises:
|
||||
Create Date: 2025-06-06 13:47:00.000000
|
||||
"""
|
||||
revision = "8eaf6006fa28"
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"api_keys",
|
||||
sa.Column("hashed_key", sa.String(), primary_key=True, nullable=False),
|
||||
sa.Column("balance", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("refund_address", sa.String(), nullable=True),
|
||||
sa.Column("key_expiry_time", sa.Integer(), nullable=True),
|
||||
sa.Column("total_spent", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("total_requests", sa.Integer(), nullable=False, server_default="0"),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("api_keys")
|
||||
Reference in New Issue
Block a user