
Features: - User registration and authentication with JWT tokens - Multi-level admin access (Admin and Super Admin) - Gym management with membership plans - Subscription management with payment integration - Stripe and Paystack payment gateway support - Role-based access control - SQLite database with Alembic migrations - Comprehensive API endpoints with FastAPI - Database models for users, gyms, memberships, subscriptions, and transactions - Admin endpoints for user management and financial reporting - Health check and documentation endpoints Core Components: - FastAPI application with CORS support - SQLAlchemy ORM with relationship mapping - JWT-based authentication with bcrypt password hashing - Payment service abstraction for multiple gateways - Pydantic schemas for request/response validation - Alembic database migration system - Admin dashboard functionality - Environment variable configuration
203 lines
7.3 KiB
Python
203 lines
7.3 KiB
Python
"""Initial migration
|
|
|
|
Revision ID: 0001
|
|
Revises:
|
|
Create Date: 2024-01-01 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:
|
|
# Create users table
|
|
op.create_table(
|
|
"users",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("email", sa.String(), nullable=False),
|
|
sa.Column("full_name", sa.String(), nullable=False),
|
|
sa.Column("phone", sa.String(), nullable=True),
|
|
sa.Column("hashed_password", sa.String(), nullable=False),
|
|
sa.Column(
|
|
"role",
|
|
sa.Enum("user", "admin", "super_admin", name="userrole"),
|
|
nullable=False,
|
|
),
|
|
sa.Column("is_active", sa.Boolean(), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(), nullable=True),
|
|
sa.Column("updated_at", sa.DateTime(), nullable=True),
|
|
sa.Column("invited_by", sa.Integer(), nullable=True),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(op.f("ix_users_email"), "users", ["email"], unique=True)
|
|
op.create_index(op.f("ix_users_id"), "users", ["id"], unique=False)
|
|
|
|
# Create gyms table
|
|
op.create_table(
|
|
"gyms",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("name", sa.String(), nullable=False),
|
|
sa.Column("description", sa.Text(), nullable=True),
|
|
sa.Column("address", sa.String(), nullable=False),
|
|
sa.Column("city", sa.String(), nullable=False),
|
|
sa.Column("state", sa.String(), nullable=False),
|
|
sa.Column("phone", sa.String(), nullable=True),
|
|
sa.Column("email", sa.String(), nullable=True),
|
|
sa.Column("is_active", sa.Boolean(), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(), nullable=True),
|
|
sa.Column("updated_at", sa.DateTime(), nullable=True),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(op.f("ix_gyms_id"), "gyms", ["id"], unique=False)
|
|
op.create_index(op.f("ix_gyms_name"), "gyms", ["name"], unique=False)
|
|
|
|
# Create membership_plans table
|
|
op.create_table(
|
|
"membership_plans",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("gym_id", sa.Integer(), nullable=False),
|
|
sa.Column("name", sa.String(), nullable=False),
|
|
sa.Column("description", sa.Text(), nullable=True),
|
|
sa.Column(
|
|
"plan_type",
|
|
sa.Enum("basic", "premium", "vip", name="plantype"),
|
|
nullable=False,
|
|
),
|
|
sa.Column("price", sa.Float(), nullable=False),
|
|
sa.Column("duration_days", sa.Integer(), nullable=False),
|
|
sa.Column("features", sa.Text(), nullable=True),
|
|
sa.Column("is_active", sa.Boolean(), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(), nullable=True),
|
|
sa.Column("updated_at", sa.DateTime(), nullable=True),
|
|
sa.ForeignKeyConstraint(
|
|
["gym_id"],
|
|
["gyms.id"],
|
|
),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(
|
|
op.f("ix_membership_plans_id"), "membership_plans", ["id"], unique=False
|
|
)
|
|
|
|
# Create gym_memberships table
|
|
op.create_table(
|
|
"gym_memberships",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
|
sa.Column("gym_id", sa.Integer(), nullable=False),
|
|
sa.Column(
|
|
"status",
|
|
sa.Enum(
|
|
"active", "inactive", "expired", "suspended", name="membershipstatus"
|
|
),
|
|
nullable=True,
|
|
),
|
|
sa.Column("joined_at", sa.DateTime(), nullable=True),
|
|
sa.Column("updated_at", sa.DateTime(), nullable=True),
|
|
sa.ForeignKeyConstraint(
|
|
["gym_id"],
|
|
["gyms.id"],
|
|
),
|
|
sa.ForeignKeyConstraint(
|
|
["user_id"],
|
|
["users.id"],
|
|
),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(
|
|
op.f("ix_gym_memberships_id"), "gym_memberships", ["id"], unique=False
|
|
)
|
|
|
|
# Create subscriptions table
|
|
op.create_table(
|
|
"subscriptions",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
|
sa.Column("membership_plan_id", sa.Integer(), nullable=False),
|
|
sa.Column(
|
|
"status",
|
|
sa.Enum(
|
|
"active", "expired", "cancelled", "pending", name="subscriptionstatus"
|
|
),
|
|
nullable=True,
|
|
),
|
|
sa.Column("start_date", sa.DateTime(), nullable=False),
|
|
sa.Column("end_date", sa.DateTime(), nullable=False),
|
|
sa.Column("amount_paid", sa.Float(), nullable=False),
|
|
sa.Column("payment_reference", sa.String(), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(), nullable=True),
|
|
sa.Column("updated_at", sa.DateTime(), nullable=True),
|
|
sa.ForeignKeyConstraint(
|
|
["membership_plan_id"],
|
|
["membership_plans.id"],
|
|
),
|
|
sa.ForeignKeyConstraint(
|
|
["user_id"],
|
|
["users.id"],
|
|
),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(op.f("ix_subscriptions_id"), "subscriptions", ["id"], unique=False)
|
|
|
|
# Create transactions table
|
|
op.create_table(
|
|
"transactions",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
|
sa.Column("subscription_id", sa.Integer(), nullable=True),
|
|
sa.Column("amount", sa.Float(), nullable=False),
|
|
sa.Column("currency", sa.String(), nullable=False),
|
|
sa.Column(
|
|
"status",
|
|
sa.Enum(
|
|
"pending", "completed", "failed", "refunded", name="transactionstatus"
|
|
),
|
|
nullable=True,
|
|
),
|
|
sa.Column(
|
|
"payment_gateway",
|
|
sa.Enum("stripe", "paystack", name="paymentgateway"),
|
|
nullable=False,
|
|
),
|
|
sa.Column("gateway_transaction_id", sa.String(), nullable=True),
|
|
sa.Column("gateway_reference", sa.String(), nullable=True),
|
|
sa.Column("description", sa.Text(), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(), nullable=True),
|
|
sa.Column("updated_at", sa.DateTime(), nullable=True),
|
|
sa.ForeignKeyConstraint(
|
|
["subscription_id"],
|
|
["subscriptions.id"],
|
|
),
|
|
sa.ForeignKeyConstraint(
|
|
["user_id"],
|
|
["users.id"],
|
|
),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(op.f("ix_transactions_id"), "transactions", ["id"], unique=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index(op.f("ix_transactions_id"), table_name="transactions")
|
|
op.drop_table("transactions")
|
|
op.drop_index(op.f("ix_subscriptions_id"), table_name="subscriptions")
|
|
op.drop_table("subscriptions")
|
|
op.drop_index(op.f("ix_gym_memberships_id"), table_name="gym_memberships")
|
|
op.drop_table("gym_memberships")
|
|
op.drop_index(op.f("ix_membership_plans_id"), table_name="membership_plans")
|
|
op.drop_table("membership_plans")
|
|
op.drop_index(op.f("ix_gyms_name"), table_name="gyms")
|
|
op.drop_index(op.f("ix_gyms_id"), table_name="gyms")
|
|
op.drop_table("gyms")
|
|
op.drop_index(op.f("ix_users_id"), table_name="users")
|
|
op.drop_index(op.f("ix_users_email"), table_name="users")
|
|
op.drop_table("users")
|