Phase 1 scaffolding: config/, core/, base models, AES-256-GCM phone encryption, enums mirror apps.tenant: Tenant + Domain (django-tenants) apps.org: 11 models (OrgUnit hierarchy, Staff, audit logs) apps.account: 4 models (UserAccount as AUTH_USER_MODEL, login/password tracking) apps.permission: 7 models (RBAC + overrides + datascope + append-only changelog) apps.region: 5 models (District, BusinessArea, MetroLine, MetroStation, School) All migrations generated, manage.py check passes
129 lines
6.4 KiB
Python
129 lines
6.4 KiB
Python
# Generated by Django 4.2.16 on 2026-04-29 08:57
|
|
|
|
from django.db import migrations, models
|
|
import django.db.models.deletion
|
|
import uuid
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
initial = True
|
|
|
|
dependencies = [
|
|
]
|
|
|
|
operations = [
|
|
migrations.CreateModel(
|
|
name='BusinessArea',
|
|
fields=[
|
|
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('name', models.CharField(max_length=100)),
|
|
('sort_order', models.IntegerField(default=0)),
|
|
('latitude', models.DecimalField(blank=True, decimal_places=7, max_digits=10, null=True)),
|
|
('longitude', models.DecimalField(blank=True, decimal_places=7, max_digits=10, null=True)),
|
|
('is_active', models.BooleanField(default=True)),
|
|
],
|
|
options={
|
|
'db_table': 'business_areas',
|
|
'ordering': ['district_id', 'sort_order', 'name'],
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='District',
|
|
fields=[
|
|
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('city', models.CharField(max_length=50)),
|
|
('name', models.CharField(max_length=50)),
|
|
('short_name', models.CharField(blank=True, default='', max_length=20)),
|
|
('sort_order', models.IntegerField(default=0)),
|
|
('is_active', models.BooleanField(default=True)),
|
|
],
|
|
options={
|
|
'db_table': 'districts',
|
|
'ordering': ['city', 'sort_order', 'name'],
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='MetroLine',
|
|
fields=[
|
|
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('city', models.CharField(max_length=50)),
|
|
('name', models.CharField(max_length=50)),
|
|
('color', models.CharField(blank=True, default='', max_length=7)),
|
|
('sort_order', models.IntegerField(default=0)),
|
|
('is_active', models.BooleanField(default=True)),
|
|
],
|
|
options={
|
|
'db_table': 'metro_lines',
|
|
'ordering': ['city', 'sort_order', 'name'],
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='School',
|
|
fields=[
|
|
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('name', models.CharField(max_length=100)),
|
|
('type', models.CharField(blank=True, choices=[('primary', '小学'), ('middle', '初中'), ('high', '高中'), ('k9', '九年一贯制'), ('k12', '十二年一贯制')], default='', max_length=20)),
|
|
('nature', models.CharField(blank=True, choices=[('public', '公立'), ('private', '私立'), ('international', '国际')], default='', max_length=20)),
|
|
('level', models.CharField(blank=True, choices=[('normal', '普通'), ('key', '重点'), ('top', '名校')], default='', max_length=20)),
|
|
('is_active', models.BooleanField(default=True)),
|
|
('district', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='schools', to='region.district')),
|
|
],
|
|
options={
|
|
'db_table': 'schools',
|
|
'ordering': ['name'],
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='MetroStation',
|
|
fields=[
|
|
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('name', models.CharField(max_length=50)),
|
|
('latitude', models.DecimalField(blank=True, decimal_places=7, max_digits=10, null=True)),
|
|
('longitude', models.DecimalField(blank=True, decimal_places=7, max_digits=10, null=True)),
|
|
('sort_order', models.IntegerField(default=0)),
|
|
('is_active', models.BooleanField(default=True)),
|
|
('metro_line', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='stations', to='region.metroline')),
|
|
],
|
|
options={
|
|
'db_table': 'metro_stations',
|
|
'ordering': ['metro_line_id', 'sort_order'],
|
|
},
|
|
),
|
|
migrations.AddConstraint(
|
|
model_name='district',
|
|
constraint=models.UniqueConstraint(condition=models.Q(('is_active', True)), fields=('city', 'name'), name='uq_districts_city_name'),
|
|
),
|
|
migrations.AddField(
|
|
model_name='businessarea',
|
|
name='district',
|
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='business_areas', to='region.district'),
|
|
),
|
|
migrations.AddIndex(
|
|
model_name='school',
|
|
index=models.Index(condition=models.Q(('is_active', True)), fields=['district'], name='idx_schools_district'),
|
|
),
|
|
migrations.AddIndex(
|
|
model_name='metrostation',
|
|
index=models.Index(condition=models.Q(('is_active', True)), fields=['metro_line'], name='idx_metro_stations_line'),
|
|
),
|
|
migrations.AddIndex(
|
|
model_name='businessarea',
|
|
index=models.Index(condition=models.Q(('is_active', True)), fields=['district'], name='idx_business_areas_district'),
|
|
),
|
|
migrations.AddConstraint(
|
|
model_name='businessarea',
|
|
constraint=models.UniqueConstraint(fields=('district', 'name'), name='uq_business_areas_name'),
|
|
),
|
|
]
|