Skip to content

Commit

Permalink
refactor(migrations): rebuild (#1387)
Browse files Browse the repository at this point in the history
  • Loading branch information
nannan00 authored Nov 13, 2023
1 parent 282d32d commit 7e99acd
Show file tree
Hide file tree
Showing 25 changed files with 169 additions and 753 deletions.
47 changes: 38 additions & 9 deletions src/bk-user/bkuser/apps/data_source/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by Django 3.2.20 on 2023-08-30 09:46
import uuid
# Generated by Django 3.2.20 on 2023-11-13 09:45

import bkuser.apps.data_source.constants
import bkuser.utils.uuid
import blue_krill.models.fields
from django.db import migrations, models
import django.db.models.deletion
import mptt.fields
Expand All @@ -20,10 +22,13 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('creator', models.CharField(blank=True, max_length=128, null=True)),
('updater', models.CharField(blank=True, max_length=128, null=True)),
('name', models.CharField(max_length=128, unique=True, verbose_name='数据源名称')),
('owner_tenant_id', models.CharField(db_index=True, max_length=64, verbose_name='归属租户')),
('plugin_config', models.JSONField(default=dict, verbose_name='数据源插件配置')),
('sync_config', models.JSONField(default=dict, verbose_name='数据源同步任务配置')),
('status', models.CharField(choices=[('enabled', '启用'), ('disabled', '未启用')], default=bkuser.apps.data_source.constants.DataSourceStatus['ENABLED'], max_length=32, verbose_name='数据源状态')),
('plugin_config', models.JSONField(default=dict, verbose_name='插件配置')),
('sync_config', models.JSONField(default=dict, verbose_name='同步任务配置')),
('field_mapping', models.JSONField(default=list, verbose_name='用户字段映射')),
],
options={
Expand All @@ -36,13 +41,14 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('code', models.CharField(blank=True, max_length=128, null=True, verbose_name='部门标识')),
('code', models.CharField(default=bkuser.utils.uuid.generate_uuid, max_length=128, verbose_name='部门标识')),
('name', models.CharField(max_length=255, verbose_name='部门名称')),
('extras', models.JSONField(default=dict, verbose_name='自定义字段')),
('data_source', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.PROTECT, to='data_source.datasource')),
],
options={
'ordering': ['id'],
'unique_together': {('code', 'data_source')},
},
),
migrations.CreateModel(
Expand All @@ -60,7 +66,7 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('code', models.CharField(default=uuid.uuid4, max_length=128, verbose_name='用户标识')),
('code', models.CharField(default=bkuser.utils.uuid.generate_uuid, max_length=128, verbose_name='用户标识')),
('username', models.CharField(max_length=128, verbose_name='用户名')),
('full_name', models.CharField(max_length=128, verbose_name='姓名')),
('email', models.EmailField(blank=True, default='', max_length=254, null=True, verbose_name='邮箱')),
Expand All @@ -72,9 +78,16 @@ class Migration(migrations.Migration):
],
options={
'ordering': ['id'],
'unique_together': {('username', 'data_source'), ('code', 'data_source')},
'unique_together': {('code', 'data_source'), ('username', 'data_source')},
},
),
migrations.CreateModel(
name='DepartmentRelationMPTTTree',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('data_source', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.PROTECT, to='data_source.datasource')),
],
),
migrations.AddField(
model_name='datasource',
name='plugin',
Expand All @@ -86,7 +99,7 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('password', models.CharField(blank=True, default='', max_length=255, null=True, verbose_name='用户密码')),
('password', models.CharField(blank=True, default='', max_length=128, null=True, verbose_name='用户密码')),
('password_updated_at', models.DateTimeField(blank=True, null=True, verbose_name='密码最后更新时间')),
('password_expired_at', models.DateTimeField(blank=True, null=True, verbose_name='密码过期时间')),
('username', models.CharField(max_length=128, verbose_name='用户名')),
Expand All @@ -103,6 +116,7 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('data_source', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to='data_source.datasource')),
('leader', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, related_name='leader', to='data_source.datasourceuser')),
('user', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to='data_source.datasourceuser')),
],
Expand All @@ -111,12 +125,27 @@ class Migration(migrations.Migration):
'unique_together': {('user', 'leader')},
},
),
migrations.CreateModel(
name='DataSourceSensitiveInfo',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('key', models.CharField(max_length=255, verbose_name='配置字段路径')),
('value', blue_krill.models.fields.EncryptField(max_length=255, verbose_name='敏感配置数据')),
('data_source', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.PROTECT, to='data_source.datasource')),
],
options={
'unique_together': {('data_source', 'key')},
},
),
migrations.CreateModel(
name='DataSourceDepartmentUserRelation',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('data_source', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to='data_source.datasource')),
('department', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to='data_source.datasourcedepartment')),
('user', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to='data_source.datasourceuser')),
],
Expand All @@ -139,7 +168,7 @@ class Migration(migrations.Migration):
('parent', mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='data_source.datasourcedepartmentrelation')),
],
options={
'index_together': {('tree_id', 'lft', 'rght'), ('parent_id', 'tree_id', 'lft')},
'index_together': {('parent_id', 'tree_id', 'lft'), ('tree_id', 'lft', 'rght')},
},
),
]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 3.2.20 on 2023-11-13 09:47
from django.conf import settings
from django.db import migrations

from bkuser.plugins.constants import DataSourcePluginEnum
from bkuser.utils.base64 import load_image_as_base64


def forwards_func(apps, schema_editor):
"""初始化本地数据源插件"""

DataSourcePlugin = apps.get_model("data_source", "DataSourcePlugin")

# 本地数据源插件
# TODO 插件名称,描述国际化
DataSourcePlugin.objects.get_or_create(
id=DataSourcePluginEnum.LOCAL,
defaults={
"name": DataSourcePluginEnum.get_choice_label(DataSourcePluginEnum.LOCAL),
"description": "支持用户和部门的增删改查,以及用户的登录认证",
"logo": load_image_as_base64(settings.BASE_DIR / "bkuser/plugins/local/logo.png"),
},
)

# Http数据源插件
# TODO 插件名称,描述国际化
DataSourcePlugin.objects.get_or_create(
id=DataSourcePluginEnum.GENERAL,
defaults={
"name": DataSourcePluginEnum.get_choice_label(DataSourcePluginEnum.GENERAL),
"description": "支持对接通用 HTTP 数据源的插件,用户需要在服务方提供 `用户数据` 及 `部门数据` API",
"logo": load_image_as_base64(settings.BASE_DIR / "bkuser/plugins/general/logo.png"),
},
)


class Migration(migrations.Migration):

dependencies = [
('data_source', '0001_initial'),
]

operations = [
migrations.RunPython(forwards_func)
]

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7e99acd

Please sign in to comment.