first commit

This commit is contained in:
Beyhan Oğur
2026-04-26 22:25:19 +03:00
commit 361dbef019
25 changed files with 814 additions and 0 deletions

45
alembic/env.py Normal file
View File

@@ -0,0 +1,45 @@
from logging.config import fileConfig
import os
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
from dotenv import load_dotenv
load_dotenv()
config = context.config
fileConfig(config.config_file_name)
# Ensure alembic picks up DATABASE_URL (or DB_URL) from environment
import os
db_url = os.getenv("DATABASE_URL") or os.getenv("DB_URL")
if db_url:
config.set_main_option("sqlalchemy.url", db_url)
target_metadata = None
def run_migrations_offline():
url = os.getenv("DATABASE_URL")
context.configure(url=url, target_metadata=target_metadata, literal_binds=True)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online():
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)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

3
alembic/script.py.mako Normal file
View File

@@ -0,0 +1,3 @@
"""
Migration script template placeholder (Alembic will autogenerate actual scripts).
"""

View File

@@ -0,0 +1,39 @@
"""create users and refresh_tokens tables
Revision ID: 0001_create_users_and_refresh_tokens
Revises:
Create Date: 2026-02-20 00:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '0001'
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
op.create_table(
'user',
sa.Column('id', sa.Integer(), primary_key=True),
sa.Column('email', sa.String(length=255), nullable=False, unique=True, index=True),
sa.Column('hashed_password', sa.String(length=512), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=False, server_default=sa.text('1')),
sa.Column('created_at', sa.DateTime(), nullable=False),
)
op.create_table(
'refreshtoken',
sa.Column('id', sa.Integer(), primary_key=True),
sa.Column('user_id', sa.Integer(), sa.ForeignKey('user.id'), nullable=False),
sa.Column('token', sa.String(length=512), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('expires_at', sa.DateTime(), nullable=False),
)
def downgrade() -> None:
op.drop_table('refreshtoken')
op.drop_table('user')