[V0.5] Working application with all 4 screens as of yet.

This commit is contained in:
c-d-p
2025-04-26 13:23:45 +02:00
parent 22a4fc50a5
commit 04d9136b96
15 changed files with 154 additions and 29 deletions

View File

@@ -4,6 +4,7 @@ from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from sqlalchemy import create_engine # Add create_engine import
from alembic import context
@@ -25,6 +26,29 @@ config = context.config
if config.config_file_name is not None:
fileConfig(config.config_file_name)
# --- Construct DB URL from environment variables ---
# Use environment variables similar to docker-compose
db_user = os.getenv("POSTGRES_USER", "maia") # Default to 'maia' if not set
db_password = os.getenv("POSTGRES_PASSWORD", "maia") # Default to 'maia' if not set
db_host = os.getenv("DB_HOST", "db") # Default to 'db' service name
db_port = os.getenv("DB_PORT", "5432") # Default to '5432'
db_name = os.getenv("DB_NAME", "maia") # Default to 'maia'
# Construct the URL, falling back to alembic.ini if needed
url = os.getenv("DB_URL")
if not url:
# Try constructing from parts if DB_URL isn't set
url = f"postgresql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}"
# As a final fallback, use the URL from alembic.ini
config_url = config.get_main_option("sqlalchemy.url")
if not url and config_url:
url = config_url
# Update the config object so engine_from_config can potentially use it,
# though we'll primarily use the constructed 'url' directly.
config.set_main_option("sqlalchemy.url", url)
# ----------------------------------------------------
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
@@ -51,9 +75,8 @@ def run_migrations_offline() -> None:
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
url=url, # Use the constructed URL
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
@@ -70,11 +93,14 @@ def run_migrations_online() -> None:
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
# Create engine directly using the constructed URL
connectable = create_engine(url, poolclass=pool.NullPool)
# Original approach using engine_from_config:
# connectable = engine_from_config(
# config.get_section(config.config_ini_section, {}),
# prefix="sqlalchemy.",
# poolclass=pool.NullPool,
# )
with connectable.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata)

View File

@@ -0,0 +1,94 @@
"""Add all_day column to calendar_events
Revision ID: a34d847510da
Revises: 9a82960db482
Create Date: 2025-04-26 11:09:35.400748
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = 'a34d847510da'
down_revision: Union[str, None] = '9a82960db482'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('calendar_events')
op.drop_table('users')
op.drop_index('ix_todos_id', table_name='todos')
op.drop_index('ix_todos_task', table_name='todos')
op.drop_table('todos')
op.drop_table('token_blacklist')
op.drop_index('ix_chat_messages_id', table_name='chat_messages')
op.drop_index('ix_chat_messages_user_id', table_name='chat_messages')
op.drop_table('chat_messages')
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('chat_messages',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('sender', postgresql.ENUM('USER', 'AI', name='messagesender'), autoincrement=False, nullable=False),
sa.Column('text', sa.TEXT(), autoincrement=False, nullable=False),
sa.Column('timestamp', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], name='chat_messages_user_id_fkey'),
sa.PrimaryKeyConstraint('id', name='chat_messages_pkey')
)
op.create_index('ix_chat_messages_user_id', 'chat_messages', ['user_id'], unique=False)
op.create_index('ix_chat_messages_id', 'chat_messages', ['id'], unique=False)
op.create_table('token_blacklist',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('token', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('expires_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name='token_blacklist_pkey'),
sa.UniqueConstraint('token', name='token_blacklist_token_key')
)
op.create_table('todos',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('task', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('date', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.Column('remind', sa.BOOLEAN(), autoincrement=False, nullable=True),
sa.Column('complete', sa.BOOLEAN(), autoincrement=False, nullable=True),
sa.Column('owner_id', sa.INTEGER(), autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], name='todos_owner_id_fkey'),
sa.PrimaryKeyConstraint('id', name='todos_pkey')
)
op.create_index('ix_todos_task', 'todos', ['task'], unique=False)
op.create_index('ix_todos_id', 'todos', ['id'], unique=False)
op.create_table('users',
sa.Column('id', sa.INTEGER(), server_default=sa.text("nextval('users_id_seq'::regclass)"), autoincrement=True, nullable=False),
sa.Column('uuid', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('username', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('role', postgresql.ENUM('ADMIN', 'USER', name='userrole'), autoincrement=False, nullable=False),
sa.Column('hashed_password', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name='users_pkey'),
sa.UniqueConstraint('username', name='users_username_key'),
sa.UniqueConstraint('uuid', name='users_uuid_key'),
postgresql_ignore_search_path=False
)
op.create_table('calendar_events',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('title', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('description', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('start', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
sa.Column('end', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.Column('location', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('tags', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=True),
sa.Column('color', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], name='calendar_events_user_id_fkey'),
sa.PrimaryKeyConstraint('id', name='calendar_events_pkey')
)
# ### end Alembic commands ###