Files
thrilltrack-explorer/django/apps/users/migrations/0001_initial.py
pacnpal 543d7bc9dc feat: Core models implementation - Phase 1 complete
Settings Configuration:
- Split settings into base.py, local.py, production.py
- Configured all 60+ installed packages
- Set up PostgreSQL, Redis, Celery, Channels
- Configured caching, sessions, logging
- Added security settings for production

Core Models (apps/core/models.py):
- BaseModel: UUID primary key + timestamps + lifecycle hooks
- VersionedModel: Automatic version tracking with DirtyFieldsMixin
- Country, Subdivision, Locality: Location reference data
- DatePrecisionMixin: Track date precision (year/month/day)
- SoftDeleteMixin: Soft-delete functionality
- ActiveManager & AllObjectsManager: Query managers

User Models (apps/users/models.py):
- Custom User model with UUID, email-based auth
- OAuth support (Google, Discord)
- MFA support fields
- Ban/unban functionality
- UserRole: Role-based permissions (user/moderator/admin)
- UserProfile: Extended user info and preferences

App Structure:
- Created 7 Django apps with proper configs
- Set up migrations for core and users apps
- All migrations applied successfully to SQLite

Testing:
- Django check passes with only 1 warning (static dir)
- Database migrations successful
- Ready for entity models (Park, Ride, Company)

Next: Implement entity models for parks, rides, companies
2025-11-08 11:35:50 -05:00

371 lines
13 KiB
Python

# Generated by Django 4.2.8 on 2025-11-08 16:35
from django.conf import settings
import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import django_lifecycle.mixins
import model_utils.fields
import uuid
class Migration(migrations.Migration):
initial = True
dependencies = [
("auth", "0012_alter_user_first_name_max_length"),
]
operations = [
migrations.CreateModel(
name="User",
fields=[
("password", models.CharField(max_length=128, verbose_name="password")),
(
"last_login",
models.DateTimeField(
blank=True, null=True, verbose_name="last login"
),
),
(
"is_superuser",
models.BooleanField(
default=False,
help_text="Designates that this user has all permissions without explicitly assigning them.",
verbose_name="superuser status",
),
),
(
"username",
models.CharField(
error_messages={
"unique": "A user with that username already exists."
},
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
max_length=150,
unique=True,
validators=[
django.contrib.auth.validators.UnicodeUsernameValidator()
],
verbose_name="username",
),
),
(
"first_name",
models.CharField(
blank=True, max_length=150, verbose_name="first name"
),
),
(
"last_name",
models.CharField(
blank=True, max_length=150, verbose_name="last name"
),
),
(
"is_staff",
models.BooleanField(
default=False,
help_text="Designates whether the user can log into this admin site.",
verbose_name="staff status",
),
),
(
"is_active",
models.BooleanField(
default=True,
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
verbose_name="active",
),
),
(
"date_joined",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="date joined"
),
),
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
(
"email",
models.EmailField(
help_text="Email address for authentication",
max_length=254,
unique=True,
),
),
(
"oauth_provider",
models.CharField(
blank=True,
choices=[
("", "None"),
("google", "Google"),
("discord", "Discord"),
],
help_text="OAuth provider used for authentication",
max_length=50,
),
),
(
"oauth_sub",
models.CharField(
blank=True,
help_text="OAuth subject identifier from provider",
max_length=255,
),
),
(
"mfa_enabled",
models.BooleanField(
default=False,
help_text="Whether two-factor authentication is enabled",
),
),
(
"avatar_url",
models.URLField(blank=True, help_text="URL to user's avatar image"),
),
(
"bio",
models.TextField(
blank=True, help_text="User biography", max_length=500
),
),
(
"banned",
models.BooleanField(
db_index=True,
default=False,
help_text="Whether this user is banned",
),
),
(
"ban_reason",
models.TextField(blank=True, help_text="Reason for ban"),
),
(
"banned_at",
models.DateTimeField(
blank=True, help_text="When the user was banned", null=True
),
),
(
"reputation_score",
models.IntegerField(
default=0,
help_text="User reputation score based on contributions",
),
),
(
"banned_by",
models.ForeignKey(
blank=True,
help_text="Moderator who banned this user",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="users_banned",
to=settings.AUTH_USER_MODEL,
),
),
(
"groups",
models.ManyToManyField(
blank=True,
help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
related_name="user_set",
related_query_name="user",
to="auth.group",
verbose_name="groups",
),
),
(
"user_permissions",
models.ManyToManyField(
blank=True,
help_text="Specific permissions for this user.",
related_name="user_set",
related_query_name="user",
to="auth.permission",
verbose_name="user permissions",
),
),
],
options={
"db_table": "users",
"ordering": ["-date_joined"],
},
managers=[
("objects", django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name="UserRole",
fields=[
(
"created",
model_utils.fields.AutoCreatedField(
default=django.utils.timezone.now,
editable=False,
verbose_name="created",
),
),
(
"modified",
model_utils.fields.AutoLastModifiedField(
default=django.utils.timezone.now,
editable=False,
verbose_name="modified",
),
),
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
(
"role",
models.CharField(
choices=[
("user", "User"),
("moderator", "Moderator"),
("admin", "Admin"),
],
db_index=True,
default="user",
max_length=20,
),
),
("granted_at", models.DateTimeField(auto_now_add=True)),
(
"granted_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="roles_granted",
to=settings.AUTH_USER_MODEL,
),
),
(
"user",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name="role",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"db_table": "user_roles",
},
bases=(django_lifecycle.mixins.LifecycleModelMixin, models.Model),
),
migrations.CreateModel(
name="UserProfile",
fields=[
(
"created",
model_utils.fields.AutoCreatedField(
default=django.utils.timezone.now,
editable=False,
verbose_name="created",
),
),
(
"modified",
model_utils.fields.AutoLastModifiedField(
default=django.utils.timezone.now,
editable=False,
verbose_name="modified",
),
),
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
(
"email_notifications",
models.BooleanField(
default=True, help_text="Receive email notifications"
),
),
(
"email_on_submission_approved",
models.BooleanField(
default=True, help_text="Email when submissions are approved"
),
),
(
"email_on_submission_rejected",
models.BooleanField(
default=True, help_text="Email when submissions are rejected"
),
),
(
"profile_public",
models.BooleanField(
default=True, help_text="Make profile publicly visible"
),
),
(
"show_email",
models.BooleanField(
default=False, help_text="Show email on public profile"
),
),
(
"total_submissions",
models.IntegerField(
default=0, help_text="Total number of submissions made"
),
),
(
"approved_submissions",
models.IntegerField(
default=0, help_text="Number of approved submissions"
),
),
(
"user",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name="profile",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"db_table": "user_profiles",
},
bases=(django_lifecycle.mixins.LifecycleModelMixin, models.Model),
),
migrations.AddIndex(
model_name="user",
index=models.Index(fields=["email"], name="users_email_4b85f2_idx"),
),
migrations.AddIndex(
model_name="user",
index=models.Index(fields=["banned"], name="users_banned_ee00ad_idx"),
),
]