-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: add application migrations #3208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # Generated by Django 5.2 on 2025-06-06 14:56 | ||
|
|
||
| import django.db.models.deletion | ||
| import uuid | ||
| import uuid_utils.compat | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('application', '0002_chat_chatrecord_workflowversion_and_more'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='applicationaccesstoken', | ||
| name='show_exec', | ||
| field=models.BooleanField(default=False, verbose_name='是否显示执行详情'), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='chat', | ||
| name='client_type', | ||
| field=models.CharField(choices=[('ANONYMOUS_USER', '匿名用户'), ('CHAT_USER', '对话用户'), ('SYSTEM_API_KEY', '系统API_KEY'), ('APPLICATION_API_KEY', '应用API_KEY')], default='ANONYMOUS_USER', max_length=64, verbose_name='客户端类型'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='chat', | ||
| name='id', | ||
| field=models.UUIDField(default=uuid.UUID('019745bd-c430-7760-b886-638356133c4b'), editable=False, primary_key=True, serialize=False, verbose_name='主键id'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='chat', | ||
| name='is_deleted', | ||
| field=models.BooleanField(default=False, verbose_name='逻辑删除'), | ||
| ), | ||
| migrations.CreateModel( | ||
| name='ApplicationChatClientStats', | ||
| fields=[ | ||
| ('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')), | ||
| ('update_time', models.DateTimeField(auto_now=True, verbose_name='修改时间')), | ||
| ('id', models.UUIDField(default=uuid_utils.compat.uuid7, editable=False, primary_key=True, serialize=False, verbose_name='主键id')), | ||
| ('client_id', models.UUIDField(default=uuid_utils.compat.uuid7, verbose_name='公共访问链接客户端id')), | ||
| ('client_type', models.CharField(choices=[('ANONYMOUS_USER', '匿名用户'), ('CHAT_USER', '对话用户'), ('SYSTEM_API_KEY', '系统API_KEY'), ('APPLICATION_API_KEY', '应用API_KEY')], default='ANONYMOUS_USER', max_length=64, verbose_name='客户端类型')), | ||
| ('access_num', models.IntegerField(default=0, verbose_name='访问总次数次数')), | ||
| ('intraday_access_num', models.IntegerField(default=0, verbose_name='当日访问次数')), | ||
| ('application', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='application.application', verbose_name='应用id')), | ||
| ], | ||
| options={ | ||
| 'db_table': 'application_chat_client_stats', | ||
| }, | ||
| ), | ||
| migrations.DeleteModel( | ||
| name='ApplicationPublicAccessClient', | ||
| ), | ||
| migrations.AddIndex( | ||
| model_name='applicationchatclientstats', | ||
| index=models.Index(fields=['application_id', 'client_id'], name='application_applica_f89647_idx'), | ||
| ), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,8 @@ class Chat(AppModelMixin): | |
| application = models.ForeignKey(Application, on_delete=models.CASCADE) | ||
| abstract = models.CharField(max_length=1024, verbose_name="摘要") | ||
| client_id = models.UUIDField(verbose_name="客户端id", default=None, null=True) | ||
| client_type = models.CharField(max_length=64, verbose_name="客户端类型", choices=ClientType.choices) | ||
| client_type = models.CharField(max_length=64, verbose_name="客户端类型", choices=ClientType.choices, | ||
| default=ClientType.ANONYMOUS_USER) | ||
| is_deleted = models.BooleanField(verbose_name="逻辑删除", default=False) | ||
|
|
||
| class Meta: | ||
|
|
@@ -88,7 +89,8 @@ class Meta: | |
| class ApplicationChatClientStats(AppModelMixin): | ||
| id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid7, editable=False, verbose_name="主键id") | ||
| client_id = models.UUIDField(max_length=128, default=uuid.uuid7, verbose_name="公共访问链接客户端id") | ||
| client_type = models.CharField(max_length=64, verbose_name="客户端类型", choices=ClientType.choices) | ||
| client_type = models.CharField(max_length=64, verbose_name="客户端类型", choices=ClientType.choices, | ||
| default=ClientType.ANONYMOUS_USER) | ||
| application = models.ForeignKey(Application, on_delete=models.CASCADE, verbose_name="应用id") | ||
| access_num = models.IntegerField(default=0, verbose_name="访问总次数次数") | ||
| intraday_access_num = models.IntegerField(default=0, verbose_name="当日访问次数") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are some observations and suggestions:
Overall, your initial code looks clean and functional, but these points offer additional improvements to ensure robustness and efficiency. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This migration seems mostly correct and well-structured, with a few areas that could be optimized or improved:
1. Use of
uuid_utils.compat.uuid7uuid_utils.compat.uuid7instead of standarduuid.uuid4is generally preferred in production environments for better performance when generating UUIDs.uuid_utils.compat.uuid7withuuid.uuid4.Add Indexes
application_id,client_id) rather than for individual columns.Field Descriptions
Here's an updated version with these changes suggested:
By making these adjustments, you improve the readability, maintainability, and potential performance of your database schema.