"""Initial migration Revision ID: 001 Revises: Create Date: 2023-06-13 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = '001' down_revision = None branch_labels = None depends_on = None def upgrade(): # Create user table op.create_table( 'user', sa.Column('id', sa.Integer(), nullable=False), sa.Column('email', sa.String(), nullable=False), sa.Column('full_name', sa.String(), nullable=True), sa.Column('hashed_password', sa.String(), nullable=False), sa.Column('is_active', sa.Boolean(), default=True), sa.Column('is_verified', sa.Boolean(), default=False), sa.Column('is_kyc_verified', sa.Boolean(), default=False), sa.Column('role', sa.String(), default='user'), sa.Column('two_factor_secret', sa.String(), nullable=True), sa.Column('is_two_factor_enabled', sa.Boolean(), default=False), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False), sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True) op.create_index(op.f('ix_user_id'), 'user', ['id'], unique=False) # Create wallet table op.create_table( 'wallet', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('wallet_type', sa.String(), nullable=False), sa.Column('balance', sa.Float(), default=0.0, nullable=False), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False), sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_wallet_id'), 'wallet', ['id'], unique=False) # Create deposit table op.create_table( 'deposit', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('amount', sa.Float(), nullable=False), sa.Column('transaction_hash', sa.String(), nullable=False), sa.Column('proof_image_path', sa.String(), nullable=True), sa.Column('status', sa.String(), default='pending', nullable=False), sa.Column('admin_notes', sa.Text(), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False), sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_deposit_id'), 'deposit', ['id'], unique=False) # Create withdrawal table op.create_table( 'withdrawal', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('amount', sa.Float(), nullable=False), sa.Column('fee', sa.Float(), default=0.0, nullable=False), sa.Column('wallet_address', sa.String(), nullable=False), sa.Column('status', sa.String(), default='pending', nullable=False), sa.Column('admin_notes', sa.Text(), nullable=True), sa.Column('transaction_hash', sa.String(), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False), sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_withdrawal_id'), 'withdrawal', ['id'], unique=False) # Create bot table op.create_table( 'bot', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(), nullable=False), sa.Column('description', sa.Text(), nullable=True), sa.Column('roi_percentage', sa.Float(), nullable=False), sa.Column('duration_hours', sa.Integer(), nullable=False), sa.Column('min_purchase_amount', sa.Float(), nullable=False), sa.Column('max_purchase_amount', sa.Float(), nullable=False), sa.Column('is_active', sa.Boolean(), default=True), sa.Column('image_path', sa.String(), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False), sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_bot_id'), 'bot', ['id'], unique=False) # Create bot purchase table op.create_table( 'botpurchase', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('bot_id', sa.Integer(), nullable=False), sa.Column('amount', sa.Float(), nullable=False), sa.Column('expected_roi_amount', sa.Float(), nullable=False), sa.Column('start_time', sa.DateTime(), default=sa.func.now()), sa.Column('end_time', sa.DateTime(), nullable=True), sa.Column('status', sa.String(), default='running'), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False), sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False), sa.ForeignKeyConstraint(['bot_id'], ['bot.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_botpurchase_id'), 'botpurchase', ['id'], unique=False) # Create KYC table op.create_table( 'kyc', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('full_name', sa.String(), nullable=False), sa.Column('id_document_type', sa.String(), nullable=False), sa.Column('id_document_path', sa.String(), nullable=False), sa.Column('selfie_path', sa.String(), nullable=False), sa.Column('additional_document_path', sa.String(), nullable=True), sa.Column('status', sa.String(), default='pending'), sa.Column('rejection_reason', sa.Text(), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False), sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('user_id') ) op.create_index(op.f('ix_kyc_id'), 'kyc', ['id'], unique=False) # Create transaction table - must be last due to self-referential relationship op.create_table( 'transaction', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('wallet_id', sa.Integer(), nullable=False), sa.Column('deposit_id', sa.Integer(), nullable=True), sa.Column('withdrawal_id', sa.Integer(), nullable=True), sa.Column('bot_purchase_id', sa.Integer(), nullable=True), sa.Column('transaction_type', sa.String(), nullable=False), sa.Column('amount', sa.Float(), nullable=False), sa.Column('description', sa.Text(), nullable=True), sa.Column('related_transaction_id', sa.Integer(), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False), sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False), sa.ForeignKeyConstraint(['bot_purchase_id'], ['botpurchase.id'], ), sa.ForeignKeyConstraint(['deposit_id'], ['deposit.id'], ), sa.ForeignKeyConstraint(['related_transaction_id'], ['transaction.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.ForeignKeyConstraint(['wallet_id'], ['wallet.id'], ), sa.ForeignKeyConstraint(['withdrawal_id'], ['withdrawal.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_transaction_id'), 'transaction', ['id'], unique=False) def downgrade(): # Drop tables in reverse order of creation op.drop_index(op.f('ix_transaction_id'), table_name='transaction') op.drop_table('transaction') op.drop_index(op.f('ix_kyc_id'), table_name='kyc') op.drop_table('kyc') op.drop_index(op.f('ix_botpurchase_id'), table_name='botpurchase') op.drop_table('botpurchase') op.drop_index(op.f('ix_bot_id'), table_name='bot') op.drop_table('bot') op.drop_index(op.f('ix_withdrawal_id'), table_name='withdrawal') op.drop_table('withdrawal') op.drop_index(op.f('ix_deposit_id'), table_name='deposit') op.drop_table('deposit') op.drop_index(op.f('ix_wallet_id'), table_name='wallet') op.drop_table('wallet') op.drop_index(op.f('ix_user_id'), table_name='user') op.drop_index(op.f('ix_user_email'), table_name='user') op.drop_table('user')