feat: add billing core models
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
# Generated by Django 5.2.15 on 2026-07-02 06:52
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('users', '0003_apikey_userwallet'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CallRecord',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('operation_type', models.CharField(choices=[('title', 'Generate title'), ('image', 'Generate image')], max_length=32)),
|
||||
('alias', models.CharField(blank=True, max_length=64)),
|
||||
('model_used', models.CharField(blank=True, max_length=128)),
|
||||
('resolution', models.CharField(blank=True, max_length=32)),
|
||||
('prompt', models.TextField(blank=True)),
|
||||
('points_cost', models.BigIntegerField(default=0)),
|
||||
('status', models.CharField(choices=[('pending', 'Pending'), ('success', 'Success'), ('failed', 'Failed')], default='pending', max_length=20)),
|
||||
('upstream_latency_ms', models.PositiveIntegerField(blank=True, null=True)),
|
||||
('error_message', models.TextField(blank=True)),
|
||||
('result_ref', models.TextField(blank=True)),
|
||||
('result_summary', models.TextField(blank=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('api_key', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='call_records', to='users.apikey')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='call_records', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'call_record',
|
||||
'ordering': ('-created_at', '-id'),
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='PointsLedger',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('change_type', models.CharField(choices=[('recharge', 'Recharge'), ('consume', 'Consume'), ('adjust', 'Adjust'), ('refund', 'Refund')], max_length=20)),
|
||||
('points_delta', models.BigIntegerField()),
|
||||
('balance_after', models.BigIntegerField()),
|
||||
('ref_order_id', models.PositiveBigIntegerField(blank=True, null=True)),
|
||||
('reason', models.TextField(blank=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('ref_call', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='ledger_entries', to='billing.callrecord')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='points_ledger_entries', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'points_ledger',
|
||||
'ordering': ('-created_at', '-id'),
|
||||
},
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='callrecord',
|
||||
index=models.Index(fields=['user', 'created_at'], name='call_record_user_id_c4cb1c_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='callrecord',
|
||||
index=models.Index(fields=['api_key', 'created_at'], name='call_record_api_key_0fe521_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='callrecord',
|
||||
index=models.Index(fields=['operation_type', 'status'], name='call_record_operati_c3ca15_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='callrecord',
|
||||
index=models.Index(fields=['alias'], name='call_record_alias_8f3c9b_idx'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='callrecord',
|
||||
constraint=models.CheckConstraint(condition=models.Q(('points_cost__gte', 0)), name='call_record_points_cost_non_negative'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='pointsledger',
|
||||
index=models.Index(fields=['user', 'created_at'], name='points_ledg_user_id_ed8d7f_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='pointsledger',
|
||||
index=models.Index(fields=['change_type', 'created_at'], name='points_ledg_change__431a16_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='pointsledger',
|
||||
index=models.Index(fields=['ref_order_id'], name='points_ledg_ref_ord_da5b21_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='pointsledger',
|
||||
index=models.Index(fields=['ref_call'], name='points_ledg_ref_cal_76574c_idx'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='pointsledger',
|
||||
constraint=models.CheckConstraint(condition=models.Q(('balance_after__gte', 0)), name='points_ledger_balance_after_non_negative'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='pointsledger',
|
||||
constraint=models.CheckConstraint(condition=models.Q(('points_delta', 0), _negated=True), name='points_ledger_points_delta_non_zero'),
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user