Files
FitTrack2/FitnessSync/backend/alembic/versions/24df1381ac00_initial_migration.py
2025-12-23 06:09:34 -08:00

151 lines
6.7 KiB
Python

"""Initial migration
Revision ID: 24df1381ac00
Revises:
Create Date: 2025-12-22 15:04:54.280508
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '24df1381ac00'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
# Create configurations table
op.create_table('configurations',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('key', sa.String(), nullable=False),
sa.Column('value', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('key')
)
op.create_index(op.f('ix_configurations_id'), 'configurations', ['id'], unique=False)
# Create api_tokens table
op.create_table('api_tokens',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('token_type', sa.String(), nullable=False),
sa.Column('access_token', sa.String(), nullable=False),
sa.Column('refresh_token', sa.String(), nullable=True),
sa.Column('expires_at', sa.DateTime(), nullable=False),
sa.Column('scopes', sa.String(), nullable=True),
sa.Column('garth_oauth1_token', sa.String(), nullable=True),
sa.Column('garth_oauth2_token', sa.String(), nullable=True),
sa.Column('last_used', sa.DateTime(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_api_tokens_id'), 'api_tokens', ['id'], unique=False)
# Create auth_status table
op.create_table('auth_status',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('service', sa.String(), nullable=False),
sa.Column('is_authenticated', sa.Boolean(), nullable=False),
sa.Column('last_sync', sa.DateTime(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('service')
)
op.create_index(op.f('ix_auth_status_id'), 'auth_status', ['id'], unique=False)
# Create weight_records table
op.create_table('weight_records',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('date', sa.Date(), nullable=False),
sa.Column('weight', sa.Float(), nullable=False),
sa.Column('bmi', sa.Float(), nullable=True),
sa.Column('body_fat', sa.Float(), nullable=True),
sa.Column('source', sa.String(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_weight_records_id'), 'weight_records', ['id'], unique=False)
# Create activities table
op.create_table('activities',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('activity_name', sa.String(), nullable=False),
sa.Column('start_time', sa.DateTime(), nullable=False),
sa.Column('end_time', sa.DateTime(), nullable=True),
sa.Column('duration', sa.Integer(), nullable=True),
sa.Column('calories', sa.Integer(), nullable=True),
sa.Column('distance', sa.Float(), nullable=True),
sa.Column('source', sa.String(), nullable=False),
sa.Column('activity_data', sa.JSON(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_activities_id'), 'activities', ['id'], unique=False)
# Create health_metrics table
op.create_table('health_metrics',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('date', sa.Date(), nullable=False),
sa.Column('metric_type', sa.String(), nullable=False),
sa.Column('value', sa.Float(), nullable=False),
sa.Column('unit', sa.String(), nullable=True),
sa.Column('source', sa.String(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_health_metrics_id'), 'health_metrics', ['id'], unique=False)
# Create sync_logs table
op.create_table('sync_logs',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('sync_type', sa.String(), nullable=False),
sa.Column('source', sa.String(), nullable=False),
sa.Column('destination', sa.String(), nullable=False),
sa.Column('start_time', sa.DateTime(), nullable=False),
sa.Column('end_time', sa.DateTime(), nullable=True),
sa.Column('status', sa.String(), nullable=False),
sa.Column('records_synced', sa.Integer(), nullable=True),
sa.Column('error_message', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_sync_logs_id'), 'sync_logs', ['id'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_sync_logs_id'), table_name='sync_logs')
op.drop_table('sync_logs')
op.drop_index(op.f('ix_health_metrics_id'), table_name='health_metrics')
op.drop_table('health_metrics')
op.drop_index(op.f('ix_activities_id'), table_name='activities')
op.drop_table('activities')
op.drop_index(op.f('ix_weight_records_id'), table_name='weight_records')
op.drop_table('weight_records')
op.drop_index(op.f('ix_auth_status_id'), table_name='auth_status')
op.drop_table('auth_status')
op.drop_index(op.f('ix_api_tokens_id'), table_name='api_tokens')
op.drop_table('api_tokens')
op.drop_index(op.f('ix_configurations_id'), table_name='configurations')
op.drop_table('configurations')
# ### end Alembic commands ###